Merge pull request #3788 from berak:fix_features2d_tut

This commit is contained in:
Vadim Pisarevsky 2015-03-05 12:22:50 +00:00
commit 2baf1a3c9f
2 changed files with 11 additions and 24 deletions

View File

@ -54,25 +54,19 @@ int main( int argc, char** argv )
if( !img_1.data || !img_2.data ) if( !img_1.data || !img_2.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; } { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors
int minHessian = 400; int minHessian = 400;
SurfFeatureDetector detector( minHessian ); Ptr<SURF> detector = SURF::create();
detector->setMinHessian(minHessian);
std::vector<KeyPoint> keypoints_1, keypoints_2; std::vector<KeyPoint> keypoints_1, keypoints_2;
detector.detect( img_1, keypoints_1 );
detector.detect( img_2, keypoints_2 );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_1, descriptors_2; Mat descriptors_1, descriptors_2;
extractor.compute( img_1, keypoints_1, descriptors_1 ); detector->detectAndCompute( img_1, keypoints_1, descriptors_1 );
extractor.compute( img_2, keypoints_2, descriptors_2 ); detector->detectAndCompute( img_2, keypoints_2, descriptors_2 );
//-- Step 3: Matching descriptor vectors using FLANN matcher //-- Step 2: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher; FlannBasedMatcher matcher;
std::vector< DMatch > matches; std::vector< DMatch > matches;
matcher.match( descriptors_1, descriptors_2, matches ); matcher.match( descriptors_1, descriptors_2, matches );

View File

@ -42,25 +42,18 @@ int main( int argc, char** argv )
if( !img_object.data || !img_scene.data ) if( !img_object.data || !img_scene.data )
{ std::cout<< " --(!) Error reading images " << std::endl; return -1; } { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
//-- Step 1: Detect the keypoints using SURF Detector //-- Step 1: Detect the keypoints and extract descriptors using SURF
int minHessian = 400; int minHessian = 400;
SurfFeatureDetector detector( minHessian ); Ptr<SURF> detector = SURF::create( minHessian );
std::vector<KeyPoint> keypoints_object, keypoints_scene; std::vector<KeyPoint> keypoints_object, keypoints_scene;
detector.detect( img_object, keypoints_object );
detector.detect( img_scene, keypoints_scene );
//-- Step 2: Calculate descriptors (feature vectors)
SurfDescriptorExtractor extractor;
Mat descriptors_object, descriptors_scene; Mat descriptors_object, descriptors_scene;
extractor.compute( img_object, keypoints_object, descriptors_object ); detector->detectAndCompute( img_object, keypoints_object, descriptors_object );
extractor.compute( img_scene, keypoints_scene, descriptors_scene ); detector->detectAndCompute( img_scene, keypoints_scene, descriptors_scene );
//-- Step 3: Matching descriptor vectors using FLANN matcher //-- Step 2: Matching descriptor vectors using FLANN matcher
FlannBasedMatcher matcher; FlannBasedMatcher matcher;
std::vector< DMatch > matches; std::vector< DMatch > matches;
matcher.match( descriptors_object, descriptors_scene, matches ); matcher.match( descriptors_object, descriptors_scene, matches );