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?