这里的未经测试示例代码
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中的方法。 – AquaAsh 2011-04-18 07:28:28
函数调用flannmatcher.match(queryDescriptors,matches);做匹配。你所要做的就是使用向量匹配中的索引。 – Sammy 2011-04-18 12:21:18
对不起,迟到的答复,谢谢,我终于明白了索引的事情。无论如何,我试图减少误报,你能否提出任何复杂的相似度量。 – AquaAsh 2011-04-25 13:32:54