在OpenCV中使用FeatureDetector会导致访问冲突

时间:2013-07-22 10:18:05

标签: c++ opencv feature-detection

我需要找到并匹配立体图像中的特征点。因此,我想比较OpenCV 2.4.5中支持的不同特征检测算法。通过将“SURF”,“SIFT”等传递给函数。

代码段:

#include "opencv2/opencv.hpp"
#include <opencv/highgui.h>
#include <opencv2/nonfree/features2d.hpp>

using namespace cv;
using namespace std;

...

void DisparityAnalysis::detectKeyPoints(Mat1b leftImageGrey, Mat1b rightImageGrey, string algorithmName)
{
    Ptr<FeatureDetector> detector = FeatureDetector::create(algorithmName);
    detector->detect(leftImageGrey, keypoints_1);
    detector->detect(rightImageGrey, keypoints_2);
}

错误:

Unhandled exception at 0x770b15de in DisparityAnalysis.exe: 0xC0000005: Access violation reading location 0x00000000.

我已经搜索了解决方案并发现了这个:Access violation reading in FeatureDetector OpenCV 2.4.5我认识到的不同之处是,他们在开头使用了cv :: initModule_nonfree()。但是当它复制到我的代码中时,它无法编译,因为找不到标识符。 有什么建议吗?

1 个答案:

答案 0 :(得分:3)

对于SIFT和SURF,您需要非自由模块,即:

  • 包括“opencv2 / nonfree / nonfree.hpp”

  • 在开头调用cv :: initModule_nonfree()

  • 链接opencv_nonfree2.4.x.lib