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。如果我使用其他类型的功能,它将正常运行。我想念什么?

最佳答案

您是否尝试致电 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)。

关于c++ - OpenCV:为什么SIFT和SURF检测器崩溃?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23630704/

10-15 16:46