1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 //  By downloading, copying, installing or using the software you agree to this license.
6 //  If you do not agree to this license, do not download, install,
7 //  copy or use the software.
8 //
9 //
10 //                          License Agreement
11 //                For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 //   * Redistribution's of source code must retain the above copyright notice,
21 //     this list of conditions and the following disclaimer.
22 //
23 //   * Redistribution's in binary form must reproduce the above copyright notice,
24 //     this list of conditions and the following disclaimer in the documentation
25 //     and/or other materials provided with the distribution.
26 //
27 //   * The name of the copyright holders may not be used to endorse or promote products
28 //     derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #include "precomp.hpp"
44 
45 namespace cv
46 {
47 
48 using std::vector;
49 
~Feature2D()50 Feature2D::~Feature2D() {}
51 
52 /*
53  * Detect keypoints in an image.
54  * image        The image.
55  * keypoints    The detected keypoints.
56  * mask         Mask specifying where to look for keypoints (optional). Must be a char
57  *              matrix with non-zero values in the region of interest.
58  */
detect(InputArray image,std::vector<KeyPoint> & keypoints,InputArray mask)59 void Feature2D::detect( InputArray image,
60                         std::vector<KeyPoint>& keypoints,
61                         InputArray mask )
62 {
63     if( image.empty() )
64     {
65         keypoints.clear();
66         return;
67     }
68     detectAndCompute(image, mask, keypoints, noArray(), false);
69 }
70 
71 
detect(InputArrayOfArrays _images,std::vector<std::vector<KeyPoint>> & keypoints,InputArrayOfArrays _masks)72 void Feature2D::detect( InputArrayOfArrays _images,
73                         std::vector<std::vector<KeyPoint> >& keypoints,
74                         InputArrayOfArrays _masks )
75 {
76     vector<Mat> images, masks;
77 
78     _images.getMatVector(images);
79     size_t i, nimages = images.size();
80 
81     if( !_masks.empty() )
82     {
83         _masks.getMatVector(masks);
84         CV_Assert(masks.size() == nimages);
85     }
86 
87     keypoints.resize(nimages);
88 
89     for( i = 0; i < nimages; i++ )
90     {
91         detect(images[i], keypoints[i], masks.empty() ? Mat() : masks[i] );
92     }
93 }
94 
95 /*
96  * Compute the descriptors for a set of keypoints in an image.
97  * image        The image.
98  * keypoints    The input keypoints. Keypoints for which a descriptor cannot be computed are removed.
99  * descriptors  Copmputed descriptors. Row i is the descriptor for keypoint i.
100  */
compute(InputArray image,std::vector<KeyPoint> & keypoints,OutputArray descriptors)101 void Feature2D::compute( InputArray image,
102                          std::vector<KeyPoint>& keypoints,
103                          OutputArray descriptors )
104 {
105     if( image.empty() )
106     {
107         descriptors.release();
108         return;
109     }
110     detectAndCompute(image, noArray(), keypoints, descriptors, true);
111 }
112 
compute(InputArrayOfArrays _images,std::vector<std::vector<KeyPoint>> & keypoints,OutputArrayOfArrays _descriptors)113 void Feature2D::compute( InputArrayOfArrays _images,
114                          std::vector<std::vector<KeyPoint> >& keypoints,
115                          OutputArrayOfArrays _descriptors )
116 {
117     if( !_descriptors.needed() )
118         return;
119 
120     vector<Mat> images;
121 
122     _images.getMatVector(images);
123     size_t i, nimages = images.size();
124 
125     CV_Assert( keypoints.size() == nimages );
126     CV_Assert( _descriptors.kind() == _InputArray::STD_VECTOR_MAT );
127 
128     vector<Mat>& descriptors = *(vector<Mat>*)_descriptors.getObj();
129     descriptors.resize(nimages);
130 
131     for( i = 0; i < nimages; i++ )
132     {
133         compute(images[i], keypoints[i], descriptors[i]);
134     }
135 }
136 
137 
138 /* Detects keypoints and computes the descriptors */
detectAndCompute(InputArray,InputArray,std::vector<KeyPoint> &,OutputArray,bool)139 void Feature2D::detectAndCompute( InputArray, InputArray,
140                                   std::vector<KeyPoint>&,
141                                   OutputArray,
142                                   bool )
143 {
144     CV_Error(Error::StsNotImplemented, "");
145 }
146 
descriptorSize() const147 int Feature2D::descriptorSize() const
148 {
149     return 0;
150 }
151 
descriptorType() const152 int Feature2D::descriptorType() const
153 {
154     return CV_32F;
155 }
156 
defaultNorm() const157 int Feature2D::defaultNorm() const
158 {
159     int tp = descriptorType();
160     return tp == CV_8U ? NORM_HAMMING : NORM_L2;
161 }
162 
163 // Return true if detector object is empty
empty() const164 bool Feature2D::empty() const
165 {
166     return true;
167 }
168 
169 }
170