3 // Here is an example on how to use the descriptor presented in the following paper:
4 // A. Alahi, R. Ortiz, and P. Vandergheynst. FREAK: Fast Retina Keypoint. In IEEE Conference on Computer Vision and Pattern Recognition, 2012.
5 // CVPR 2012 Open Source Award winner
7 // Copyright (C) 2011-2012 Signal processing laboratory 2, EPFL,
8 // Kirell Benzi (kirell.benzi@epfl.ch),
9 // Raphael Ortiz (raphael.ortiz@a3.epfl.ch),
10 // Alexandre Alahi (alexandre.alahi@epfl.ch)
11 // and Pierre Vandergheynst (pierre.vandergheynst@epfl.ch)
13 // Redistribution and use in source and binary forms, with or without modification,
14 // are permitted provided that the following conditions are met:
16 // * Redistribution's of source code must retain the above copyright notice,
17 // this list of conditions and the following disclaimer.
19 // * Redistribution's in binary form must reproduce the above copyright notice,
20 // this list of conditions and the following disclaimer in the documentation
21 // and/or other materials provided with the distribution.
23 // * The name of the copyright holders may not be used to endorse or promote products
24 // derived from this software without specific prior written permission.
26 // This software is provided by the copyright holders and contributors "as is" and
27 // any express or implied warranties, including, but not limited to, the implied
28 // warranties of merchantability and fitness for a particular purpose are disclaimed.
29 // In no event shall the Intel Corporation or contributors be liable for any direct,
30 // indirect, incidental, special, exemplary, or consequential damages
31 // (including, but not limited to, procurement of substitute goods or services;
32 // loss of use, data, or profits; or business interruption) however caused
33 // and on any theory of liability, whether in contract, strict liability,
34 // or tort (including negligence or otherwise) arising in any way out of
35 // the use of this software, even if advised of the possibility of such damage.
41 #include <opencv2/core/core.hpp>
42 #include <opencv2/highgui/highgui.hpp>
43 #include <opencv2/features2d/features2d.hpp>
44 #include <opencv2/nonfree/features2d.hpp>
45 #include <opencv2/legacy/legacy.hpp>
49 static void help( char** argv )
51 std::cout << "\nUsage: " << argv[0] << " [path/to/image1] [path/to/image2] \n"
52 << "This is an example on how to use the keypoint descriptor presented in the following paper: \n"
53 << "A. Alahi, R. Ortiz, and P. Vandergheynst. FREAK: Fast Retina Keypoint. \n"
54 << "In IEEE Conference on Computer Vision and Pattern Recognition, 2012. CVPR 2012 Open Source Award winner \n"
58 int main( int argc, char** argv ) {
59 // check http://opencv.itseez.com/doc/tutorials/features2d/table_of_content_features2d/table_of_content_features2d.html
60 // for OpenCV general detection/matching framework details
68 Mat imgA = imread(argv[1], CV_LOAD_IMAGE_GRAYSCALE );
70 std::cout<< " --(!) Error reading image " << argv[1] << std::endl;
74 Mat imgB = imread(argv[2], CV_LOAD_IMAGE_GRAYSCALE );
76 std::cout << " --(!) Error reading image " << argv[2] << std::endl;
80 std::vector<KeyPoint> keypointsA, keypointsB;
81 Mat descriptorsA, descriptorsB;
82 std::vector<DMatch> matches;
85 // Any openCV detector such as
86 SurfFeatureDetector detector(2000,4);
89 // Our proposed FREAK descriptor
90 // (roation invariance, scale invariance, pattern radius corresponding to SMALLEST_KP_SIZE,
91 // number of octaves, optional vector containing the selected pairs)
92 // FREAK extractor(true, true, 22, 4, std::vector<int>());
96 // The standard Hamming distance can be used such as
97 // BruteForceMatcher<Hamming> matcher;
98 // or the proposed cascade of hamming distance using SSSE3
99 BruteForceMatcher<Hamming> matcher;
102 double t = (double)getTickCount();
103 detector.detect( imgA, keypointsA );
104 detector.detect( imgB, keypointsB );
105 t = ((double)getTickCount() - t)/getTickFrequency();
106 std::cout << "detection time [s]: " << t/1.0 << std::endl;
109 t = (double)getTickCount();
110 extractor.compute( imgA, keypointsA, descriptorsA );
111 extractor.compute( imgB, keypointsB, descriptorsB );
112 t = ((double)getTickCount() - t)/getTickFrequency();
113 std::cout << "extraction time [s]: " << t << std::endl;
116 t = (double)getTickCount();
117 matcher.match(descriptorsA, descriptorsB, matches);
118 t = ((double)getTickCount() - t)/getTickFrequency();
119 std::cout << "matching time [s]: " << t << std::endl;
123 drawMatches(imgA, keypointsA, imgB, keypointsB, matches, imgMatch);
125 namedWindow("matches", CV_WINDOW_KEEPRATIO);
126 imshow("matches", imgMatch);