c++ - BFMatcher knnMatch

标签 c++ opencv brute-force

我尝试在 BFMatcher 上实现 knnMatch,如下所示:

BFMatcher matcher(NORM_L2, true);
vector<DMatch> matches;
//matcher.match(descriptors1, descriptors2, matches);
matcher.knnMatch(descriptors1, descriptors2, matches, 2);

并收到以下错误:

fiducialMain.cpp: In function ‘void fiducialCalc(cv::Mat, cv::Mat, cv::Mat&, cv::Mat&, int&)’:
fiducialMain.cpp:98:56: error: no matching function for call to ‘cv::BFMatcher::knnMatch(cv::Mat&, cv::Mat&, std::vector<cv::DMatch>&, int)’
  matcher.knnMatch(descriptors1, descriptors2, matches,2);
                                                        ^
fiducialMain.cpp:98:56: note: candidates are:
In file included from fiducialMain.cpp:15:0:
/usr/local/include/opencv2/features2d/features2d.hpp:1116:18: note: void cv::DescriptorMatcher::knnMatch(const cv::Mat&, const cv::Mat&, std::vector<std::vector<cv::DMatch> >&, int, const cv::Mat&, bool) const
     CV_WRAP void knnMatch( const Mat& queryDescriptors, const Mat& trainDescriptors,
                  ^
/usr/local/include/opencv2/features2d/features2d.hpp:1116:18: note:   no known conversion for argument 3 from ‘std::vector<cv::DMatch>’ to ‘std::vector<std::vector<cv::DMatch> >&’
/usr/local/include/opencv2/features2d/features2d.hpp:1130:18: note: void cv::DescriptorMatcher::knnMatch(const cv::Mat&, std::vector<std::vector<cv::DMatch> >&, int, const std::vector<cv::Mat>&, bool)
     CV_WRAP void knnMatch( const Mat& queryDescriptors, CV_OUT vector<vector<DMatch> >& matches, int k,
                  ^
/usr/local/include/opencv2/features2d/features2d.hpp:1130:18: note:   no known conversion for argument 2 from ‘cv::Mat’ to ‘std::vector<std::vector<cv::DMatch> >&’

谁能解释这个错误?

最佳答案

请再看看the docs

而普通的匹配函数有一个vector<DMatch>结果,

knnMatch(大声说:k-nearest-neighbours!)产生几个(k)个 vector ,因此你需要一个:

vector < vector >匹配

结果

关于c++ - BFMatcher knnMatch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28729880/

相关文章:

string - 字符串中连续 1 的最大数目

c++ - std::map 插入陷入无限循环或给出访问冲突错误

android - 语句无效 'AVPacket'

>4.1.2 中未调用 Android 相机更新回调

python - 检测 OCR 文本图像是否上下颠倒

opencv - 关于安装开放式简历库

c++ - 为什么不同编译器的ascii值有差异

c++ - 动态库的链接问题

Python - 生成 string.ascii_lowercase 的紊乱

arrays - 股票价格的最大利润