如何在OpenCV C++中使用FeatureDetector

How to use FeatureDetector in OpenCV C++?

本文关键字:FeatureDetector C++ OpenCV      更新时间:2023-10-16

我使用的是根据安装指南安装了OpenCV 2.1的VS 2008。FeatureDetector/SurfFeatureDetector在文档中被列为类,但它们被视为"语法错误:标识符‘SurfFeatureDetetor’">

这几乎是我的全部代码。

#include "cv.h"
#include "highgui.h"
Ptr<FeatureDetector> *detect = new SurfFeatureDetector();

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

您正在声明一个指向cv::Ptr的指针——您实际上应该只有cv::Ptr。将代码更改为

#include "cv.h"
#include "highgui.h"
using namespace cv;
Ptr<FeatureDetector> detect = new SurfFeatureDetector();

它应该起作用。

我认为您有安装问题,请尝试从以下位置重新安装:sourceforge.net/projects/opencvlibrary/files/opencv-win/2.2

另一种选择是预编译器已经定义了__OPENCV_OLD_CV_H__。尝试在#include "cv.h" 之前取消定义

当您键入#include "cv.h"时它应该自动包含featus2d。事实上,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"

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

#include "opencv2/features2d/features2d.hpp"
#include "cv.h"
#include "highgui.h"
using namespace cv;
Ptr<FeatureDetector> detect = new SurfFeatureDetector();

您需要:

#include <opencv2/nonfree/nonfree.hpp>

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