1Feature Description {#tutorial_feature_description} 2=================== 3 4Goal 5---- 6 7In this tutorial you will learn how to: 8 9- Use the @ref cv::DescriptorExtractor interface in order to find the feature vector correspondent 10 to the keypoints. Specifically: 11 - Use cv::xfeatures2d::SURF and its function cv::xfeatures2d::SURF::compute to perform the 12 required calculations. 13 - Use a @ref cv::BFMatcher to match the features vector 14 - Use the function @ref cv::drawMatches to draw the detected matches. 15 16Theory 17------ 18 19Code 20---- 21 22This tutorial code's is shown lines below. 23@code{.cpp} 24#include <stdio.h> 25#include <iostream> 26#include "opencv2/core.hpp" 27#include "opencv2/features2d.hpp" 28#include "opencv2/highgui.hpp" 29#include "opencv2/xfeatures2d.hpp" 30 31using namespace cv; 32using namespace cv::xfeatures2d; 33 34void readme(); 35 36/* @function main */ 37int main( int argc, char** argv ) 38{ 39 if( argc != 3 ) 40 { return -1; } 41 42 Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE ); 43 Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE ); 44 45 if( !img_1.data || !img_2.data ) 46 { return -1; } 47 48 //-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors 49 int minHessian = 400; 50 51 Ptr<SURF> detector = SURF::create(); 52 detector->setHessianThreshold(minHessian); 53 54 std::vector<KeyPoint> keypoints_1, keypoints_2; 55 Mat descriptors_1, descriptors_2; 56 57 detector->detectAndCompute( img_1, Mat(), keypoints_1, descriptors_1 ); 58 detector->detectAndCompute( img_2, Mat(), keypoints_2, descriptors_2 ); 59 60 //-- Step 2: Matching descriptor vectors with a brute force matcher 61 BFMatcher matcher(NORM_L2); 62 std::vector< DMatch > matches; 63 matcher.match( descriptors_1, descriptors_2, matches ); 64 65 //-- Draw matches 66 Mat img_matches; 67 drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches ); 68 69 //-- Show detected matches 70 imshow("Matches", img_matches ); 71 72 waitKey(0); 73 74 return 0; 75 } 76 77 /* @function readme */ 78 void readme() 79 { std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; } 80@endcode 81 82Explanation 83----------- 84 85Result 86------ 87 88Here is the result after applying the BruteForce matcher between the two original images: 89 90![](images/Feature_Description_BruteForce_Result.jpg) 91