SiftFeatureDetector .detect function broken?

假如想象 提交于 2019-12-11 09:19:15

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!