簡體   English   中英

OpenCV - 使用SURF描述符和BruteForceMatcher進行對象匹配

[英]OpenCV - Object matching using SURF descriptors and BruteForceMatcher

我有一個關於與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;

問題在於僅使用Brute Force Matcher,我找到了在“OpenCV 2計算機視覺應用程序編程手冊”中獲得兩個視圖之間的一組良好匹配的方法

Ch9:使用隨機樣本共識匹配圖像

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

謝謝

為了去除異常值,在比較兩個平面圖像時, RANSAC +單應性是一種很好的方法。

Homography是RANSAC將用於比較兩個圖像中的點的模型,它將找到更好地適合單應性投影模型(從一個平面到另一個平面的變換)的最佳點集。

cv::findHomography(srcPoints,dstPoints, RANSAC, status);

上面的函數將返回一個數組狀態,對於被視為inliers的索引為1,對於被視為異常值的索引為0,因此您可以通過檢查此狀態數組來刪除異常值。

你需要修改你的Hessian,2500太多了。 嘗試50.當你使用一個大的Hessian時,結果是很多關鍵點,導致一些不必要的。 關於SURF的另一個信息是你的標記需要更豐富,更詳細。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM