Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
629 views
in Technique[技术] by (71.8m points)

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

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

Please can somebody show me sample code or tell me how to use this class and methods. I just want to match SURF's from a query image to those with an image set by applying Flann. I have seen many image match code in the samples but what still eludes me is a metric to quantify how similar an image is to other. Any help will be much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...