【问题标题】:How to draw matches in Opencv?如何在 Opencv 中绘制匹配?
【发布时间】:2017-08-28 11:20:35
【问题描述】:

我已经匹配了两个图像的描述符的两个向量:

cv::Ptr<BinaryDescriptorMatcher> bdm = BinaryDescriptorMatcher::createBinaryDescriptorMatcher();
std::vector<std::vector<cv::DMatch> >  matches;
float maxDist = 10.0;
bdm->radiusMatch(descr2, descr1, matches, maxDist);
// descr1 from image1, descr2 from image2
std::vector<char> mask(matches.size(), 1);

但现在我想从这两个图像中绘制找到的匹配项。

这不起作用:

drawMatches(gmlimg, keylines, walls, keylines1, matches, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT);

这两个都不是:

drawLineMatches(gmlimg, keylines, walls, keylines1, matches, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT);

【问题讨论】:

  • 你怎么知道他们没有工作?您希望在哪个图像中进行匹配?对我来说,你应该尝试做cv::Scalar::all(255, 255, 255),你应该得到白线。此外,您从图像 2 到 1 得到匹配,但反过来绘制。(但我不知道 gmlimg 是图像 1 还是图像 2)
  • drawLineMatches 不起作用,因为匹配项必须是 std::vector<:dmatch>,但我的是 std::vector<:vector> > ,因为 radiusMatch 需要它。 drawMatches 需要关键点而不是关键线。 docs.opencv.org/3.0-beta/modules/line_descriptor/doc/…docs.opencv.org/2.4.8/modules/features2d/doc/…
  • drawMatches 不起作用的原因不一样吗?
  • 是的,你是对的,没有看到这一点,因为我只看到了关键点并且知道这就是它不起作用的原因(因为我有关键线而不是关键点)。但是如何使用 drawLineMatches 或其他函数绘制 std::vector<:vector> > 中的匹配项?
  • 我会这样回答好吗?

标签: c++ opencv c++11 computer-vision opencv3.0


【解决方案1】:

由于您获得的匹配为std::vector&lt; std::vector&lt;cv::DMatch&gt; &gt;,这是您在使用BinaryDescriptorMatcher 时所使用的,您可以按如下方式绘制匹配:

std::vector<DMatch> matches_to_draw;
std::vector< std::vector<DMatch> >matches_from_matcher;
std::vector< cv::Keypoint > keypoints_Object, keypoints_Scene; // Keypoints 
// Iterate through the matches from descriptor
for(unsigned int i = 0; i < matches_from_matcher.size(); i++)
{
    if (matches_from_matcher[i].size() >= 1)
    {
      cv::DMatch v = matches[i][0];
      /*
       May be you can add a filtering here for the matches
       Skip it if you want to see all the matches
       Something like this - avg is the average distance between all keypoint pairs
       double difference_for_each_match = fabs(keypoints_Object[v.queryIdx].pt.y
                                         - keypoints_Scene[v.trainIdx].pt.y);
       if( (fabs (avg - difference_for_each_match)) <= 5))
     {
       matches_to_draw.push_back(v);
     }
     */
     // This is for all matches
     matches_to_draw.push_back(v);
    }
}
cv::drawMatches(image, keypoints_Object, walls, keypoints_Scene, matches_to_draw, outImg, cv::Scalar::all(-1), cv::Scalar::all(-1), mask, DrawLinesMatchesFlags::DEFAULT);`

outImg 应该有匹配项和绘制的关键点。

如果有帮助请告诉我!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-12-19
    • 2016-10-26
    • 2013-03-25
    • 2021-10-09
    • 2015-05-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多