【问题标题】:How to use flann based matcher, or generally flann in opencv?如何在opencv中使用基于flann的匹配器,或者一般是flann?
【发布时间】:2011-04-17 17:15:53
【问题描述】:

http://opencv.willowgarage.com/documentation/cpp/features2d_common_interfaces_of_descriptor_matchers.html#flannbasedmatcher

请有人给我看示例代码或告诉我如何使用这个类和方法。 我只想将查询图像中的 SURF 与通过应用 Flann 设置的图像匹配。我在示例中看到了许多图像匹配代码,但我仍然难以理解的是量化图像与其他图像的相似程度的指标。任何帮助将不胜感激。

【问题讨论】:

    标签: opencv computer-vision


    【解决方案1】:

    这是未经测试的示例代码

    using namespace std;
    using namespace cv;
    
    Mat query; //the query image
    vector<Mat> images;   //set of images in your db
    
    /* ... get the images from somewhere   ... */
    
    vector<vector<KeyPoint> > dbKeypoints;
    vector<Mat> dbDescriptors;
    
    vector<KeyPoint> queryKeypoints;
    Mat queryDescriptors;
    
    /* ... Extract the descriptors ... */
    
    FlannBasedMatcher flannmatcher;
    
    //train with descriptors from your db
     flannmatcher.add(dbDescriptors);
     flannmatcher.train();
    
    vector<DMatch > matches;
    
    flannmatcher.match(queryDescriptors, matches);
    
    /* for kk=0 to matches.size()
    
           the best match for queryKeypoints[matches[kk].queryIdx].pt 
           is dbKeypoints[matches[kk].imgIdx][matches[kk].trainIdx].pt
    
     */
    

    查找与查询图像最“相似”的图像取决于您的应用程序。也许匹配的关键点的数量就足够了。或者您可能需要更复杂的相似性度量。

    【讨论】:

    • 感谢回复,“queryKeypoints[matches[kk].queryIdx].pt 的最佳匹配是 dbKeypoints[matches[kk].imgIdx][matches[kk].trainIdx].pt”这部分怎么做,如何确定最佳匹配,opencv中要实现的任何算法或方法。
    • 函数调用flannmatcher.match(queryDescriptors, matches);做匹配。您所要做的就是使用向量匹配中的索引。
    • 抱歉回复晚了,谢谢,终于明白索引的事情了。无论如何,我正在努力减少误报,你能建议任何复杂的相似性衡量标准吗?
    • @Sammy:这样可以从不同大小的不同训练图像中计算单应性吗?我的意思是当你必须做perspectiveTransform(时你会通过哪个训练图像的哪个角落?
    【解决方案2】:

    为了减少误报的数量,您可以通过计算距离的比率来比较第一个最近的邻居和第二个最近的邻居。 distance(query,mostnearestneighbor)/distance(query,secondnearestneighbor)

    【讨论】:

      猜你喜欢
      • 2018-06-09
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-21
      • 1970-01-01
      • 2015-07-21
      • 2018-09-12
      相关资源
      最近更新 更多