问题
Ive been trying out SIFT/SURF from online resources and wanted to test it out myself.
I first tried without the non-free libraries using this code:
int _tmain(int argc, _TCHAR* argv[])
{
Mat img = imread("c:\\car.jpg", 0);
Ptr<FeatureDetector> feature_detector = FeatureDetector::create("SIFT");
vector<KeyPoint> keypoints;
feature_detector->detect(img, keypoints);
Mat output;
drawKeypoints(img, keypoints, output, Scalar(255, 0, 0));
namedWindow("meh", CV_WINDOW_AUTOSIZE);
imshow("meh", output);
waitKey(0);
return 0;
}
Here if I do a step by step debugging it breaks at feature_detector->detect(img, keypoints);
Then I tried using the non-free library and tried this code:
int main(int argc, char** argv)
{
const Mat input = cv::imread("/tmp/image.jpg", 0); //Load as grayscale
SiftFeatureDetector detector;
vector<KeyPoint> keypoints;
detector.detect(input, keypoints);
// Add results to image and save.
Mat output;
drawKeypoints(input, keypoints, output);
imwrite("/tmp/SIFT_RESULT.jpg", output);
return 0;
}
This again compiles without errors but when ran, breaks at this step: detector.detect(input, keypoints);
I cannot find the reason why. Can some one please help me out here.
Thank you
edit: This is the error I get when it breaks:
Unhandled exception at 0x007f0900 in SIFT.exe: 0xC0000005: Access violation reading location 0x00000000.
.
My setup: Microsoft Visual C++ 2010, OpenCV 2.4.2, Windows XP. All libraries added and linked
回答1:
Use color image not grayscale, it works for me that way.
You could try skipping "const" too, if the color image would not work either.
const Mat input = cv::imread("/tmp/image.jpg");
来源:https://stackoverflow.com/questions/13162074/siftfeaturedetector-detect-function-broken