我对与 OpenCV 匹配的对象有疑问。我正在使用 opencv 2.3 中实现的 SURF 算法首先检测每个图像上的特征,然后提取这些特征的描述符。使用蛮力匹配器匹配的问题,我不知道如何判断这两个图像是否匹配,就像当我使用两个不同的图像时,两个图像中的描述符之间有线条!
我的代码的这些输出,无论是两个图像 - 我与它们进行比较 - 是相似的还是不同的,结果图像表明这两个图像是匹配的。
问题是:如何区分这两个图像?
真实匹配:
错误匹配!!:
我的代码:
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;