2

为什么 SIFT 和 SURF 检测器会崩溃?

using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{        
  Mat image = imread("TestImage.jpg");

  // Create smart pointer for SIFT feature detector.
  Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SIFT");
  vector<KeyPoint> keypoints;

  // Detect the keypoints
  featureDetector->detect(image, keypoints); // here crash
  // ...
}

错误是Segmentation fault (core dumped)。我使用 OpenCV 2.4.8、gcc 4.9 和 Ubuntu。如果我使用其他类型的功能,它会正常运行。我错过了什么?

4

1 回答 1

10

你试过打电话initModule_nonfree()吗?

#include <opencv2/nonfree/nonfree.hpp>
using namespace std;
using namespace cv;

int main(int argc, char *argv[])
{
  initModule_nonfree();
  Mat image = imread("TestImage.jpg");

  // Create smart pointer for SIFT feature detector.
  Ptr<FeatureDetector> featureDetector = FeatureDetector::create("SIFT");
  vector<KeyPoint> keypoints;

  // Detect the keypoints
  featureDetector->detect(image, keypoints); // here crash
  // ...
}

此外,您没有检查可能为空的指针 featureDetector(因为您没有调用 initModule)。

于 2014-05-13T12:09:04.300 回答