0

I'm trying to use SIFT to match two images and i'm using the code below:

cv::initModule_nonfree(); 

cv::Mat matFrame(frame);
cv::Mat matFrameAnt(frameAnterior);

cv::SiftFeatureDetector detector(400);            //I've tried different values here
cv::SiftDescriptorExtractor extractor(400);       //but i get always the same error

std::vector<cv::KeyPoint> keypoints1;
std::vector<cv::KeyPoint> keypoints2;

detector.detect( matFrame, keypoints1 );
detector.detect( matFrameAnt, keypoints2 );

cv::Mat feat1;
cv::Mat feat2;
cv::Mat descriptor1;
cv::Mat descriptor2;

extractor.compute( matFrame, keypoints1, descriptor1 );
extractor.compute( matFrameAnt, keypoints2, descriptor2 );

    std::vector<cv::DMatch> matches;

cv::BFMatcher matcher(cv::NORM_L2, false); 

matcher.match(descriptor1,descriptor2, matches);

cv::Mat result;
cv::drawMatches( matFrame, keypoints1, matFrameAnt, keypoints2, matches, result );

cv::namedWindow("SIFT", CV_WINDOW_AUTOSIZE );
cv::imshow("SIFT", result);

I get this error when i run the code (it compiles perfectly).

"OpenCV Error: Assertion failed (firstOctave >= -1 && actualNlayers <= nOctaveLayers) in unknown function, file ......\src\opencv\modules\nonfree\src\sift.cpp, line 755".

I understand that that function is getting a non positive value, so i printed all the possible values from my code and i found out that the size of my two keypoints vectors are -616431 and -616422. The two images i'm using are black&white images, with a black blackground and my hand (white) in the middle of it.

What's happening? Am i using not valid images? Am i using the functions cv::SiftFeatureDetector and cv::SiftDescriptorExtractor wrong?

1 Answers1

0

It seems you have no clue what you are doing. This feature is fairly undocumented, therefore try digging into the source, or let me tell you what you did.

cv::SiftFeatureDetector detector(50)

This means you will get at most 50 matches.

cv::SiftDescriptorExtractor extractor(400);

This means your magnification for extration is 400x. This parameter should be in the order of "1" for normal results.

The rest of the documentation is here: http://docs.opencv.org/2.3/modules/features2d/doc/common_interfaces_of_feature_detectors.html#SiftFeatureDetector

TimZaman
  • 2,689
  • 2
  • 26
  • 36