2

我正在使用 VS 2008,按照安装指南安装了 OpenCV 2.1。FeatureDetector/SurfFeatureDetector 在文档中被列为类,但它们被认为是“语法错误:标识符'SurfFeatureDetector”

这几乎是我的全部代码。

#include "cv.h"
#include "highgui.h"

Ptr<FeatureDetector> *detect = new SurfFeatureDetector();

我已经尝试了一堆随机组合来让它工作。如何初始化特征检测器?

4

4 回答 4

3

你声明了一个指向 cv::Ptr 的指针——你真的应该只有 cv::Ptr。将您的代码更改为

#include "cv.h"
#include "highgui.h"

using namespace cv;
Ptr<FeatureDetector> detect = new SurfFeatureDetector();

它应该可以工作。

于 2011-07-01T22:28:04.727 回答
1

我认为你有安装问题,尝试从这里重新安装:sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2

另一个选项是您的预编译器已经__OPENCV_OLD_CV_H__定义。尝试取消定义它之前#include "cv.h"

当您键入时 #include "cv.h" ,它会自动包含 features2d。事实上 cv.h 包括以下内容:

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/tracking.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/flann/flann.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/legacy/compat.hpp"
于 2011-07-03T15:07:09.843 回答
0

您需要包含 OpenCV 2.x 风格的 C++。见下文

#include "opencv2/features2d/features2d.hpp"
#include "cv.h"
#include "highgui.h"

using namespace cv;
Ptr<FeatureDetector> detect = new SurfFeatureDetector();
于 2011-07-03T01:44:44.247 回答
0

你需要:

#include <opencv2/nonfree/nonfree.hpp>

(从这里:http ://answers.opencv.org/question/411/feature-detector-crash/ )

于 2012-12-06T12:47:22.623 回答