OpenCV,功能与教程中的代码匹配

Ant*_*sto 10 c++ opencv

我从OpenCV教程页面复制了FLANN功能匹配的代码,并进行了以下更改:

我用了

    if( matches[i].distance <= 2*min_dist )
Run Code Online (Sandbox Code Playgroud)

否则,在比较图像与自身时,我会得到零匹配.

  • 绘制关键点时修改的参数:

    drawMatches( img1, k1, img2, k2,
                     good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
                     vector<char>(), DrawMatchesFlags::DEFAULT);
    
    Run Code Online (Sandbox Code Playgroud)

我从INRIA-Holidays数据集的爱尔兰文件夹中的所有图像中提取了SIFT .然后我将每个图像与所有其他图像进行比较并绘制匹配.

然而,我在过去使用的任何其他SIFT/Matcher实现中都没有遇到过一个奇怪的问题:

  • 我匹配的图像匹配很好.除了一些关键点之外,每个关键点都映射到自身.见上图.图像与itselft匹配
  • 当我将I与另一个图像J(J不等于I)匹配时,许多点被映射到同一个图像上.下面是一些例子. 火柴 火柴火柴

是否有人使用OpenCV教程中的相同代码并报告我的不同经历?

小智 2

查看 matcher_simple.cpp 示例。它使用了一个蛮力匹配器,看起来效果很好。这是代码:

// 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);
Run Code Online (Sandbox Code Playgroud)