How to use flann based matcher, or generally flann in opencv?

前端 未结 2 553
失恋的感觉
失恋的感觉 2020-12-17 05:51

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

Please can somebody show me sample code o

相关标签:
2条回答
  • 2020-12-17 06:28

    Here's untested sample code

    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
    
     */
    

    Finding the most 'similar' image to the query image depends on your application. Perhaps the number of matched keypoints is adequate. Or you may need a more complex measure of similarity.

    0 讨论(0)
  • 2020-12-17 06:39

    To reduce the number of false positives, you can compare the first most nearest neighbor to the second most nearest neighbor by taking the ratio of there distances. distance(query,mostnearestneighbor)/distance(query,secondnearestneighbor) < T, the smaller the ratio is, the higher the distance of the second nearest neighbor to the query descriptor. This thus is a translation of high distinctiveness. Used in many computer vision papers that envision registration.

    0 讨论(0)
提交回复
热议问题