Feature Matching with FLANN - Exception on "nonfree_init.cpp"
HI! I'm new to OpenCV. I use opencv 2.4.3 with Visual Studio 2010 Express on Windows 7. To better understand OpenCV, I created a project on matching using SURF and FLANN. I just copied / pasted the code from the opencv tutorial.
I report my code:
#include <stdio.h>
#include <iostream>
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/core/include/opencv2/core/core.hpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/features2d/include/opencv2/features2d/features2d.hpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/highgui/include/opencv2/highgui/highgui.hpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/nonfree/include/opencv2/nonfree/features2d.hpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/nonfree/include/opencv2/nonfree/nonfree.hpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/nonfree/src/surf.cpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/nonfree/src/sift.cpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/nonfree/src/nonfree_init.cpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/calib3d/include/opencv2/calib3d/calib3d.hpp"
#include "C:/Users/Cristina/Desktop/OpenCV/opencv/modules/imgproc/include/opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
int main()
{
Mat img_1 = cvLoadImage( "box.png", CV_LOAD_IMAGE_GRAYSCALE );
Mat img_2 = cvLoadImage( "box_in_scene.png", CV_LOAD_IMAGE_GRAYSCALE );
namedWindow("Good Matches", CV_WINDOW_AUTOSIZE);
imshow("Good Matches",img_1);
namedWindow("Good Matches1", CV_WINDOW_AUTOSIZE);
imshow("Good Matches1",img_2);
if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl;
system("pause");
return -1; }
//-- Step 1: Detect the keypoints using SURF Detector
cv::initModule_nonfree();
int minHessian = 400;
SurfFeatureDetector detector( minHessian );
vector<KeyPoint> keypoints_1, keypoints_2;
printf("arriva qui 1\n");
detector.detect( img_1, keypoints_1);
printf("arriva qui 2\n");
detector.detect( img_2, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2;
extractor.compute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher;
std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches );
double max_dist = 0; double min_dist = 100;
//-- Quick calculation of max and min distances between keypoints
for( int i = 0; i < descriptors_1.rows; i++ )
{ double dist = matches[i].distance;
if( dist < min_dist ) min_dist = dist;
if( dist > max_dist ) max_dist = dist;
}
printf("-- Max dist : %f \n", max_dist );
printf("-- Min dist : %f \n", min_dist );
//-- Draw only "good" matches (i.e. whose distance is less than 2*min_dist )
//-- PS.- radiusMatch can also be used here.
std::vector< DMatch > good_matches;
for( int i = 0; i < descriptors_1.rows; i++ )
{ if( matches[i].distance < 2*min_dist )
{ good_matches.push_back( matches[i]); }
}
//-- Draw only "good" matches
Mat img_matches;
drawMatches( img_1, keypoints_1, img_2, keypoints_2,
good_matches, img_matches, Scalar::all(-1), Scalar::all(-1),
vector<char>(), DrawMatchesFlags::NOT_DRAW_SINGLE_POINTS );
//-- Show detected matches
namedWindow("Good Matches2",CV_WINDOW_AUTOSIZE);
imshow( "Good Matches2", img_matches );
for( int i = 0; i < (int)good_matches.size(); i++ )
{ printf( "-- Good Match [%d] Keypoint 1: %d -- Keypoint 2: %d \n", i, good_matches[i].queryIdx, good_matches[i].trainIdx ); }
waitKey(0);
return 0;
}
When I run my project, I get this exception about (I suppose) "nonfree_init.cpp" file:
(it seems to me that just does not come in the ...