问题
Why do the SIFT and SURF detectors crash?
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
// ...
}
The error is Segmentation fault (core dumped)
. I use OpenCV 2.4.8, gcc 4.9 and Ubuntu. If I use the other types of features it runs normally. What am I missing?
回答1:
Have you tried to call 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
// ...
}
Also, you didnt check the pointer featureDetector which is probably null (since you have not called initModule).
来源:https://stackoverflow.com/questions/23630704/opencv-why-sift-and-surf-detectors-crashes