问题描述
我复制了特征匹配的代码使用来自 OpenCV 教程页面的 FLANN,并进行了以下更改:
I copied the code of the Feature Matching with FLANN from the OpenCV tutorial page, and made the following changes:
- 我使用了 SIFT 功能,而不是 SURF;
我修改了良好匹配"的检查.而不是
- I used the SIFT features, instead of SURF;
I modified the check for a 'good match'. Instead of
if( matches[i].distance < 2*min_dist )
我用过
if( matches[i].distance <= 2*min_dist )
否则在将图像与其自身进行比较时,我会得到零个良好匹配.
otherwise I would get zero good matches when comparing an image with itself.
在绘制关键点时修改了参数:
Modified parameter in drawing the keypoints:
drawMatches( img1, k1, img2, k2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::DEFAULT);
我从INRIA-Holidays数据集.然后我将每个图像与所有其他图像进行比较并绘制匹配项.
I extracted the SIFT from all the images in the folder Ireland of the INRIA-Holidays dataset. Then I compared each image to all the others and draw the matches.
然而,我在过去使用的任何其他 SIFT/Matcher 实现中从未遇到过一个奇怪的问题:
However there is a strange problem I have never experienced with any other SIFT/Matcher implementation I used in the past:
- 我与自己匹配的图像的匹配很好.除了一些关键点之外,每个关键点都映射到自身上.见上图.
- 当我将 I 与另一个图像 J(J 不等于 I)进行匹配时,许多点被映射到同一点上.下面是一些示例.
是否有人使用了 OpenCV 教程中的相同代码并报告了与我不同的体验?
Is there anyone who used the same code from the OpenCV tutorial and can report a different experience from mine?
推荐答案
查看 matcher_simple.cpp 示例.它使用了一个蛮力匹配器,似乎工作得很好.代码如下:
Checkout the matcher_simple.cpp example. It uses a brute force matcher that seems to work pretty well. Here is the code:
// detecting keypoints
SurfFeatureDetector detector(400);
vector<KeyPoint> keypoints1, keypoints2;
detector.detect(img1, keypoints1);
detector.detect(img2, keypoints2);
// computing descriptors
SurfDescriptorExtractor extractor;
Mat descriptors1, descriptors2;
extractor.compute(img1, keypoints1, descriptors1);
extractor.compute(img2, keypoints2, descriptors2);
// matching descriptors
BFMatcher matcher(NORM_L2);
vector<DMatch> matches;
matcher.match(descriptors1, descriptors2, matches);
// drawing the results
namedWindow("matches", 1);
Mat img_matches;
drawMatches(img1, keypoints1, img2, keypoints2, matches, img_matches);
imshow("matches", img_matches);
waitKey(0);
这篇关于OpenCV,功能与教程中的代码匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!