【问题标题】:OpenCV - Two completely different images are having more matches using BFMatcherOpenCV - 两个完全不同的图像使用 BFMatcher 进行更多匹配
【发布时间】:2017-01-27 10:03:09
【问题描述】:

我有一些杯子的照片

还有一张猫的照片

我想在 OpenCV 中使用 surf 比较这两张图片,并使用 BFMatcher 进行匹配。

代码如下:

//read the image
cv::Mat image1= cv::imread("C:\\Users\\The\\Desktop\\cub.jpg");
cv::Mat image2= cv::imread("C:\\Users\\The\\Desktop\\cat.jpg");
//detect the key points using surf
cv::SurfFeatureDetector surf(300,4,2,true,false);
   //image 1 key points
vector<cv::KeyPoint> image1Keypoints;
//detect the key points in image 1 using surf
surf.detect(image1,image1Keypoints);
//draw the keypoints of image1
cv::drawKeypoints(image1,image1Keypoints,image1,                                      
  cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);
cv::namedWindow("Original image 1 with keypoints");
cv::imshow("Original image 1 with keypoints",image1);
// image 2 key points
std::vector<cv::KeyPoint> image2keypoints;
//detect the key points in image 1 using surf
 surf.detect(image2,image2keypoints);
 //draw the key points
 cv::drawKeypoints(image2,keypoints1,image2,                                   
      cv::Scalar(255,255,255),cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);                      
 //the extracted image display
cv::namedWindow("image 2 with keypoints");
cv::imshow("image 2 with keypoints",image2);

从上面的代码中,这个 cups 图像具有

图像特征:

cv::SiftDescriptorExtractor sift;
cv::Mat image1Descriptor;
cv::Mat image2Desccriptor;
sift.compute(image1,
             image1Keypoints,
             image1Descriptor);
sift.compute(image2,
             keypoints1,
             image2Desccriptor);
 cv::BFMatcher matcher(cv::NORM_L2,true);
std::vector<cv::DMatch> matches;
matcher.match(image2Desccriptor,image1Descriptor,matches);
cout<<"match=";
//the number of matched features between the two images
cout<<matches.size()<<endl;
cv::Mat imageMatches;   
cv::drawMatches(image2,keypoints1,image1,image1Keypoints,                
   matches,imageMatches,cv::DrawMatchesFlags::DRAW_OVER_OUTIMG);              
cv::namedWindow("matches");
cv::imshow("matches",imageMatches);
cv::waitKey(0);

真正让我困惑的是配图:

大约有 833 个匹配的特征,但图像完全不同。

我的代码有什么问题以及如何减少匹配数。我可以通过更改 surf 参数来减少匹配的数量,但这是因为它检测到的特征数量很少。例如,将 siftFeature 检测器更改为:

cv::SurfFeatureDetector surf(1000,4,2,true,false);

我能够得到matches=77,但它仍然是大量的匹配并且匹配减少了,因为与上述数字相比,我得到的特征数量较少。

【问题讨论】:

  • 当我滚动时,我看到了一个故事...... :-D
  • 您正在比较小图像块(32x32 左右),即描述符...匹配描述符并不意味着比较图像。匹配后还需要做一些其他的步骤。
  • @POW 我的问题是对于两个不同的图像,怎么可能有这么多的匹配以及如何减少匹配的数量?
  • @Miki 你能详细说明“匹配后你必须使用其他一些步骤”的意思吗?我是opencv的初学者。
  • 例如,估计匹配关键点的变换,并检查异常值的数量。更少的异常值意味着更多相似的图像。或者在 BoW、SVM 等分类器中使用描述符。

标签: c++ opencv image-processing computer-vision surf


【解决方案1】:

你应该检查这个answer

通常,BruteForce 将返回两个匹配项之间的距离。两个特征之间的距离越小,它们就越相似。通过对这些距离应用阈值将帮助您消除误报匹配。

但是,特征匹配本身并不能保证两个图像中的对象是相同的。要进行这种验证,您需要在实现上更进一步,并(例如)用 Homography 几何验证正匹配。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-03-21
    • 1970-01-01
    • 2017-02-17
    • 2012-04-18
    • 1970-01-01
    • 2011-02-05
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多