1

我正在尝试将模板图像中的 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)哪个返回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]);原始帖子中显示的位置。

4

1 回答 1

2

代码中有两个问题:

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

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

于 2015-01-14T13:02:54.637 回答