OpenCV - 使用SURF描述符和BruteForceMatcher的对象匹配 [英] OpenCV - Object matching using SURF descriptors and BruteForceMatcher

查看:362
本文介绍了OpenCV - 使用SURF描述符和BruteForceMatcher的对象匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于与OpenCV匹配的对象的问题。
我使用在opencv 2.3中实现的SURF算法首先检测每个图像上的特征,然后提取这些特征的描述符。
使用Brute Force Matcher匹配的问题,我不知道我如何判断两个图像是否匹配,就像我使用两个不同的图像时,两个图像之间的描述符之间有线! / p>

我的代码的这些输出,两个图像(我们与它们相比较)是相似或不同的,结果图像表示两个图像匹配。



问题是:如何区分两张图片?



True匹配:





虚假匹配! :





我的代码:

  Mat image1,outImg1,image2,outImg2; 

//关键点向量
向量< KeyPoint> keypoints1,keypoints2;

//读取输入图片
image1 = imread(C://Google-Logo.jpg,0);
image2 = imread(C://Alex_Eng.jpg,0);

SurfFeatureDetector surf(2500);
surf.detect(image1,keypoints1);
surf.detect(image2,keypoints2);
drawKeypoints(image1,keypoints1,outImg1,Scalar(255,255,255),DrawMatchesFlags :: DRAW_RICH_KEYPOINTS);
drawKeypoints(image2,keypoints2,outImg2,Scalar(255,255,255),DrawMatchesFlags :: DRAW_RICH_KEYPOINTS);

namedWindow(SURF detection img1);
imshow(SURF detection img1,outImg1);

namedWindow(SURF detection img2);
imshow(SURF detection img2,outImg2);

SurfDescriptorExtractor surfDesc;
Mat descriptors1,descriptors2;
surfDesc.compute(image1,keypoints1,descriptors1);
surfDesc.compute(image2,keypoints2,descriptors2);

BruteForceMatcher< L2< float>>匹配器
vector< DMatch>火柴;
matcher.match(descriptors1,descriptors2,matches);

nth_element(matches.begin(),matches.begin()+ 24,matches.end());
matches.erase(matches.begin()+ 25,matches.end());

Mat imageMatches;
drawMatches(image1,keypoints1,image2,keypoints2,matches,imageMatches,Scalar(255,255,255));

namedWindow(Matched);
imshow(Matched,imageMatches);

cv :: waitKey();
return 0;


解决方案

问题出在使用Brute Force Matcher找到了在OpenCV 2 Computer Vision应用程序编程库的两个视图之间获得一组良好匹配的方法



Ch9:样本共识



他们正在使用K-最近邻和RANSAC



并感谢


I have a question about objects matching with OpenCV. I'm useing SURF algorithm implemented in opencv 2.3 to first detect features on each image, and then extracting the descriptors of these features. The problem in matching using Brute Force Matcher, I don't know how I judge that the two images are matched or not that's as when I'm using two different images there are lines between descriptors in the two images!

These outputs of my code, either the two images -I compare with them - are similar or different, the result image indicate that the two images are matched.

The question is: How can I distinguish between the two images?

True matching:

False matching!! :

My code:

Mat image1, outImg1, image2, outImg2;

// vector of keypoints
vector<KeyPoint> keypoints1, keypoints2;

// Read input images
image1 = imread("C://Google-Logo.jpg",0);
image2 = imread("C://Alex_Eng.jpg",0);

SurfFeatureDetector surf(2500);
surf.detect(image1, keypoints1);
surf.detect(image2, keypoints2);
drawKeypoints(image1, keypoints1, outImg1, Scalar(255,255,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);
drawKeypoints(image2, keypoints2, outImg2, Scalar(255,255,255), DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

namedWindow("SURF detector img1");
imshow("SURF detector img1", outImg1);

namedWindow("SURF detector img2");
imshow("SURF detector img2", outImg2);

SurfDescriptorExtractor surfDesc;
Mat descriptors1, descriptors2;
surfDesc.compute(image1, keypoints1, descriptors1);
surfDesc.compute(image2, keypoints2, descriptors2);

BruteForceMatcher<L2<float>> matcher;
vector<DMatch> matches;
matcher.match(descriptors1,descriptors2, matches);

nth_element(matches.begin(), matches.begin()+24, matches.end());
matches.erase(matches.begin()+25, matches.end());

Mat imageMatches;
drawMatches(image1, keypoints1, image2, keypoints2, matches, imageMatches, Scalar(255,255,255));

namedWindow("Matched");
imshow("Matched", imageMatches);

cv::waitKey();
return 0;

解决方案

The problem was in using Brute Force Matcher only, I found methods to obtain a set of good matches between two views at "OpenCV 2 Computer Vision Application Programming Cookbook"

Ch9: Matching images using random sample consensus

They are using K-Nearest Neighbor and RANSAC

And thanks

这篇关于OpenCV - 使用SURF描述符和BruteForceMatcher的对象匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆