~paparazzi-uav/paparazzi/v5.0-manual

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/doc/tutorials/features2d/feature_description/feature_description.markdown

  • Committer: Paparazzi buildbot
  • Date: 2016-05-18 15:00:29 UTC
  • Revision ID: felix.ruess+docbot@gmail.com-20160518150029-e8lgzi5kvb4p7un9
Manual import commit 4b8bbb730080dac23cf816b98908dacfabe2a8ec from v5.0 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Feature Description {#tutorial_feature_description}
 
2
===================
 
3
 
 
4
Goal
 
5
----
 
6
 
 
7
In 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
 
 
16
Theory
 
17
------
 
18
 
 
19
Code
 
20
----
 
21
 
 
22
This 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
 
 
31
using namespace cv;
 
32
using namespace cv::xfeatures2d;
 
33
 
 
34
void readme();
 
35
 
 
36
/* @function main */
 
37
int 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
 
 
82
Explanation
 
83
-----------
 
84
 
 
85
Result
 
86
------
 
87
 
 
88
Here is the result after applying the BruteForce matcher between the two original images:
 
89
 
 
90
![](images/Feature_Description_BruteForce_Result.jpg)