c++ - OpenCV - 使用 SURF 描述符和 BruteForceMatcher 进行对象匹配

标签 c++ opencv computer-vision surf object-detection

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

我的代码的这些输出,无论是两个图像 - 我与它们进行比较 - 相似或不同,结果图像表明这两个图像匹配。

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

真匹配:

http://store1.up-00.com/Jun11/hxM00286.jpg

错误匹配!! :

http://store1.up-00.com/Jun11/D5H00286.jpg

我的代码:

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;

最佳答案

问题在于仅使用蛮力匹配器,我在 “OpenCV 2 计算机视觉应用程序编程手册”中找到了在两个 View 之间获得一组良好匹配的方法

第 9 章:使用随机样本共识匹配图像

他们正在使用 K-Nearest Neighbor 和 RANSAC

谢谢

关于c++ - OpenCV - 使用 SURF 描述符和 BruteForceMatcher 进行对象匹配,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7296915/

相关文章:

c++ - Proxy 是否适合创建演示模式?

android - 尝试使用 opencv 从图像中检测蓝色,并得到意想不到的结果

image - MATLAB 中有没有一种方法可以计算哪些离散图像区域包围或被另一个区域包围?

matlab - 为手-前臂分割实现手腕裁剪程序(Matlab)

c++ - 如何在英特尔 SSE 内在函数中将参数传递给 const 值?

c++ - 函数不读取二维数组的 [i][0] 行

c++ - 如何使用 Scalar 类指定颜色

python - OpenCV-Python 中的简单数字识别 OCR

c++ - 内联和成员初始值设定项

c++ - 使用 Opencv Mat 的可视化像素