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

前端 未结 2 558
失恋的感觉
失恋的感觉 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 images;   //set of images in your db
    
    /* ... get the images from somewhere   ... */
    
    vector > dbKeypoints;
    vector dbDescriptors;
    
    vector queryKeypoints;
    Mat queryDescriptors;
    
    /* ... Extract the descriptors ... */
    
    FlannBasedMatcher flannmatcher;
    
    //train with descriptors from your db
     flannmatcher.add(dbDescriptors);
     flannmatcher.train();
    
    vector 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.

提交回复
热议问题