请有人能告诉我示例代码或告诉我如何使用这个类和方法。 我只想将查询图像中的 SURF 与通过应用 Flann 设置的图像相匹配。我在示例中看到过许多图像匹配代码,但我仍然无法理解的是量化图像与其他图像相似程度的指标。任何帮助将不胜感激。
最佳答案
这是未经测试的示例代码
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
*/
找到与查询图像最“相似”的图像取决于您的应用程序。也许匹配的关键点的数量是足够的。或者您可能需要更复杂的相似性度量。
关于opencv - 如何使用基于 flann 的匹配器,或者通常在 opencv 中使用 flann?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5695034/