OpenCV SurfDescriptorExtractor编译错误

时间:2012-04-13 21:56:17

标签: c++ opencv compilation

当尝试编译特征检测算法时,我得到以下编译错误: 我正在使用clang编译/链接,而我的OpenCV版本是2.3.1版本。我(大致)按照本教程进行功能匹配:http://opencv.itseez.com/doc/tutorials/features2d/feature_flann_matcher/feature_flann_matcher.html

error: use of undeclared identifier 'SurfDescriptorExtractor';
      did you mean 'OrbDescriptorExtractor'?
SurfDescriptorExtractor extractor;
^

有趣的是,Brief和Orb描述符提取器工作"很好"(我最终得到运行时错误)。

以下是相关代码:

void setup_and_draw_keypoints(Mat& img, Mat& prev)
{
  // Detect Keypoints
  vector<KeyPoint> keypoints, prev_keypoints;
  GoodFeaturesToTrackDetector gftt;
  gftt.detect(img, keypoints);
  gftt.detect(prev, prev_keypoints);

  //Extract Descriptors
  SurfDescriptorExtractor extractor;
  Mat desc_1, desc_2; // Descriptors
  extractor.compute(img, keypoints, desc_1);
  extractor.compute(prev, prev_keypoints, desc_2);
  FlannBasedMatcher matcher;
  vector<DMatch> matches;

  matcher.match(desc_1, desc_2, matches);
}

2 个答案:

答案 0 :(得分:1)

您链接到的教程是在将features2d库分离为免费(非专利,开放许可)算法之前编写的,以及未经公开许可的内容。 SURF和SIFT是两种这样的算法。要访问SurfFeatureDescriptor,您需要做的就是包含来自nonfree includes文件夹的features2d.hpp标头。

在我的opencv发行版(我目前正在使用2.4.1)中,它位于:“C:\ Users \ Jake \ Downloads \ opencv \ modules \ nonfree \ include \ opencv2 \ nonfree \ features2d.hpp”。我在项目设置中将路径“C:\ Users \ Jake \ Downloads \ opencv \ modules \ nonfree \ include \”列为包含目录,因此在我的代码中我所做的只是:

#include <opencv2/nonfree/features2d.hpp>

SiftDescriptorExtractor siftExtractor;
//Later on in the file, after a frame has been grabbed, keypoints found, etc.
Mat siftDescriptors;
siftExtractor.compute(frame,roiKP,siftDescriptors);

你有它。希望这对您来说还不算太晚。

答案 1 :(得分:0)

某些内容存在于您的库的文档中并不一定意味着它位于库的.so和标题中;)

Open CV有多个模块,其中一个是flann,可能只在安装了flann时才编译,你甚至可能需要明确要求它。当您在opencv的源tar.gz下载中运行cmake或cmake-gui时,您可以选择要编译的模块。

也许你没有从源代码编译opencv,在这种情况下你的linux系统软件包维护者做了,可能没有包含它。

这是你可能会发现的:

[herbert@Durk ~]$ ls /usr/lib/libopencv_*.so
/usr/lib/libopencv_calib3d.so  /usr/lib/libopencv_features2d.so      /usr/lib/libopencv_highgui.so  /usr/lib/libopencv_ml.so         /usr/lib/libopencv_photo.so          /usr/lib/libopencv_video.so
/usr/lib/libopencv_contrib.so  /usr/lib/libopencv_flann.so           /usr/lib/libopencv_imgproc.so  /usr/lib/libopencv_nonfree.so        /usr/lib/libopencv_stitching.so  /usr/lib/libopencv_videostab.so
/usr/lib/libopencv_core.so     /usr/lib/libopencv_gpu.so             /usr/lib/libopencv_legacy.so   /usr/lib/libopencv_objdetect.so  /usr/lib/libopencv_ts.so
[herbert@Durk ~]$ ls /usr/include/opencv2/
calib3d  contrib  core  features2d  flann  gpu  highgui  imgproc  legacy  ml  nonfree      objdetect  opencv.hpp  opencv_modules.hpp  photo  stitching  ts  video  videostab
[herbert@Durk ~]$ 

正如你所看到的,我很幸运能安装了flann;)