jma*_*tel 4 c++ opencv brute-force matching
简介: 首先,作为介绍,我很自豪地在StackOverflow上提出我的第一个问题.我希望我能帮助别人,就像他们帮助我一样.
上下文: 我正在开发一个使用SURF算法搜索图像中的要素的应用程序.我计算关键点,然后用SURF提取描述符.然后,我使用基于欧几里德距离的强力匹配来匹配图像1的描述符和图像2.这是问题,我没有得到相同的结果与2个不同的程序运行(使用相同的图像,我应该精确:p).
输出: 这是输出,
第一场比赛的第一场比赛是在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
Run Code Online (Sandbox Code Playgroud)
第一场比赛的第二场比赛在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
Run Code Online (Sandbox Code Playgroud)
代码:这是我使用的代码的一部分
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);
Run Code Online (Sandbox Code Playgroud)
这是匹配功能
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);
...
}
Run Code Online (Sandbox Code Playgroud)
结论: SURF算法给出了"实际"输出,部分证明了相同数量的检测关键点在2个运行时间内具有相同的2个图像.BruteForceMatcher给了我非常奇怪的输出,它由日志文件证明,并且我可以输出的图像清楚地显示它在两个运行时以相同的方式不匹配.
我还在GPU上实现了所有这些代码,我的观察也很相似.但是,SURF在GPU上提供了更多的点(具有相同的参数).
如果我们仔细观察这些点,一些距离是完全相似的,这可能是奇怪的(即使两组点之间的描述符可以相等......).这是这对夫妇的榜样
(runtime 1) 1: 1 997 0.186256
/ (runtime 2) 1:1 963 0.186256
Run Code Online (Sandbox Code Playgroud)
甚至是陌生人
(runtime 1) 14: 14 329 0.18388
/ (runtime 2) 18: 18 311 0.18388
Run Code Online (Sandbox Code Playgroud)
OpenCV2.0 Doc并没有从我读到的内容中说出任何特别有趣的内容. 请参阅此处的OpenCV2.1的BruteForceMatcher C++文档
如果您有任何解释,或者我可以在代码中更改任何内容,我会很高兴.谢谢你的帮助.
朱利安,