我有一個關於與OpenCV匹配的對象的問題。 我使用opencv 2.3中實現的SURF算法首先檢測每個圖像的特徵,然後提取這些特徵的描述符。 在使用Brute Force Matcher進行匹配時出現問題,我不知道如何判斷兩個圖像是否匹配,就像當我使用兩個不同的圖像時,兩個圖像中的描述符之間有線條!OpenCV - 使用SURF描述符和BruteForceMatcher對象匹配
我的代碼的這些輸出,無論是兩個圖像 - 我與他們比較 - 是相似還是不同,結果圖像表明這兩個圖像是匹配的。
問題是:如何區分這兩個圖像?
真正匹配:
假匹配! :
我的代碼:
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;
這本書變得非常有用! – 2012-10-02 00:58:29
你應該接受你的答案。 –