1
Feature Description {#tutorial_feature_description}
7
In this tutorial you will learn how to:
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.
22
This tutorial code's is shown lines below.
26
#include "opencv2/core.hpp"
27
#include "opencv2/features2d.hpp"
28
#include "opencv2/highgui.hpp"
29
#include "opencv2/xfeatures2d.hpp"
32
using namespace cv::xfeatures2d;
37
int main( int argc, char** argv )
42
Mat img_1 = imread( argv[1], IMREAD_GRAYSCALE );
43
Mat img_2 = imread( argv[2], IMREAD_GRAYSCALE );
45
if( !img_1.data || !img_2.data )
48
//-- Step 1: Detect the keypoints using SURF Detector, compute the descriptors
51
Ptr<SURF> detector = SURF::create();
52
detector->setHessianThreshold(minHessian);
54
std::vector<KeyPoint> keypoints_1, keypoints_2;
55
Mat descriptors_1, descriptors_2;
57
detector->detectAndCompute( img_1, Mat(), keypoints_1, descriptors_1 );
58
detector->detectAndCompute( img_2, Mat(), keypoints_2, descriptors_2 );
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 );
67
drawMatches( img_1, keypoints_1, img_2, keypoints_2, matches, img_matches );
69
//-- Show detected matches
70
imshow("Matches", img_matches );
77
/* @function readme */
79
{ std::cout << " Usage: ./SURF_descriptor <img1> <img2>" << std::endl; }
88
Here is the result after applying the BruteForce matcher between the two original images:
90
![](images/Feature_Description_BruteForce_Result.jpg)