SiftFeatureDetector .detect function broken?

2019-07-30 19:17发布

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条回答
2楼-- · 2019-07-30 19:35

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");
查看更多
登录 后发表回答