
void sift_detector_and_descriptors(IplImage* i_left,IplImage* i_right)
{
Mat mat_image_left=Mat(i_left,false)
Mat mat_image_right=Mat(i_right,false)
cv::SiftFeatureDetector *pDetector=new cv::SiftFeatureDetector
pDetector->detect(mat_image_left,left_key_point)
pDetector->detect(mat_image_right,right_key_point)
Mat left_image_descriptors,right_image_descriptors
cv::SiftDescriptorExtractor *descriptor_extractor=new cv::SiftDescriptorExtractor
descriptor_extractor->compute(mat_image_left,left_key_point,left_image_descriptors)
descriptor_extractor->compute(mat_image_right,right_key_point,right_image_descriptors)
Mat result_l,result_r
drawKeypoints(mat_image_left,left_key_point,result_l,Scalar::all(-1),0)
drawKeypoints(mat_image_right,right_key_point,result_r,Scalar::all(-1),0)
//imshow("result_of_left_detector_sift",result_l)
//imshow("result_of_right_detector_sift",result_r)
Mat result_of_sift_match
BruteForceMatcher<L2<float>>matcher
matcher.match(left_image_descriptors,right_image_descriptors,result_of_point_match)
drawMatches(mat_image_left,left_key_point,mat_image_right,right_key_point,result_of_sift_match,result_of_sift_match)
imshow("matches_of_sift",result_of_sift_match)
imwrite("matches_of_sift.jpg",result_of_sift_match)
}
void main()
{
IplImage *n_left_image=cvLoadImage("D:\\lena.jpg")
IplImage *n_right_image=cvLoadImage("D:\\lena_r.jpg")
sift_detector_and_descriptors(n_left_image,n_right_image)
cvWaitKey(0)
}
这就是核心代码了,至于opencv所要用到的库,你自己弄一下吧,每个人的opencv版本不一样,这个都市不同的,希望能够帮到你~
hog描述子在opencv中为HOGDescriptor。
2. 可以调用该描述子setSVMDetector方法给用于对hog特征进行分类的svm模型的系数赋值,这里的参数为HOGDescriptor::getDefaultPeopleDetector()时表示采用系统默认的参数,因为这些参数是用很多图片训练而来的。
3. 对输入图片进行行人检测时由于图片的大小不一样,所以要用到多尺度检测。这里是用hog类的方法detectMultiScale。参数解释如下:
HOGDescriptor::detectMultiScale(const GpuMat img, vector<Rect>found_locations, doublehit_threshold=0, Size win_stride=Size(), Size padding=Size(), double scale0=1.05, int group_threshold=2)
该函数表示对输入的图片img进行多尺度行人检测 img为输入待检测的图片;found_locations为检测到目标区域列表;参数3为程序内部计算为行人目标的阈值,也就是检测到的特征到SVM分类超平面的距离参数4为滑动窗口每次移动的距离。它必须是块移动的整数倍;参数5为图像扩充的大小;参数6为比例系数,即滑动窗口每次增加的比例;参数7为组阈值,即校正系数,当一个目标被多个窗口检测出来时,该参数此时就起了调节作用,为0时表示不起调节作用。
4. 最后对检测出来的目标矩形框,要采用一些方法处理,比如说2个目标框嵌套着,则选择最外面的那个框。
5. 因为hog检测出的矩形框比实际人体框要稍微大些,所以需要对这些矩形框大小尺寸做一些调整。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)