简介: 首先,作为介绍,我很“自豪”地在 StackOverflow 上提出我的第一个问题。我希望我能像他们帮助我一样帮助其他人。
上下文: 我正在开发一个使用 SURF 算法在图像中搜索特征的应用程序。我计算关键点并使用 SURF 提取描述符。然后,我使用基于欧几里得距离的蛮力匹配器来匹配图像 1 和图像 2 的描述符。这是问题所在,我在程序的 2 次不同运行中没有得到相同的结果(使用相同的图像,我应该精确:p)。
输出: 这是输出,
3620 场比赛中前 20 场比赛的第一次运行时
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
3620 场比赛中的 20 场比赛的第二次运行时间
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 上提供了更多的点(具有相同的参数)。
如果我们仔细观察这些点,一些距离是完全相似的,这可能但很奇怪(即使 2 组点之间的描述符可以相等......)。这是夫妻的榜样
(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 Doc 并没有说我读到的任何特别有趣的东西。 在此处查看 OpenCV2.1 的 BruteForceMatcher C++ 文档
如果您有任何解释,或者我可以在代码中更改任何内容,我会很高兴。谢谢你的帮助。
朱利安,