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

OpenCV - loading descriptors from yml - no matching function call

我正在尝试将模板图像中的 SURF 关键点与视频源中显示的内容相匹配,但在尝试调用 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) 其中 returns 到 makeitgrey() 其中 returns 到 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]);,显示在原始 post.

代码中有两个问题:

  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);,因为您要匹配描述符而不是文件存储节点。