OpenCV - 从yml加载描述符 - 没有匹配的函数调用

时间:2015-01-14 10:28:21

标签: c++ opencv feature-detection surf flannbasedmatcher

我尝试将模板图片中的SURF关键点与视频Feed中显示的内容进行匹配,但在尝试调用FlannBasedMatcher时出现以下错误。

captureFromCam.cpp: In function ‘void matchAndDrawKeypoints(cv::Mat, IplImage*)’:
captureFromCam.cpp:110:55: error: no matching function for call to ‘cv::FlannBasedMatcher::match(cv::FileNode&, cv::Mat&, std::vector<cv::DMatch>&)’
captureFromCam.cpp:110:55: note: candidates are:
In file included from /usr/local/include/opencv/cv.h:68:0,
                 from captureFromCam.cpp:2:
/usr/local/include/opencv2/features2d/features2d.hpp:1110:18: note: void cv::DescriptorMatcher::match(const cv::Mat&, const cv::Mat&, std::vector<cv::DMatch>&, const cv::Mat&) const
/usr/local/include/opencv2/features2d/features2d.hpp:1110:18: note:   no known conversion for argument 1 from ‘cv::FileNode’ to ‘const cv::Mat&’
/usr/local/include/opencv2/features2d/features2d.hpp:1128:18: note: void cv::DescriptorMatcher::match(const cv::Mat&, std::vector<cv::DMatch>&, const std::vector<cv::Mat>&)
/usr/local/include/opencv2/features2d/features2d.hpp:1128:18: note:   no known conversion for argument 1 from ‘cv::FileNode’ to ‘const cv::Mat&’

我试图通过读取图像,计算关键点和描述符并以yml格式保存它们来做到这一点:

// code to detect features/descriptors
...
  cv::FileStorage fs(fileNamePostCut + ".yml", cv::FileStorage::WRITE);
  write(fs, fileNamePostCut + "Keypoints_1", keypoints_1);
  write(fs, fileNamePostCut + "Descriptors_1", img_descriptors_1);
  fs.release();

在一个单独的函数中,我然后尝试加载关键点和描述符,并将它们与为视频流计算的值进行比较:

matchAndDrawKeypoints (cv::Mat img_1, IplImage* frames)
      std::vector<cv::KeyPoint> templateKeypoints;
      std::vector<cv::KeyPoint> templateDescriptor;
      cv::FileStorage fs2("VWlogo.yml", cv::FileStorage::READ);
      cv::FileNode kptFileNode = fs2["VWlogoKeypoints_1"];
      read(kptFileNode, templateKeypoints);
      cv::FileNode desFileNode = fs2["VWlogoDescriptors_1"];
      read(desFileNode, templateDescriptor);
      fs2.release();
      cv::FlannBasedMatcher matcher;
      std::vector<cv::DMatch> matches;
      matcher.match(desFileNode, img_descriptors_1, matches);

我假设问题是来自yml文件的描述符没有正确加载,或者视频输入的描述符没有正确传递。

以下是有关信息流的一些额外信息:

main()调用makeitgrey(frame)来电detectKeypoints(grey_frame),返回makeitgrey(),返回main()然后调用matchAndDrawKeypoints (img_1, frames)

编辑: 计算关键点和声明的代码。

cv::Mat img_keypoints_1;
cv::Mat img_1;
cv::Mat img_descriptors_1;
std::vector<cv::KeyPoint> keypoints_1;
std::vector<cv::KeyPoint> descriptors_1;

main()将视频传递给makeitgrey(),传递给:

IplImage* detectKeypointsImage (IplImage* img_1) {
  int minHessian = 400;
  cv::SurfFeatureDetector detector(minHessian);
  detector.detect(img_1, keypoints_1);
  drawKeypoints(img_1, keypoints_1, img_keypoints_1);
  cv::SurfDescriptorExtractor extractor;
  extractor.compute(img_1, keypoints_1, img_descriptors_1);
  return img_1;
}

模板图像作为命令行arg传入,然后传递给原始帖子中显示的detectTemplateKeypoints(img_1, argv[1]);

1 个答案:

答案 0 :(得分:2)

代码中存在两个问题:

  1. std::vector<cv::KeyPoint> templateDescriptor;不是描述符的正确类型。用于描述符计算。在http://docs.opencv.org/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html的示例代码中,您可以看到,一堆关键点的描述符通常是类型cv::Mat。因此,请将其更改为cv::Mat templateDescriptor;cv::Mat descriptors_1;

  2. matcher.match(desFileNode, img_descriptors_1, matches);必须是matcher.match(templateDescriptor, img_descriptors_1, matches);,因为您要匹配描述符而不是文件存储节点。