CLAHE Python bindings
[profile/ivi/opencv.git] / doc / tutorials / features2d / feature_detection / feature_detection.rst
1 .. _feature_detection:
2
3 Feature Detection
4 ******************
5
6 Goal
7 =====
8
9 In this tutorial you will learn how to:
10
11 .. container:: enumeratevisibleitemswithsquare
12
13    * Use the :feature_detector:`FeatureDetector<>` interface in order to find interest points. Specifically:
14
15      * Use the :surf_feature_detector:`SurfFeatureDetector<>` and its function :feature_detector_detect:`detect<>` to perform the detection process
16      * Use the function :draw_keypoints:`drawKeypoints<>` to draw the detected keypoints
17
18
19 Theory
20 ======
21
22 Code
23 ====
24
25 This tutorial code's is shown lines below. You can also download it from `here <http://code.opencv.org/projects/opencv/repository/revisions/master/raw/samples/cpp/tutorial_code/features2D/SURF_detector.cpp>`_
26
27 .. code-block:: cpp
28
29    #include <stdio.h>
30    #include <iostream>
31    #include "opencv2/core/core.hpp"
32    #include "opencv2/features2d/features2d.hpp"
33    #include "opencv2/highgui/highgui.hpp"
34
35    using namespace cv;
36
37    void readme();
38
39    /** @function main */
40    int main( int argc, char** argv )
41    {
42      if( argc != 3 )
43      { readme(); return -1; }
44
45      Mat img_1 = imread( argv[1], CV_LOAD_IMAGE_GRAYSCALE );
46      Mat img_2 = imread( argv[2], CV_LOAD_IMAGE_GRAYSCALE );
47
48      if( !img_1.data || !img_2.data )
49      { std::cout<< " --(!) Error reading images " << std::endl; return -1; }
50
51      //-- Step 1: Detect the keypoints using SURF Detector
52      int minHessian = 400;
53
54      SurfFeatureDetector detector( minHessian );
55
56      std::vector<KeyPoint> keypoints_1, keypoints_2;
57
58      detector.detect( img_1, keypoints_1 );
59      detector.detect( img_2, keypoints_2 );
60
61      //-- Draw keypoints
62      Mat img_keypoints_1; Mat img_keypoints_2;
63
64      drawKeypoints( img_1, keypoints_1, img_keypoints_1, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
65      drawKeypoints( img_2, keypoints_2, img_keypoints_2, Scalar::all(-1), DrawMatchesFlags::DEFAULT );
66
67      //-- Show detected (drawn) keypoints
68      imshow("Keypoints 1", img_keypoints_1 );
69      imshow("Keypoints 2", img_keypoints_2 );
70
71      waitKey(0);
72
73      return 0;
74      }
75
76      /** @function readme */
77      void readme()
78      { std::cout << " Usage: ./SURF_detector <img1> <img2>" << std::endl; }
79
80 Explanation
81 ============
82
83 Result
84 ======
85
86 #. Here is the result of the feature detection applied to the first image:
87
88    .. image:: images/Feature_Detection_Result_a.jpg
89       :align: center
90       :height: 125pt
91
92 #. And here is the result for the second image:
93
94    .. image:: images/Feature_Detection_Result_b.jpg
95       :align: center
96       :height: 200pt
97