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

« back to all changes in this revision

Viewing changes to sw/ext/opencv_bebop/opencv/doc/tutorials/features2d/trackingmotion/good_features_to_track/good_features_to_track.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
Shi-Tomasi corner detector {#tutorial_good_features_to_track}
 
2
==========================
 
3
 
 
4
Goal
 
5
----
 
6
 
 
7
In this tutorial you will learn how to:
 
8
 
 
9
-   Use the function @ref cv::goodFeaturesToTrack to detect corners using the Shi-Tomasi method.
 
10
 
 
11
Theory
 
12
------
 
13
 
 
14
Code
 
15
----
 
16
 
 
17
This tutorial code's is shown lines below. You can also download it from
 
18
[here](https://github.com/Itseez/opencv/tree/master/samples/cpp/tutorial_code/TrackingMotion/goodFeaturesToTrack_Demo.cpp)
 
19
@code{.cpp}
 
20
#include "opencv2/highgui.hpp"
 
21
#include "opencv2/imgproc.hpp"
 
22
#include <iostream>
 
23
#include <stdio.h>
 
24
#include <stdlib.h>
 
25
 
 
26
using namespace cv;
 
27
using namespace std;
 
28
 
 
29
/// Global variables
 
30
Mat src, src_gray;
 
31
 
 
32
int maxCorners = 23;
 
33
int maxTrackbar = 100;
 
34
 
 
35
RNG rng(12345);
 
36
char* source_window = "Image";
 
37
 
 
38
/// Function header
 
39
void goodFeaturesToTrack_Demo( int, void* );
 
40
 
 
41
/*
 
42
 * @function main
 
43
 */
 
44
int main( int argc, char** argv )
 
45
{
 
46
  /// Load source image and convert it to gray
 
47
  src = imread( argv[1], 1 );
 
48
  cvtColor( src, src_gray, COLOR_BGR2GRAY );
 
49
 
 
50
  /// Create Window
 
51
  namedWindow( source_window, WINDOW_AUTOSIZE );
 
52
 
 
53
  /// Create Trackbar to set the number of corners
 
54
  createTrackbar( "Max  corners:", source_window, &maxCorners, maxTrackbar, goodFeaturesToTrack_Demo );
 
55
 
 
56
  imshow( source_window, src );
 
57
 
 
58
  goodFeaturesToTrack_Demo( 0, 0 );
 
59
 
 
60
  waitKey(0);
 
61
  return(0);
 
62
}
 
63
 
 
64
/*
 
65
 * @function goodFeaturesToTrack_Demo.cpp
 
66
 * @brief Apply Shi-Tomasi corner detector
 
67
 */
 
68
void goodFeaturesToTrack_Demo( int, void* )
 
69
{
 
70
  if( maxCorners < 1 ) { maxCorners = 1; }
 
71
 
 
72
  /// Parameters for Shi-Tomasi algorithm
 
73
  vector<Point2f> corners;
 
74
  double qualityLevel = 0.01;
 
75
  double minDistance = 10;
 
76
  int blockSize = 3;
 
77
  bool useHarrisDetector = false;
 
78
  double k = 0.04;
 
79
 
 
80
  /// Copy the source image
 
81
  Mat copy;
 
82
  copy = src.clone();
 
83
 
 
84
  /// Apply corner detection
 
85
  goodFeaturesToTrack( src_gray,
 
86
               corners,
 
87
               maxCorners,
 
88
               qualityLevel,
 
89
               minDistance,
 
90
               Mat(),
 
91
               blockSize,
 
92
               useHarrisDetector,
 
93
               k );
 
94
 
 
95
 
 
96
  /// Draw corners detected
 
97
  cout<<"** Number of corners detected: "<<corners.size()<<endl;
 
98
  int r = 4;
 
99
  for( size_t i = 0; i < corners.size(); i++ )
 
100
     { circle( copy, corners[i], r, Scalar(rng.uniform(0,255), rng.uniform(0,255),
 
101
              rng.uniform(0,255)), -1, 8, 0 ); }
 
102
 
 
103
  /// Show what you got
 
104
  namedWindow( source_window, WINDOW_AUTOSIZE );
 
105
  imshow( source_window, copy );
 
106
}
 
107
@endcode
 
108
Explanation
 
109
-----------
 
110
 
 
111
Result
 
112
------
 
113
 
 
114
![](images/Feature_Detection_Result_a.jpg)