簡介: 第一,作爲一個介紹,我感到很「自豪」要問我在計算器上的第一個問題。我希望我能夠幫助其他人,就像他們幫助我一樣。OpenCV的不同的輸出結果
上下文: 我正在開發一個應用程序,使用SURF算法搜索圖像中的要素。我計算關鍵點,然後用SURF提取描述符。然後,我使用基於歐幾里德距離的bruteforce匹配器來匹配圖像1與圖像2的描述符。 這裏是問題,我沒有得到相同的結果與2程序的不同運行(使用相同的圖像,我應該精確:p)。
輸出: 這裏是輸出,
在20個第一匹配第一運行時總分3620
0: 0 89 0.292352
1: 1 997 0.186256
2: 2 1531 0.25669
3: 3 2761 0.24148
4: 4 2116 0.286187
5: 5 2996 0.201048
6: 6 3109 0.266272
7: 7 2537 0.17112
8: 8 2743 0.211974
9: 9 2880 0.208735
10: 10 2167 0.269716
11: 11 2431 0.164508
12: 12 1474 0.281442
13: 13 1867 0.161129
14: 14 329 0.18388
15: 15 1580 0.229825
16: 16 1275 0.254946
17: 17 1749 0.203006
18: 18 305 0.221724
19: 19 1501 0.224663
20: 20 917 0.20708
第二運行時對20個第一匹配總分3620
0: 0 1455 0.25669
1: 1 963 0.186256
2: 2 3008 0.150252
3: 3 2936 0.24148
4: 4 2172 0.286187
5: 5 2708 0.211974
6: 6 730 0.185199
7: 7 3128 0.266272
8: 8 750 0.181001
9: 9 2272 0.17112
10: 10 2842 0.208735
11: 11 55 0.229677
12: 12 2430 0.269716
13: 13 2360 0.164508
14: 14 1497 0.229825
15: 15 2443 0.254148
16: 16 1784 0.161129
17: 17 1209 0.254946
18: 18 311 0.18388
19: 19 944 0.228939
20: 20 533 0.221724
代碼:這是我使用的代碼的一部分
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
vector<DMatch> filteredMatches;
matching(descriptors1,descriptors2,filteredMatches,1);
這裏是匹配函數
void crossCheckMatching(const Mat& descriptors1, const Mat& descriptors2,
vector<DMatch>& filteredMatches12, int knn=1)
{
BruteForceMatcher<L2<float>> matcher;
filteredMatches12.clear();
vector<vector<DMatch> > matches12, matches21;
matcher.knnMatch(descriptors1, descriptors2, matches12, knn);
matcher.knnMatch(descriptors2, descriptors1, matches21, knn);
debug_writeMatches("D:/jmartel/exec2-log.txt",matches12);
...
}
結論:的SURF算法給出「現實」的輸出,它部分是由相同數量的檢測關鍵點的證明在2點運行時具有相同的2圖片。 BruteForceMatcher給了我非常奇怪的輸出,它由日誌文件證明,並且可以輸出圖像,清楚地顯示它在兩個運行時間中以相同方式不匹配。
我也在GPU上實現了所有這些代碼,我的觀察結果是相似的。然而,SURF在GPU上提供了更多點(具有相同的參數)。
如果我們仔細觀察點,一些距離是完全相似的,這可能是奇怪的(即使兩個點集之間的描述符可能相等)。這是這對夫妻的
(runtime 1) 1: 1 997 0.186256
/(runtime 2) 1:1 963 0.186256
或例子更奇怪
(runtime 1) 14: 14 329 0.18388
/(runtime 2) 18: 18 311 0.18388
的OpenCV2.0文件沒有說什麼從我讀特別有意思。 See BruteForceMatcher C++ Documentation for OpenCV2.1 here
如果您有任何解釋,或者我可以在代碼中進行更改,我會很高興。 感謝您的幫助。
朱利安,