1

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

ipunished
  • 684
  • 2
  • 6
  • 22
  • People are more likely to help you if you are more specific about how it 'breaks'. What kind of error do you get? Is an assertion being thrown? Etc. – Aurelius Oct 31 '12 at 16:10
  • Thanks, details added. Is this the required error you were talking about? – ipunished Oct 31 '12 at 16:21
  • It sounds like the image may not be being read correctly. Make sure your image data is not `NULL` before you call `detect()` – Aurelius Oct 31 '12 at 16:29
  • Thanks, I tried that before too and I edited the imshow with this: ``imshow("meh", img);`` and when I run it (after commenting the problematic line) It displays the image correctly. Hence it is being read. – ipunished Oct 31 '12 at 16:33
  • I think I should also note that when I debug step by step, and check the value of keypoints just before the error, it has two parameters; size and capacity: both of which has a value of 0 – ipunished Oct 31 '12 at 16:36
  • Please also include information about which version of OpenCV you are using and what platform you are developing on. I just tried your top code on OSX Mountain Lion using OpenCV 2.4.2 (and a different image file, of course) and it worked. – Aurelius Oct 31 '12 at 16:46
  • Thanks, details added to original post. – ipunished Oct 31 '12 at 16:48
  • @Aurelius you said it worked when you tried it out. can you please mention which libraries you used, the #include ones. I have almost every one related to features detection and still get the same error – ipunished Nov 01 '12 at 00:33

1 Answers1

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");
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91