如何使用基于flann的匹配器,或者通常在opencv中使用flann?

Aqu*_*Ash 3 opencv computer-vision

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

请有人可以给我看示例代码或告诉我如何使用这个类和方法.我只想将查询图像中的SURF与应用Flann的图像集匹配.我在样本中看到了很多图像匹配代码,但仍然没有得到的是量化图像与其他图像相似程度的指标.任何帮助都感激不尽.

Sam*_*mmy 10

这是未经测试的示例代码

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

 */
Run Code Online (Sandbox Code Playgroud)

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