opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew contents of line
joeverbout 0:ea44dc9ed014 1 /*M///////////////////////////////////////////////////////////////////////////////////////
joeverbout 0:ea44dc9ed014 2 //
joeverbout 0:ea44dc9ed014 3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
joeverbout 0:ea44dc9ed014 4 //
joeverbout 0:ea44dc9ed014 5 // By downloading, copying, installing or using the software you agree to this license.
joeverbout 0:ea44dc9ed014 6 // If you do not agree to this license, do not download, install,
joeverbout 0:ea44dc9ed014 7 // copy or use the software.
joeverbout 0:ea44dc9ed014 8 //
joeverbout 0:ea44dc9ed014 9 //
joeverbout 0:ea44dc9ed014 10 // License Agreement
joeverbout 0:ea44dc9ed014 11 // For Open Source Computer Vision Library
joeverbout 0:ea44dc9ed014 12 //
joeverbout 0:ea44dc9ed014 13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
joeverbout 0:ea44dc9ed014 14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
joeverbout 0:ea44dc9ed014 15 // Third party copyrights are property of their respective owners.
joeverbout 0:ea44dc9ed014 16 //
joeverbout 0:ea44dc9ed014 17 // Redistribution and use in source and binary forms, with or without modification,
joeverbout 0:ea44dc9ed014 18 // are permitted provided that the following conditions are met:
joeverbout 0:ea44dc9ed014 19 //
joeverbout 0:ea44dc9ed014 20 // * Redistribution's of source code must retain the above copyright notice,
joeverbout 0:ea44dc9ed014 21 // this list of conditions and the following disclaimer.
joeverbout 0:ea44dc9ed014 22 //
joeverbout 0:ea44dc9ed014 23 // * Redistribution's in binary form must reproduce the above copyright notice,
joeverbout 0:ea44dc9ed014 24 // this list of conditions and the following disclaimer in the documentation
joeverbout 0:ea44dc9ed014 25 // and/or other materials provided with the distribution.
joeverbout 0:ea44dc9ed014 26 //
joeverbout 0:ea44dc9ed014 27 // * The name of the copyright holders may not be used to endorse or promote products
joeverbout 0:ea44dc9ed014 28 // derived from this software without specific prior written permission.
joeverbout 0:ea44dc9ed014 29 //
joeverbout 0:ea44dc9ed014 30 // This software is provided by the copyright holders and contributors "as is" and
joeverbout 0:ea44dc9ed014 31 // any express or implied warranties, including, but not limited to, the implied
joeverbout 0:ea44dc9ed014 32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
joeverbout 0:ea44dc9ed014 33 // In no event shall the Intel Corporation or contributors be liable for any direct,
joeverbout 0:ea44dc9ed014 34 // indirect, incidental, special, exemplary, or consequential damages
joeverbout 0:ea44dc9ed014 35 // (including, but not limited to, procurement of substitute goods or services;
joeverbout 0:ea44dc9ed014 36 // loss of use, data, or profits; or business interruption) however caused
joeverbout 0:ea44dc9ed014 37 // and on any theory of liability, whether in contract, strict liability,
joeverbout 0:ea44dc9ed014 38 // or tort (including negligence or otherwise) arising in any way out of
joeverbout 0:ea44dc9ed014 39 // the use of this software, even if advised of the possibility of such damage.
joeverbout 0:ea44dc9ed014 40 //
joeverbout 0:ea44dc9ed014 41 //M*/
joeverbout 0:ea44dc9ed014 42
joeverbout 0:ea44dc9ed014 43 #ifndef __OPENCV_FEATURES_2D_HPP__
joeverbout 0:ea44dc9ed014 44 #define __OPENCV_FEATURES_2D_HPP__
joeverbout 0:ea44dc9ed014 45
joeverbout 0:ea44dc9ed014 46 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 47 #include "opencv2/flann/miniflann.hpp"
joeverbout 0:ea44dc9ed014 48
joeverbout 0:ea44dc9ed014 49 /**
joeverbout 0:ea44dc9ed014 50 @defgroup features2d 2D Features Framework
joeverbout 0:ea44dc9ed014 51 @{
joeverbout 0:ea44dc9ed014 52 @defgroup features2d_main Feature Detection and Description
joeverbout 0:ea44dc9ed014 53 @defgroup features2d_match Descriptor Matchers
joeverbout 0:ea44dc9ed014 54
joeverbout 0:ea44dc9ed014 55 Matchers of keypoint descriptors in OpenCV have wrappers with a common interface that enables you to
joeverbout 0:ea44dc9ed014 56 easily switch between different algorithms solving the same problem. This section is devoted to
joeverbout 0:ea44dc9ed014 57 matching descriptors that are represented as vectors in a multidimensional space. All objects that
joeverbout 0:ea44dc9ed014 58 implement vector descriptor matchers inherit the DescriptorMatcher interface.
joeverbout 0:ea44dc9ed014 59
joeverbout 0:ea44dc9ed014 60 @note
joeverbout 0:ea44dc9ed014 61 - An example explaining keypoint matching can be found at
joeverbout 0:ea44dc9ed014 62 opencv_source_code/samples/cpp/descriptor_extractor_matcher.cpp
joeverbout 0:ea44dc9ed014 63 - An example on descriptor matching evaluation can be found at
joeverbout 0:ea44dc9ed014 64 opencv_source_code/samples/cpp/detector_descriptor_matcher_evaluation.cpp
joeverbout 0:ea44dc9ed014 65 - An example on one to many image matching can be found at
joeverbout 0:ea44dc9ed014 66 opencv_source_code/samples/cpp/matching_to_many_images.cpp
joeverbout 0:ea44dc9ed014 67
joeverbout 0:ea44dc9ed014 68 @defgroup features2d_draw Drawing Function of Keypoints and Matches
joeverbout 0:ea44dc9ed014 69 @defgroup features2d_category Object Categorization
joeverbout 0:ea44dc9ed014 70
joeverbout 0:ea44dc9ed014 71 This section describes approaches based on local 2D features and used to categorize objects.
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 @note
joeverbout 0:ea44dc9ed014 74 - A complete Bag-Of-Words sample can be found at
joeverbout 0:ea44dc9ed014 75 opencv_source_code/samples/cpp/bagofwords_classification.cpp
joeverbout 0:ea44dc9ed014 76 - (Python) An example using the features2D framework to perform object categorization can be
joeverbout 0:ea44dc9ed014 77 found at opencv_source_code/samples/python/find_obj.py
joeverbout 0:ea44dc9ed014 78
joeverbout 0:ea44dc9ed014 79 @}
joeverbout 0:ea44dc9ed014 80 */
joeverbout 0:ea44dc9ed014 81
joeverbout 0:ea44dc9ed014 82 namespace cv
joeverbout 0:ea44dc9ed014 83 {
joeverbout 0:ea44dc9ed014 84
joeverbout 0:ea44dc9ed014 85 //! @addtogroup features2d
joeverbout 0:ea44dc9ed014 86 //! @{
joeverbout 0:ea44dc9ed014 87
joeverbout 0:ea44dc9ed014 88 // //! writes vector of keypoints to the file storage
joeverbout 0:ea44dc9ed014 89 // CV_EXPORTS void write(FileStorage& fs, const String& name, const std::vector<KeyPoint>& keypoints);
joeverbout 0:ea44dc9ed014 90 // //! reads vector of keypoints from the specified file storage node
joeverbout 0:ea44dc9ed014 91 // CV_EXPORTS void read(const FileNode& node, CV_OUT std::vector<KeyPoint>& keypoints);
joeverbout 0:ea44dc9ed014 92
joeverbout 0:ea44dc9ed014 93 /** @brief A class filters a vector of keypoints.
joeverbout 0:ea44dc9ed014 94
joeverbout 0:ea44dc9ed014 95 Because now it is difficult to provide a convenient interface for all usage scenarios of the
joeverbout 0:ea44dc9ed014 96 keypoints filter class, it has only several needed by now static methods.
joeverbout 0:ea44dc9ed014 97 */
joeverbout 0:ea44dc9ed014 98 class CV_EXPORTS KeyPointsFilter
joeverbout 0:ea44dc9ed014 99 {
joeverbout 0:ea44dc9ed014 100 public:
joeverbout 0:ea44dc9ed014 101 KeyPointsFilter(){}
joeverbout 0:ea44dc9ed014 102
joeverbout 0:ea44dc9ed014 103 /*
joeverbout 0:ea44dc9ed014 104 * Remove keypoints within borderPixels of an image edge.
joeverbout 0:ea44dc9ed014 105 */
joeverbout 0:ea44dc9ed014 106 static void runByImageBorder( std::vector<KeyPoint>& keypoints, Size imageSize, int borderSize );
joeverbout 0:ea44dc9ed014 107 /*
joeverbout 0:ea44dc9ed014 108 * Remove keypoints of sizes out of range.
joeverbout 0:ea44dc9ed014 109 */
joeverbout 0:ea44dc9ed014 110 static void runByKeypointSize( std::vector<KeyPoint>& keypoints, float minSize,
joeverbout 0:ea44dc9ed014 111 float maxSize=FLT_MAX );
joeverbout 0:ea44dc9ed014 112 /*
joeverbout 0:ea44dc9ed014 113 * Remove keypoints from some image by mask for pixels of this image.
joeverbout 0:ea44dc9ed014 114 */
joeverbout 0:ea44dc9ed014 115 static void runByPixelsMask( std::vector<KeyPoint>& keypoints, const Mat& mask );
joeverbout 0:ea44dc9ed014 116 /*
joeverbout 0:ea44dc9ed014 117 * Remove duplicated keypoints.
joeverbout 0:ea44dc9ed014 118 */
joeverbout 0:ea44dc9ed014 119 static void removeDuplicated( std::vector<KeyPoint>& keypoints );
joeverbout 0:ea44dc9ed014 120
joeverbout 0:ea44dc9ed014 121 /*
joeverbout 0:ea44dc9ed014 122 * Retain the specified number of the best keypoints (according to the response)
joeverbout 0:ea44dc9ed014 123 */
joeverbout 0:ea44dc9ed014 124 static void retainBest( std::vector<KeyPoint>& keypoints, int npoints );
joeverbout 0:ea44dc9ed014 125 };
joeverbout 0:ea44dc9ed014 126
joeverbout 0:ea44dc9ed014 127
joeverbout 0:ea44dc9ed014 128 /************************************ Base Classes ************************************/
joeverbout 0:ea44dc9ed014 129
joeverbout 0:ea44dc9ed014 130 /** @brief Abstract base class for 2D image feature detectors and descriptor extractors
joeverbout 0:ea44dc9ed014 131 */
joeverbout 0:ea44dc9ed014 132 class CV_EXPORTS_W Feature2D : public virtual Algorithm
joeverbout 0:ea44dc9ed014 133 {
joeverbout 0:ea44dc9ed014 134 public:
joeverbout 0:ea44dc9ed014 135 virtual ~Feature2D();
joeverbout 0:ea44dc9ed014 136
joeverbout 0:ea44dc9ed014 137 /** @brief Detects keypoints in an image (first variant) or image set (second variant).
joeverbout 0:ea44dc9ed014 138
joeverbout 0:ea44dc9ed014 139 @param image Image.
joeverbout 0:ea44dc9ed014 140 @param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set
joeverbout 0:ea44dc9ed014 141 of keypoints detected in images[i] .
joeverbout 0:ea44dc9ed014 142 @param mask Mask specifying where to look for keypoints (optional). It must be a 8-bit integer
joeverbout 0:ea44dc9ed014 143 matrix with non-zero values in the region of interest.
joeverbout 0:ea44dc9ed014 144 */
joeverbout 0:ea44dc9ed014 145 CV_WRAP virtual void detect( InputArray image,
joeverbout 0:ea44dc9ed014 146 CV_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 147 InputArray mask=noArray() );
joeverbout 0:ea44dc9ed014 148
joeverbout 0:ea44dc9ed014 149 /** @overload
joeverbout 0:ea44dc9ed014 150 @param images Image set.
joeverbout 0:ea44dc9ed014 151 @param keypoints The detected keypoints. In the second variant of the method keypoints[i] is a set
joeverbout 0:ea44dc9ed014 152 of keypoints detected in images[i] .
joeverbout 0:ea44dc9ed014 153 @param masks Masks for each input image specifying where to look for keypoints (optional).
joeverbout 0:ea44dc9ed014 154 masks[i] is a mask for images[i].
joeverbout 0:ea44dc9ed014 155 */
joeverbout 0:ea44dc9ed014 156 virtual void detect( InputArrayOfArrays images,
joeverbout 0:ea44dc9ed014 157 std::vector<std::vector<KeyPoint> >& keypoints,
joeverbout 0:ea44dc9ed014 158 InputArrayOfArrays masks=noArray() );
joeverbout 0:ea44dc9ed014 159
joeverbout 0:ea44dc9ed014 160 /** @brief Computes the descriptors for a set of keypoints detected in an image (first variant) or image set
joeverbout 0:ea44dc9ed014 161 (second variant).
joeverbout 0:ea44dc9ed014 162
joeverbout 0:ea44dc9ed014 163 @param image Image.
joeverbout 0:ea44dc9ed014 164 @param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be
joeverbout 0:ea44dc9ed014 165 computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint
joeverbout 0:ea44dc9ed014 166 with several dominant orientations (for each orientation).
joeverbout 0:ea44dc9ed014 167 @param descriptors Computed descriptors. In the second variant of the method descriptors[i] are
joeverbout 0:ea44dc9ed014 168 descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the
joeverbout 0:ea44dc9ed014 169 descriptor for keypoint j-th keypoint.
joeverbout 0:ea44dc9ed014 170 */
joeverbout 0:ea44dc9ed014 171 CV_WRAP virtual void compute( InputArray image,
joeverbout 0:ea44dc9ed014 172 CV_OUT CV_IN_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 173 OutputArray descriptors );
joeverbout 0:ea44dc9ed014 174
joeverbout 0:ea44dc9ed014 175 /** @overload
joeverbout 0:ea44dc9ed014 176
joeverbout 0:ea44dc9ed014 177 @param images Image set.
joeverbout 0:ea44dc9ed014 178 @param keypoints Input collection of keypoints. Keypoints for which a descriptor cannot be
joeverbout 0:ea44dc9ed014 179 computed are removed. Sometimes new keypoints can be added, for example: SIFT duplicates keypoint
joeverbout 0:ea44dc9ed014 180 with several dominant orientations (for each orientation).
joeverbout 0:ea44dc9ed014 181 @param descriptors Computed descriptors. In the second variant of the method descriptors[i] are
joeverbout 0:ea44dc9ed014 182 descriptors computed for a keypoints[i]. Row j is the keypoints (or keypoints[i]) is the
joeverbout 0:ea44dc9ed014 183 descriptor for keypoint j-th keypoint.
joeverbout 0:ea44dc9ed014 184 */
joeverbout 0:ea44dc9ed014 185 virtual void compute( InputArrayOfArrays images,
joeverbout 0:ea44dc9ed014 186 std::vector<std::vector<KeyPoint> >& keypoints,
joeverbout 0:ea44dc9ed014 187 OutputArrayOfArrays descriptors );
joeverbout 0:ea44dc9ed014 188
joeverbout 0:ea44dc9ed014 189 /** Detects keypoints and computes the descriptors */
joeverbout 0:ea44dc9ed014 190 CV_WRAP virtual void detectAndCompute( InputArray image, InputArray mask,
joeverbout 0:ea44dc9ed014 191 CV_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 192 OutputArray descriptors,
joeverbout 0:ea44dc9ed014 193 bool useProvidedKeypoints=false );
joeverbout 0:ea44dc9ed014 194
joeverbout 0:ea44dc9ed014 195 CV_WRAP virtual int descriptorSize() const;
joeverbout 0:ea44dc9ed014 196 CV_WRAP virtual int descriptorType() const;
joeverbout 0:ea44dc9ed014 197 CV_WRAP virtual int defaultNorm() const;
joeverbout 0:ea44dc9ed014 198
joeverbout 0:ea44dc9ed014 199 //! Return true if detector object is empty
joeverbout 0:ea44dc9ed014 200 CV_WRAP virtual bool empty() const;
joeverbout 0:ea44dc9ed014 201 };
joeverbout 0:ea44dc9ed014 202
joeverbout 0:ea44dc9ed014 203 /** Feature detectors in OpenCV have wrappers with a common interface that enables you to easily switch
joeverbout 0:ea44dc9ed014 204 between different algorithms solving the same problem. All objects that implement keypoint detectors
joeverbout 0:ea44dc9ed014 205 inherit the FeatureDetector interface. */
joeverbout 0:ea44dc9ed014 206 typedef Feature2D FeatureDetector;
joeverbout 0:ea44dc9ed014 207
joeverbout 0:ea44dc9ed014 208 /** Extractors of keypoint descriptors in OpenCV have wrappers with a common interface that enables you
joeverbout 0:ea44dc9ed014 209 to easily switch between different algorithms solving the same problem. This section is devoted to
joeverbout 0:ea44dc9ed014 210 computing descriptors represented as vectors in a multidimensional space. All objects that implement
joeverbout 0:ea44dc9ed014 211 the vector descriptor extractors inherit the DescriptorExtractor interface.
joeverbout 0:ea44dc9ed014 212 */
joeverbout 0:ea44dc9ed014 213 typedef Feature2D DescriptorExtractor;
joeverbout 0:ea44dc9ed014 214
joeverbout 0:ea44dc9ed014 215 //! @addtogroup features2d_main
joeverbout 0:ea44dc9ed014 216 //! @{
joeverbout 0:ea44dc9ed014 217
joeverbout 0:ea44dc9ed014 218 /** @brief Class implementing the BRISK keypoint detector and descriptor extractor, described in @cite LCS11 .
joeverbout 0:ea44dc9ed014 219 */
joeverbout 0:ea44dc9ed014 220 class CV_EXPORTS_W BRISK : public Feature2D
joeverbout 0:ea44dc9ed014 221 {
joeverbout 0:ea44dc9ed014 222 public:
joeverbout 0:ea44dc9ed014 223 /** @brief The BRISK constructor
joeverbout 0:ea44dc9ed014 224
joeverbout 0:ea44dc9ed014 225 @param thresh AGAST detection threshold score.
joeverbout 0:ea44dc9ed014 226 @param octaves detection octaves. Use 0 to do single scale.
joeverbout 0:ea44dc9ed014 227 @param patternScale apply this scale to the pattern used for sampling the neighbourhood of a
joeverbout 0:ea44dc9ed014 228 keypoint.
joeverbout 0:ea44dc9ed014 229 */
joeverbout 0:ea44dc9ed014 230 CV_WRAP static Ptr<BRISK> create(int thresh=30, int octaves=3, float patternScale=1.0f);
joeverbout 0:ea44dc9ed014 231
joeverbout 0:ea44dc9ed014 232 /** @brief The BRISK constructor for a custom pattern
joeverbout 0:ea44dc9ed014 233
joeverbout 0:ea44dc9ed014 234 @param radiusList defines the radii (in pixels) where the samples around a keypoint are taken (for
joeverbout 0:ea44dc9ed014 235 keypoint scale 1).
joeverbout 0:ea44dc9ed014 236 @param numberList defines the number of sampling points on the sampling circle. Must be the same
joeverbout 0:ea44dc9ed014 237 size as radiusList..
joeverbout 0:ea44dc9ed014 238 @param dMax threshold for the short pairings used for descriptor formation (in pixels for keypoint
joeverbout 0:ea44dc9ed014 239 scale 1).
joeverbout 0:ea44dc9ed014 240 @param dMin threshold for the long pairings used for orientation determination (in pixels for
joeverbout 0:ea44dc9ed014 241 keypoint scale 1).
joeverbout 0:ea44dc9ed014 242 @param indexChange index remapping of the bits. */
joeverbout 0:ea44dc9ed014 243 CV_WRAP static Ptr<BRISK> create(const std::vector<float> &radiusList, const std::vector<int> &numberList,
joeverbout 0:ea44dc9ed014 244 float dMax=5.85f, float dMin=8.2f, const std::vector<int>& indexChange=std::vector<int>());
joeverbout 0:ea44dc9ed014 245 };
joeverbout 0:ea44dc9ed014 246
joeverbout 0:ea44dc9ed014 247 /** @brief Class implementing the ORB (*oriented BRIEF*) keypoint detector and descriptor extractor
joeverbout 0:ea44dc9ed014 248
joeverbout 0:ea44dc9ed014 249 described in @cite RRKB11 . The algorithm uses FAST in pyramids to detect stable keypoints, selects
joeverbout 0:ea44dc9ed014 250 the strongest features using FAST or Harris response, finds their orientation using first-order
joeverbout 0:ea44dc9ed014 251 moments and computes the descriptors using BRIEF (where the coordinates of random point pairs (or
joeverbout 0:ea44dc9ed014 252 k-tuples) are rotated according to the measured orientation).
joeverbout 0:ea44dc9ed014 253 */
joeverbout 0:ea44dc9ed014 254 class CV_EXPORTS_W ORB : public Feature2D
joeverbout 0:ea44dc9ed014 255 {
joeverbout 0:ea44dc9ed014 256 public:
joeverbout 0:ea44dc9ed014 257 enum { kBytes = 32, HARRIS_SCORE=0, FAST_SCORE=1 };
joeverbout 0:ea44dc9ed014 258
joeverbout 0:ea44dc9ed014 259 /** @brief The ORB constructor
joeverbout 0:ea44dc9ed014 260
joeverbout 0:ea44dc9ed014 261 @param nfeatures The maximum number of features to retain.
joeverbout 0:ea44dc9ed014 262 @param scaleFactor Pyramid decimation ratio, greater than 1. scaleFactor==2 means the classical
joeverbout 0:ea44dc9ed014 263 pyramid, where each next level has 4x less pixels than the previous, but such a big scale factor
joeverbout 0:ea44dc9ed014 264 will degrade feature matching scores dramatically. On the other hand, too close to 1 scale factor
joeverbout 0:ea44dc9ed014 265 will mean that to cover certain scale range you will need more pyramid levels and so the speed
joeverbout 0:ea44dc9ed014 266 will suffer.
joeverbout 0:ea44dc9ed014 267 @param nlevels The number of pyramid levels. The smallest level will have linear size equal to
joeverbout 0:ea44dc9ed014 268 input_image_linear_size/pow(scaleFactor, nlevels).
joeverbout 0:ea44dc9ed014 269 @param edgeThreshold This is size of the border where the features are not detected. It should
joeverbout 0:ea44dc9ed014 270 roughly match the patchSize parameter.
joeverbout 0:ea44dc9ed014 271 @param firstLevel It should be 0 in the current implementation.
joeverbout 0:ea44dc9ed014 272 @param WTA_K The number of points that produce each element of the oriented BRIEF descriptor. The
joeverbout 0:ea44dc9ed014 273 default value 2 means the BRIEF where we take a random point pair and compare their brightnesses,
joeverbout 0:ea44dc9ed014 274 so we get 0/1 response. Other possible values are 3 and 4. For example, 3 means that we take 3
joeverbout 0:ea44dc9ed014 275 random points (of course, those point coordinates are random, but they are generated from the
joeverbout 0:ea44dc9ed014 276 pre-defined seed, so each element of BRIEF descriptor is computed deterministically from the pixel
joeverbout 0:ea44dc9ed014 277 rectangle), find point of maximum brightness and output index of the winner (0, 1 or 2). Such
joeverbout 0:ea44dc9ed014 278 output will occupy 2 bits, and therefore it will need a special variant of Hamming distance,
joeverbout 0:ea44dc9ed014 279 denoted as NORM_HAMMING2 (2 bits per bin). When WTA_K=4, we take 4 random points to compute each
joeverbout 0:ea44dc9ed014 280 bin (that will also occupy 2 bits with possible values 0, 1, 2 or 3).
joeverbout 0:ea44dc9ed014 281 @param scoreType The default HARRIS_SCORE means that Harris algorithm is used to rank features
joeverbout 0:ea44dc9ed014 282 (the score is written to KeyPoint::score and is used to retain best nfeatures features);
joeverbout 0:ea44dc9ed014 283 FAST_SCORE is alternative value of the parameter that produces slightly less stable keypoints,
joeverbout 0:ea44dc9ed014 284 but it is a little faster to compute.
joeverbout 0:ea44dc9ed014 285 @param patchSize size of the patch used by the oriented BRIEF descriptor. Of course, on smaller
joeverbout 0:ea44dc9ed014 286 pyramid layers the perceived image area covered by a feature will be larger.
joeverbout 0:ea44dc9ed014 287 @param fastThreshold
joeverbout 0:ea44dc9ed014 288 */
joeverbout 0:ea44dc9ed014 289 CV_WRAP static Ptr<ORB> create(int nfeatures=500, float scaleFactor=1.2f, int nlevels=8, int edgeThreshold=31,
joeverbout 0:ea44dc9ed014 290 int firstLevel=0, int WTA_K=2, int scoreType=ORB::HARRIS_SCORE, int patchSize=31, int fastThreshold=20);
joeverbout 0:ea44dc9ed014 291
joeverbout 0:ea44dc9ed014 292 CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
joeverbout 0:ea44dc9ed014 293 CV_WRAP virtual int getMaxFeatures() const = 0;
joeverbout 0:ea44dc9ed014 294
joeverbout 0:ea44dc9ed014 295 CV_WRAP virtual void setScaleFactor(double scaleFactor) = 0;
joeverbout 0:ea44dc9ed014 296 CV_WRAP virtual double getScaleFactor() const = 0;
joeverbout 0:ea44dc9ed014 297
joeverbout 0:ea44dc9ed014 298 CV_WRAP virtual void setNLevels(int nlevels) = 0;
joeverbout 0:ea44dc9ed014 299 CV_WRAP virtual int getNLevels() const = 0;
joeverbout 0:ea44dc9ed014 300
joeverbout 0:ea44dc9ed014 301 CV_WRAP virtual void setEdgeThreshold(int edgeThreshold) = 0;
joeverbout 0:ea44dc9ed014 302 CV_WRAP virtual int getEdgeThreshold() const = 0;
joeverbout 0:ea44dc9ed014 303
joeverbout 0:ea44dc9ed014 304 CV_WRAP virtual void setFirstLevel(int firstLevel) = 0;
joeverbout 0:ea44dc9ed014 305 CV_WRAP virtual int getFirstLevel() const = 0;
joeverbout 0:ea44dc9ed014 306
joeverbout 0:ea44dc9ed014 307 CV_WRAP virtual void setWTA_K(int wta_k) = 0;
joeverbout 0:ea44dc9ed014 308 CV_WRAP virtual int getWTA_K() const = 0;
joeverbout 0:ea44dc9ed014 309
joeverbout 0:ea44dc9ed014 310 CV_WRAP virtual void setScoreType(int scoreType) = 0;
joeverbout 0:ea44dc9ed014 311 CV_WRAP virtual int getScoreType() const = 0;
joeverbout 0:ea44dc9ed014 312
joeverbout 0:ea44dc9ed014 313 CV_WRAP virtual void setPatchSize(int patchSize) = 0;
joeverbout 0:ea44dc9ed014 314 CV_WRAP virtual int getPatchSize() const = 0;
joeverbout 0:ea44dc9ed014 315
joeverbout 0:ea44dc9ed014 316 CV_WRAP virtual void setFastThreshold(int fastThreshold) = 0;
joeverbout 0:ea44dc9ed014 317 CV_WRAP virtual int getFastThreshold() const = 0;
joeverbout 0:ea44dc9ed014 318 };
joeverbout 0:ea44dc9ed014 319
joeverbout 0:ea44dc9ed014 320 /** @brief Maximally stable extremal region extractor
joeverbout 0:ea44dc9ed014 321
joeverbout 0:ea44dc9ed014 322 The class encapsulates all the parameters of the %MSER extraction algorithm (see [wiki
joeverbout 0:ea44dc9ed014 323 article](http://en.wikipedia.org/wiki/Maximally_stable_extremal_regions)).
joeverbout 0:ea44dc9ed014 324
joeverbout 0:ea44dc9ed014 325 - there are two different implementation of %MSER: one for grey image, one for color image
joeverbout 0:ea44dc9ed014 326
joeverbout 0:ea44dc9ed014 327 - the grey image algorithm is taken from: @cite nister2008linear ; the paper claims to be faster
joeverbout 0:ea44dc9ed014 328 than union-find method; it actually get 1.5~2m/s on my centrino L7200 1.2GHz laptop.
joeverbout 0:ea44dc9ed014 329
joeverbout 0:ea44dc9ed014 330 - the color image algorithm is taken from: @cite forssen2007maximally ; it should be much slower
joeverbout 0:ea44dc9ed014 331 than grey image method ( 3~4 times ); the chi_table.h file is taken directly from paper's source
joeverbout 0:ea44dc9ed014 332 code which is distributed under GPL.
joeverbout 0:ea44dc9ed014 333
joeverbout 0:ea44dc9ed014 334 - (Python) A complete example showing the use of the %MSER detector can be found at samples/python/mser.py
joeverbout 0:ea44dc9ed014 335 */
joeverbout 0:ea44dc9ed014 336 class CV_EXPORTS_W MSER : public Feature2D
joeverbout 0:ea44dc9ed014 337 {
joeverbout 0:ea44dc9ed014 338 public:
joeverbout 0:ea44dc9ed014 339 /** @brief Full consturctor for %MSER detector
joeverbout 0:ea44dc9ed014 340
joeverbout 0:ea44dc9ed014 341 @param _delta it compares \f$(size_{i}-size_{i-delta})/size_{i-delta}\f$
joeverbout 0:ea44dc9ed014 342 @param _min_area prune the area which smaller than minArea
joeverbout 0:ea44dc9ed014 343 @param _max_area prune the area which bigger than maxArea
joeverbout 0:ea44dc9ed014 344 @param _max_variation prune the area have simliar size to its children
joeverbout 0:ea44dc9ed014 345 @param _min_diversity for color image, trace back to cut off mser with diversity less than min_diversity
joeverbout 0:ea44dc9ed014 346 @param _max_evolution for color image, the evolution steps
joeverbout 0:ea44dc9ed014 347 @param _area_threshold for color image, the area threshold to cause re-initialize
joeverbout 0:ea44dc9ed014 348 @param _min_margin for color image, ignore too small margin
joeverbout 0:ea44dc9ed014 349 @param _edge_blur_size for color image, the aperture size for edge blur
joeverbout 0:ea44dc9ed014 350 */
joeverbout 0:ea44dc9ed014 351 CV_WRAP static Ptr<MSER> create( int _delta=5, int _min_area=60, int _max_area=14400,
joeverbout 0:ea44dc9ed014 352 double _max_variation=0.25, double _min_diversity=.2,
joeverbout 0:ea44dc9ed014 353 int _max_evolution=200, double _area_threshold=1.01,
joeverbout 0:ea44dc9ed014 354 double _min_margin=0.003, int _edge_blur_size=5 );
joeverbout 0:ea44dc9ed014 355
joeverbout 0:ea44dc9ed014 356 /** @brief Detect %MSER regions
joeverbout 0:ea44dc9ed014 357
joeverbout 0:ea44dc9ed014 358 @param image input image (8UC1, 8UC3 or 8UC4)
joeverbout 0:ea44dc9ed014 359 @param msers resulting list of point sets
joeverbout 0:ea44dc9ed014 360 @param bboxes resulting bounding boxes
joeverbout 0:ea44dc9ed014 361 */
joeverbout 0:ea44dc9ed014 362 CV_WRAP virtual void detectRegions( InputArray image,
joeverbout 0:ea44dc9ed014 363 CV_OUT std::vector<std::vector<Point> >& msers,
joeverbout 0:ea44dc9ed014 364 std::vector<Rect>& bboxes ) = 0;
joeverbout 0:ea44dc9ed014 365
joeverbout 0:ea44dc9ed014 366 CV_WRAP virtual void setDelta(int delta) = 0;
joeverbout 0:ea44dc9ed014 367 CV_WRAP virtual int getDelta() const = 0;
joeverbout 0:ea44dc9ed014 368
joeverbout 0:ea44dc9ed014 369 CV_WRAP virtual void setMinArea(int minArea) = 0;
joeverbout 0:ea44dc9ed014 370 CV_WRAP virtual int getMinArea() const = 0;
joeverbout 0:ea44dc9ed014 371
joeverbout 0:ea44dc9ed014 372 CV_WRAP virtual void setMaxArea(int maxArea) = 0;
joeverbout 0:ea44dc9ed014 373 CV_WRAP virtual int getMaxArea() const = 0;
joeverbout 0:ea44dc9ed014 374
joeverbout 0:ea44dc9ed014 375 CV_WRAP virtual void setPass2Only(bool f) = 0;
joeverbout 0:ea44dc9ed014 376 CV_WRAP virtual bool getPass2Only() const = 0;
joeverbout 0:ea44dc9ed014 377 };
joeverbout 0:ea44dc9ed014 378
joeverbout 0:ea44dc9ed014 379 /** @overload */
joeverbout 0:ea44dc9ed014 380 CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 381 int threshold, bool nonmaxSuppression=true );
joeverbout 0:ea44dc9ed014 382
joeverbout 0:ea44dc9ed014 383 /** @brief Detects corners using the FAST algorithm
joeverbout 0:ea44dc9ed014 384
joeverbout 0:ea44dc9ed014 385 @param image grayscale image where keypoints (corners) are detected.
joeverbout 0:ea44dc9ed014 386 @param keypoints keypoints detected on the image.
joeverbout 0:ea44dc9ed014 387 @param threshold threshold on difference between intensity of the central pixel and pixels of a
joeverbout 0:ea44dc9ed014 388 circle around this pixel.
joeverbout 0:ea44dc9ed014 389 @param nonmaxSuppression if true, non-maximum suppression is applied to detected corners
joeverbout 0:ea44dc9ed014 390 (keypoints).
joeverbout 0:ea44dc9ed014 391 @param type one of the three neighborhoods as defined in the paper:
joeverbout 0:ea44dc9ed014 392 FastFeatureDetector::TYPE_9_16, FastFeatureDetector::TYPE_7_12,
joeverbout 0:ea44dc9ed014 393 FastFeatureDetector::TYPE_5_8
joeverbout 0:ea44dc9ed014 394
joeverbout 0:ea44dc9ed014 395 Detects corners using the FAST algorithm by @cite Rosten06 .
joeverbout 0:ea44dc9ed014 396
joeverbout 0:ea44dc9ed014 397 @note In Python API, types are given as cv2.FAST_FEATURE_DETECTOR_TYPE_5_8,
joeverbout 0:ea44dc9ed014 398 cv2.FAST_FEATURE_DETECTOR_TYPE_7_12 and cv2.FAST_FEATURE_DETECTOR_TYPE_9_16. For corner
joeverbout 0:ea44dc9ed014 399 detection, use cv2.FAST.detect() method.
joeverbout 0:ea44dc9ed014 400 */
joeverbout 0:ea44dc9ed014 401 CV_EXPORTS void FAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 402 int threshold, bool nonmaxSuppression, int type );
joeverbout 0:ea44dc9ed014 403
joeverbout 0:ea44dc9ed014 404 //! @} features2d_main
joeverbout 0:ea44dc9ed014 405
joeverbout 0:ea44dc9ed014 406 //! @addtogroup features2d_main
joeverbout 0:ea44dc9ed014 407 //! @{
joeverbout 0:ea44dc9ed014 408
joeverbout 0:ea44dc9ed014 409 /** @brief Wrapping class for feature detection using the FAST method. :
joeverbout 0:ea44dc9ed014 410 */
joeverbout 0:ea44dc9ed014 411 class CV_EXPORTS_W FastFeatureDetector : public Feature2D
joeverbout 0:ea44dc9ed014 412 {
joeverbout 0:ea44dc9ed014 413 public:
joeverbout 0:ea44dc9ed014 414 enum
joeverbout 0:ea44dc9ed014 415 {
joeverbout 0:ea44dc9ed014 416 TYPE_5_8 = 0, TYPE_7_12 = 1, TYPE_9_16 = 2,
joeverbout 0:ea44dc9ed014 417 THRESHOLD = 10000, NONMAX_SUPPRESSION=10001, FAST_N=10002,
joeverbout 0:ea44dc9ed014 418 };
joeverbout 0:ea44dc9ed014 419
joeverbout 0:ea44dc9ed014 420 CV_WRAP static Ptr<FastFeatureDetector> create( int threshold=10,
joeverbout 0:ea44dc9ed014 421 bool nonmaxSuppression=true,
joeverbout 0:ea44dc9ed014 422 int type=FastFeatureDetector::TYPE_9_16 );
joeverbout 0:ea44dc9ed014 423
joeverbout 0:ea44dc9ed014 424 CV_WRAP virtual void setThreshold(int threshold) = 0;
joeverbout 0:ea44dc9ed014 425 CV_WRAP virtual int getThreshold() const = 0;
joeverbout 0:ea44dc9ed014 426
joeverbout 0:ea44dc9ed014 427 CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
joeverbout 0:ea44dc9ed014 428 CV_WRAP virtual bool getNonmaxSuppression() const = 0;
joeverbout 0:ea44dc9ed014 429
joeverbout 0:ea44dc9ed014 430 CV_WRAP virtual void setType(int type) = 0;
joeverbout 0:ea44dc9ed014 431 CV_WRAP virtual int getType() const = 0;
joeverbout 0:ea44dc9ed014 432 };
joeverbout 0:ea44dc9ed014 433
joeverbout 0:ea44dc9ed014 434 /** @overload */
joeverbout 0:ea44dc9ed014 435 CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 436 int threshold, bool nonmaxSuppression=true );
joeverbout 0:ea44dc9ed014 437
joeverbout 0:ea44dc9ed014 438 /** @brief Detects corners using the AGAST algorithm
joeverbout 0:ea44dc9ed014 439
joeverbout 0:ea44dc9ed014 440 @param image grayscale image where keypoints (corners) are detected.
joeverbout 0:ea44dc9ed014 441 @param keypoints keypoints detected on the image.
joeverbout 0:ea44dc9ed014 442 @param threshold threshold on difference between intensity of the central pixel and pixels of a
joeverbout 0:ea44dc9ed014 443 circle around this pixel.
joeverbout 0:ea44dc9ed014 444 @param nonmaxSuppression if true, non-maximum suppression is applied to detected corners
joeverbout 0:ea44dc9ed014 445 (keypoints).
joeverbout 0:ea44dc9ed014 446 @param type one of the four neighborhoods as defined in the paper:
joeverbout 0:ea44dc9ed014 447 AgastFeatureDetector::AGAST_5_8, AgastFeatureDetector::AGAST_7_12d,
joeverbout 0:ea44dc9ed014 448 AgastFeatureDetector::AGAST_7_12s, AgastFeatureDetector::OAST_9_16
joeverbout 0:ea44dc9ed014 449
joeverbout 0:ea44dc9ed014 450 For non-Intel platforms, there is a tree optimised variant of AGAST with same numerical results.
joeverbout 0:ea44dc9ed014 451 The 32-bit binary tree tables were generated automatically from original code using perl script.
joeverbout 0:ea44dc9ed014 452 The perl script and examples of tree generation are placed in features2d/doc folder.
joeverbout 0:ea44dc9ed014 453 Detects corners using the AGAST algorithm by @cite mair2010_agast .
joeverbout 0:ea44dc9ed014 454
joeverbout 0:ea44dc9ed014 455 */
joeverbout 0:ea44dc9ed014 456 CV_EXPORTS void AGAST( InputArray image, CV_OUT std::vector<KeyPoint>& keypoints,
joeverbout 0:ea44dc9ed014 457 int threshold, bool nonmaxSuppression, int type );
joeverbout 0:ea44dc9ed014 458 //! @} features2d_main
joeverbout 0:ea44dc9ed014 459
joeverbout 0:ea44dc9ed014 460 //! @addtogroup features2d_main
joeverbout 0:ea44dc9ed014 461 //! @{
joeverbout 0:ea44dc9ed014 462
joeverbout 0:ea44dc9ed014 463 /** @brief Wrapping class for feature detection using the AGAST method. :
joeverbout 0:ea44dc9ed014 464 */
joeverbout 0:ea44dc9ed014 465 class CV_EXPORTS_W AgastFeatureDetector : public Feature2D
joeverbout 0:ea44dc9ed014 466 {
joeverbout 0:ea44dc9ed014 467 public:
joeverbout 0:ea44dc9ed014 468 enum
joeverbout 0:ea44dc9ed014 469 {
joeverbout 0:ea44dc9ed014 470 AGAST_5_8 = 0, AGAST_7_12d = 1, AGAST_7_12s = 2, OAST_9_16 = 3,
joeverbout 0:ea44dc9ed014 471 THRESHOLD = 10000, NONMAX_SUPPRESSION = 10001,
joeverbout 0:ea44dc9ed014 472 };
joeverbout 0:ea44dc9ed014 473
joeverbout 0:ea44dc9ed014 474 CV_WRAP static Ptr<AgastFeatureDetector> create( int threshold=10,
joeverbout 0:ea44dc9ed014 475 bool nonmaxSuppression=true,
joeverbout 0:ea44dc9ed014 476 int type=AgastFeatureDetector::OAST_9_16 );
joeverbout 0:ea44dc9ed014 477
joeverbout 0:ea44dc9ed014 478 CV_WRAP virtual void setThreshold(int threshold) = 0;
joeverbout 0:ea44dc9ed014 479 CV_WRAP virtual int getThreshold() const = 0;
joeverbout 0:ea44dc9ed014 480
joeverbout 0:ea44dc9ed014 481 CV_WRAP virtual void setNonmaxSuppression(bool f) = 0;
joeverbout 0:ea44dc9ed014 482 CV_WRAP virtual bool getNonmaxSuppression() const = 0;
joeverbout 0:ea44dc9ed014 483
joeverbout 0:ea44dc9ed014 484 CV_WRAP virtual void setType(int type) = 0;
joeverbout 0:ea44dc9ed014 485 CV_WRAP virtual int getType() const = 0;
joeverbout 0:ea44dc9ed014 486 };
joeverbout 0:ea44dc9ed014 487
joeverbout 0:ea44dc9ed014 488 /** @brief Wrapping class for feature detection using the goodFeaturesToTrack function. :
joeverbout 0:ea44dc9ed014 489 */
joeverbout 0:ea44dc9ed014 490 class CV_EXPORTS_W GFTTDetector : public Feature2D
joeverbout 0:ea44dc9ed014 491 {
joeverbout 0:ea44dc9ed014 492 public:
joeverbout 0:ea44dc9ed014 493 CV_WRAP static Ptr<GFTTDetector> create( int maxCorners=1000, double qualityLevel=0.01, double minDistance=1,
joeverbout 0:ea44dc9ed014 494 int blockSize=3, bool useHarrisDetector=false, double k=0.04 );
joeverbout 0:ea44dc9ed014 495 CV_WRAP virtual void setMaxFeatures(int maxFeatures) = 0;
joeverbout 0:ea44dc9ed014 496 CV_WRAP virtual int getMaxFeatures() const = 0;
joeverbout 0:ea44dc9ed014 497
joeverbout 0:ea44dc9ed014 498 CV_WRAP virtual void setQualityLevel(double qlevel) = 0;
joeverbout 0:ea44dc9ed014 499 CV_WRAP virtual double getQualityLevel() const = 0;
joeverbout 0:ea44dc9ed014 500
joeverbout 0:ea44dc9ed014 501 CV_WRAP virtual void setMinDistance(double minDistance) = 0;
joeverbout 0:ea44dc9ed014 502 CV_WRAP virtual double getMinDistance() const = 0;
joeverbout 0:ea44dc9ed014 503
joeverbout 0:ea44dc9ed014 504 CV_WRAP virtual void setBlockSize(int blockSize) = 0;
joeverbout 0:ea44dc9ed014 505 CV_WRAP virtual int getBlockSize() const = 0;
joeverbout 0:ea44dc9ed014 506
joeverbout 0:ea44dc9ed014 507 CV_WRAP virtual void setHarrisDetector(bool val) = 0;
joeverbout 0:ea44dc9ed014 508 CV_WRAP virtual bool getHarrisDetector() const = 0;
joeverbout 0:ea44dc9ed014 509
joeverbout 0:ea44dc9ed014 510 CV_WRAP virtual void setK(double k) = 0;
joeverbout 0:ea44dc9ed014 511 CV_WRAP virtual double getK() const = 0;
joeverbout 0:ea44dc9ed014 512 };
joeverbout 0:ea44dc9ed014 513
joeverbout 0:ea44dc9ed014 514 /** @brief Class for extracting blobs from an image. :
joeverbout 0:ea44dc9ed014 515
joeverbout 0:ea44dc9ed014 516 The class implements a simple algorithm for extracting blobs from an image:
joeverbout 0:ea44dc9ed014 517
joeverbout 0:ea44dc9ed014 518 1. Convert the source image to binary images by applying thresholding with several thresholds from
joeverbout 0:ea44dc9ed014 519 minThreshold (inclusive) to maxThreshold (exclusive) with distance thresholdStep between
joeverbout 0:ea44dc9ed014 520 neighboring thresholds.
joeverbout 0:ea44dc9ed014 521 2. Extract connected components from every binary image by findContours and calculate their
joeverbout 0:ea44dc9ed014 522 centers.
joeverbout 0:ea44dc9ed014 523 3. Group centers from several binary images by their coordinates. Close centers form one group that
joeverbout 0:ea44dc9ed014 524 corresponds to one blob, which is controlled by the minDistBetweenBlobs parameter.
joeverbout 0:ea44dc9ed014 525 4. From the groups, estimate final centers of blobs and their radiuses and return as locations and
joeverbout 0:ea44dc9ed014 526 sizes of keypoints.
joeverbout 0:ea44dc9ed014 527
joeverbout 0:ea44dc9ed014 528 This class performs several filtrations of returned blobs. You should set filterBy\* to true/false
joeverbout 0:ea44dc9ed014 529 to turn on/off corresponding filtration. Available filtrations:
joeverbout 0:ea44dc9ed014 530
joeverbout 0:ea44dc9ed014 531 - **By color**. This filter compares the intensity of a binary image at the center of a blob to
joeverbout 0:ea44dc9ed014 532 blobColor. If they differ, the blob is filtered out. Use blobColor = 0 to extract dark blobs
joeverbout 0:ea44dc9ed014 533 and blobColor = 255 to extract light blobs.
joeverbout 0:ea44dc9ed014 534 - **By area**. Extracted blobs have an area between minArea (inclusive) and maxArea (exclusive).
joeverbout 0:ea44dc9ed014 535 - **By circularity**. Extracted blobs have circularity
joeverbout 0:ea44dc9ed014 536 (\f$\frac{4*\pi*Area}{perimeter * perimeter}\f$) between minCircularity (inclusive) and
joeverbout 0:ea44dc9ed014 537 maxCircularity (exclusive).
joeverbout 0:ea44dc9ed014 538 - **By ratio of the minimum inertia to maximum inertia**. Extracted blobs have this ratio
joeverbout 0:ea44dc9ed014 539 between minInertiaRatio (inclusive) and maxInertiaRatio (exclusive).
joeverbout 0:ea44dc9ed014 540 - **By convexity**. Extracted blobs have convexity (area / area of blob convex hull) between
joeverbout 0:ea44dc9ed014 541 minConvexity (inclusive) and maxConvexity (exclusive).
joeverbout 0:ea44dc9ed014 542
joeverbout 0:ea44dc9ed014 543 Default values of parameters are tuned to extract dark circular blobs.
joeverbout 0:ea44dc9ed014 544 */
joeverbout 0:ea44dc9ed014 545 class CV_EXPORTS_W SimpleBlobDetector : public Feature2D
joeverbout 0:ea44dc9ed014 546 {
joeverbout 0:ea44dc9ed014 547 public:
joeverbout 0:ea44dc9ed014 548 struct CV_EXPORTS_W_SIMPLE Params
joeverbout 0:ea44dc9ed014 549 {
joeverbout 0:ea44dc9ed014 550 CV_WRAP Params();
joeverbout 0:ea44dc9ed014 551 CV_PROP_RW float thresholdStep;
joeverbout 0:ea44dc9ed014 552 CV_PROP_RW float minThreshold;
joeverbout 0:ea44dc9ed014 553 CV_PROP_RW float maxThreshold;
joeverbout 0:ea44dc9ed014 554 CV_PROP_RW size_t minRepeatability;
joeverbout 0:ea44dc9ed014 555 CV_PROP_RW float minDistBetweenBlobs;
joeverbout 0:ea44dc9ed014 556
joeverbout 0:ea44dc9ed014 557 CV_PROP_RW bool filterByColor;
joeverbout 0:ea44dc9ed014 558 CV_PROP_RW uchar blobColor;
joeverbout 0:ea44dc9ed014 559
joeverbout 0:ea44dc9ed014 560 CV_PROP_RW bool filterByArea;
joeverbout 0:ea44dc9ed014 561 CV_PROP_RW float minArea, maxArea;
joeverbout 0:ea44dc9ed014 562
joeverbout 0:ea44dc9ed014 563 CV_PROP_RW bool filterByCircularity;
joeverbout 0:ea44dc9ed014 564 CV_PROP_RW float minCircularity, maxCircularity;
joeverbout 0:ea44dc9ed014 565
joeverbout 0:ea44dc9ed014 566 CV_PROP_RW bool filterByInertia;
joeverbout 0:ea44dc9ed014 567 CV_PROP_RW float minInertiaRatio, maxInertiaRatio;
joeverbout 0:ea44dc9ed014 568
joeverbout 0:ea44dc9ed014 569 CV_PROP_RW bool filterByConvexity;
joeverbout 0:ea44dc9ed014 570 CV_PROP_RW float minConvexity, maxConvexity;
joeverbout 0:ea44dc9ed014 571
joeverbout 0:ea44dc9ed014 572 void read( const FileNode& fn );
joeverbout 0:ea44dc9ed014 573 void write( FileStorage& fs ) const;
joeverbout 0:ea44dc9ed014 574 };
joeverbout 0:ea44dc9ed014 575
joeverbout 0:ea44dc9ed014 576 CV_WRAP static Ptr<SimpleBlobDetector>
joeverbout 0:ea44dc9ed014 577 create(const SimpleBlobDetector::Params &parameters = SimpleBlobDetector::Params());
joeverbout 0:ea44dc9ed014 578 };
joeverbout 0:ea44dc9ed014 579
joeverbout 0:ea44dc9ed014 580 //! @} features2d_main
joeverbout 0:ea44dc9ed014 581
joeverbout 0:ea44dc9ed014 582 //! @addtogroup features2d_main
joeverbout 0:ea44dc9ed014 583 //! @{
joeverbout 0:ea44dc9ed014 584
joeverbout 0:ea44dc9ed014 585 /** @brief Class implementing the KAZE keypoint detector and descriptor extractor, described in @cite ABD12 .
joeverbout 0:ea44dc9ed014 586
joeverbout 0:ea44dc9ed014 587 @note AKAZE descriptor can only be used with KAZE or AKAZE keypoints .. [ABD12] KAZE Features. Pablo
joeverbout 0:ea44dc9ed014 588 F. Alcantarilla, Adrien Bartoli and Andrew J. Davison. In European Conference on Computer Vision
joeverbout 0:ea44dc9ed014 589 (ECCV), Fiorenze, Italy, October 2012.
joeverbout 0:ea44dc9ed014 590 */
joeverbout 0:ea44dc9ed014 591 class CV_EXPORTS_W KAZE : public Feature2D
joeverbout 0:ea44dc9ed014 592 {
joeverbout 0:ea44dc9ed014 593 public:
joeverbout 0:ea44dc9ed014 594 enum
joeverbout 0:ea44dc9ed014 595 {
joeverbout 0:ea44dc9ed014 596 DIFF_PM_G1 = 0,
joeverbout 0:ea44dc9ed014 597 DIFF_PM_G2 = 1,
joeverbout 0:ea44dc9ed014 598 DIFF_WEICKERT = 2,
joeverbout 0:ea44dc9ed014 599 DIFF_CHARBONNIER = 3
joeverbout 0:ea44dc9ed014 600 };
joeverbout 0:ea44dc9ed014 601
joeverbout 0:ea44dc9ed014 602 /** @brief The KAZE constructor
joeverbout 0:ea44dc9ed014 603
joeverbout 0:ea44dc9ed014 604 @param extended Set to enable extraction of extended (128-byte) descriptor.
joeverbout 0:ea44dc9ed014 605 @param upright Set to enable use of upright descriptors (non rotation-invariant).
joeverbout 0:ea44dc9ed014 606 @param threshold Detector response threshold to accept point
joeverbout 0:ea44dc9ed014 607 @param nOctaves Maximum octave evolution of the image
joeverbout 0:ea44dc9ed014 608 @param nOctaveLayers Default number of sublevels per scale level
joeverbout 0:ea44dc9ed014 609 @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or
joeverbout 0:ea44dc9ed014 610 DIFF_CHARBONNIER
joeverbout 0:ea44dc9ed014 611 */
joeverbout 0:ea44dc9ed014 612 CV_WRAP static Ptr<KAZE> create(bool extended=false, bool upright=false,
joeverbout 0:ea44dc9ed014 613 float threshold = 0.001f,
joeverbout 0:ea44dc9ed014 614 int nOctaves = 4, int nOctaveLayers = 4,
joeverbout 0:ea44dc9ed014 615 int diffusivity = KAZE::DIFF_PM_G2);
joeverbout 0:ea44dc9ed014 616
joeverbout 0:ea44dc9ed014 617 CV_WRAP virtual void setExtended(bool extended) = 0;
joeverbout 0:ea44dc9ed014 618 CV_WRAP virtual bool getExtended() const = 0;
joeverbout 0:ea44dc9ed014 619
joeverbout 0:ea44dc9ed014 620 CV_WRAP virtual void setUpright(bool upright) = 0;
joeverbout 0:ea44dc9ed014 621 CV_WRAP virtual bool getUpright() const = 0;
joeverbout 0:ea44dc9ed014 622
joeverbout 0:ea44dc9ed014 623 CV_WRAP virtual void setThreshold(double threshold) = 0;
joeverbout 0:ea44dc9ed014 624 CV_WRAP virtual double getThreshold() const = 0;
joeverbout 0:ea44dc9ed014 625
joeverbout 0:ea44dc9ed014 626 CV_WRAP virtual void setNOctaves(int octaves) = 0;
joeverbout 0:ea44dc9ed014 627 CV_WRAP virtual int getNOctaves() const = 0;
joeverbout 0:ea44dc9ed014 628
joeverbout 0:ea44dc9ed014 629 CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
joeverbout 0:ea44dc9ed014 630 CV_WRAP virtual int getNOctaveLayers() const = 0;
joeverbout 0:ea44dc9ed014 631
joeverbout 0:ea44dc9ed014 632 CV_WRAP virtual void setDiffusivity(int diff) = 0;
joeverbout 0:ea44dc9ed014 633 CV_WRAP virtual int getDiffusivity() const = 0;
joeverbout 0:ea44dc9ed014 634 };
joeverbout 0:ea44dc9ed014 635
joeverbout 0:ea44dc9ed014 636 /** @brief Class implementing the AKAZE keypoint detector and descriptor extractor, described in @cite ANB13 . :
joeverbout 0:ea44dc9ed014 637
joeverbout 0:ea44dc9ed014 638 @note AKAZE descriptors can only be used with KAZE or AKAZE keypoints. Try to avoid using *extract*
joeverbout 0:ea44dc9ed014 639 and *detect* instead of *operator()* due to performance reasons. .. [ANB13] Fast Explicit Diffusion
joeverbout 0:ea44dc9ed014 640 for Accelerated Features in Nonlinear Scale Spaces. Pablo F. Alcantarilla, Jesús Nuevo and Adrien
joeverbout 0:ea44dc9ed014 641 Bartoli. In British Machine Vision Conference (BMVC), Bristol, UK, September 2013.
joeverbout 0:ea44dc9ed014 642 */
joeverbout 0:ea44dc9ed014 643 class CV_EXPORTS_W AKAZE : public Feature2D
joeverbout 0:ea44dc9ed014 644 {
joeverbout 0:ea44dc9ed014 645 public:
joeverbout 0:ea44dc9ed014 646 // AKAZE descriptor type
joeverbout 0:ea44dc9ed014 647 enum
joeverbout 0:ea44dc9ed014 648 {
joeverbout 0:ea44dc9ed014 649 DESCRIPTOR_KAZE_UPRIGHT = 2, ///< Upright descriptors, not invariant to rotation
joeverbout 0:ea44dc9ed014 650 DESCRIPTOR_KAZE = 3,
joeverbout 0:ea44dc9ed014 651 DESCRIPTOR_MLDB_UPRIGHT = 4, ///< Upright descriptors, not invariant to rotation
joeverbout 0:ea44dc9ed014 652 DESCRIPTOR_MLDB = 5
joeverbout 0:ea44dc9ed014 653 };
joeverbout 0:ea44dc9ed014 654
joeverbout 0:ea44dc9ed014 655 /** @brief The AKAZE constructor
joeverbout 0:ea44dc9ed014 656
joeverbout 0:ea44dc9ed014 657 @param descriptor_type Type of the extracted descriptor: DESCRIPTOR_KAZE,
joeverbout 0:ea44dc9ed014 658 DESCRIPTOR_KAZE_UPRIGHT, DESCRIPTOR_MLDB or DESCRIPTOR_MLDB_UPRIGHT.
joeverbout 0:ea44dc9ed014 659 @param descriptor_size Size of the descriptor in bits. 0 -\> Full size
joeverbout 0:ea44dc9ed014 660 @param descriptor_channels Number of channels in the descriptor (1, 2, 3)
joeverbout 0:ea44dc9ed014 661 @param threshold Detector response threshold to accept point
joeverbout 0:ea44dc9ed014 662 @param nOctaves Maximum octave evolution of the image
joeverbout 0:ea44dc9ed014 663 @param nOctaveLayers Default number of sublevels per scale level
joeverbout 0:ea44dc9ed014 664 @param diffusivity Diffusivity type. DIFF_PM_G1, DIFF_PM_G2, DIFF_WEICKERT or
joeverbout 0:ea44dc9ed014 665 DIFF_CHARBONNIER
joeverbout 0:ea44dc9ed014 666 */
joeverbout 0:ea44dc9ed014 667 CV_WRAP static Ptr<AKAZE> create(int descriptor_type=AKAZE::DESCRIPTOR_MLDB,
joeverbout 0:ea44dc9ed014 668 int descriptor_size = 0, int descriptor_channels = 3,
joeverbout 0:ea44dc9ed014 669 float threshold = 0.001f, int nOctaves = 4,
joeverbout 0:ea44dc9ed014 670 int nOctaveLayers = 4, int diffusivity = KAZE::DIFF_PM_G2);
joeverbout 0:ea44dc9ed014 671
joeverbout 0:ea44dc9ed014 672 CV_WRAP virtual void setDescriptorType(int dtype) = 0;
joeverbout 0:ea44dc9ed014 673 CV_WRAP virtual int getDescriptorType() const = 0;
joeverbout 0:ea44dc9ed014 674
joeverbout 0:ea44dc9ed014 675 CV_WRAP virtual void setDescriptorSize(int dsize) = 0;
joeverbout 0:ea44dc9ed014 676 CV_WRAP virtual int getDescriptorSize() const = 0;
joeverbout 0:ea44dc9ed014 677
joeverbout 0:ea44dc9ed014 678 CV_WRAP virtual void setDescriptorChannels(int dch) = 0;
joeverbout 0:ea44dc9ed014 679 CV_WRAP virtual int getDescriptorChannels() const = 0;
joeverbout 0:ea44dc9ed014 680
joeverbout 0:ea44dc9ed014 681 CV_WRAP virtual void setThreshold(double threshold) = 0;
joeverbout 0:ea44dc9ed014 682 CV_WRAP virtual double getThreshold() const = 0;
joeverbout 0:ea44dc9ed014 683
joeverbout 0:ea44dc9ed014 684 CV_WRAP virtual void setNOctaves(int octaves) = 0;
joeverbout 0:ea44dc9ed014 685 CV_WRAP virtual int getNOctaves() const = 0;
joeverbout 0:ea44dc9ed014 686
joeverbout 0:ea44dc9ed014 687 CV_WRAP virtual void setNOctaveLayers(int octaveLayers) = 0;
joeverbout 0:ea44dc9ed014 688 CV_WRAP virtual int getNOctaveLayers() const = 0;
joeverbout 0:ea44dc9ed014 689
joeverbout 0:ea44dc9ed014 690 CV_WRAP virtual void setDiffusivity(int diff) = 0;
joeverbout 0:ea44dc9ed014 691 CV_WRAP virtual int getDiffusivity() const = 0;
joeverbout 0:ea44dc9ed014 692 };
joeverbout 0:ea44dc9ed014 693
joeverbout 0:ea44dc9ed014 694 //! @} features2d_main
joeverbout 0:ea44dc9ed014 695
joeverbout 0:ea44dc9ed014 696 /****************************************************************************************\
joeverbout 0:ea44dc9ed014 697 * Distance *
joeverbout 0:ea44dc9ed014 698 \****************************************************************************************/
joeverbout 0:ea44dc9ed014 699
joeverbout 0:ea44dc9ed014 700 template<typename T>
joeverbout 0:ea44dc9ed014 701 struct CV_EXPORTS Accumulator
joeverbout 0:ea44dc9ed014 702 {
joeverbout 0:ea44dc9ed014 703 typedef T Type;
joeverbout 0:ea44dc9ed014 704 };
joeverbout 0:ea44dc9ed014 705
joeverbout 0:ea44dc9ed014 706 template<> struct Accumulator<unsigned char> { typedef float Type; };
joeverbout 0:ea44dc9ed014 707 template<> struct Accumulator<unsigned short> { typedef float Type; };
joeverbout 0:ea44dc9ed014 708 template<> struct Accumulator<char> { typedef float Type; };
joeverbout 0:ea44dc9ed014 709 template<> struct Accumulator<short> { typedef float Type; };
joeverbout 0:ea44dc9ed014 710
joeverbout 0:ea44dc9ed014 711 /*
joeverbout 0:ea44dc9ed014 712 * Squared Euclidean distance functor
joeverbout 0:ea44dc9ed014 713 */
joeverbout 0:ea44dc9ed014 714 template<class T>
joeverbout 0:ea44dc9ed014 715 struct CV_EXPORTS SL2
joeverbout 0:ea44dc9ed014 716 {
joeverbout 0:ea44dc9ed014 717 enum { normType = NORM_L2SQR };
joeverbout 0:ea44dc9ed014 718 typedef T ValueType;
joeverbout 0:ea44dc9ed014 719 typedef typename Accumulator<T>::Type ResultType;
joeverbout 0:ea44dc9ed014 720
joeverbout 0:ea44dc9ed014 721 ResultType operator()( const T* a, const T* b, int size ) const
joeverbout 0:ea44dc9ed014 722 {
joeverbout 0:ea44dc9ed014 723 return normL2Sqr<ValueType, ResultType>(a, b, size);
joeverbout 0:ea44dc9ed014 724 }
joeverbout 0:ea44dc9ed014 725 };
joeverbout 0:ea44dc9ed014 726
joeverbout 0:ea44dc9ed014 727 /*
joeverbout 0:ea44dc9ed014 728 * Euclidean distance functor
joeverbout 0:ea44dc9ed014 729 */
joeverbout 0:ea44dc9ed014 730 template<class T>
joeverbout 0:ea44dc9ed014 731 struct CV_EXPORTS L2
joeverbout 0:ea44dc9ed014 732 {
joeverbout 0:ea44dc9ed014 733 enum { normType = NORM_L2 };
joeverbout 0:ea44dc9ed014 734 typedef T ValueType;
joeverbout 0:ea44dc9ed014 735 typedef typename Accumulator<T>::Type ResultType;
joeverbout 0:ea44dc9ed014 736
joeverbout 0:ea44dc9ed014 737 ResultType operator()( const T* a, const T* b, int size ) const
joeverbout 0:ea44dc9ed014 738 {
joeverbout 0:ea44dc9ed014 739 return (ResultType)std::sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
joeverbout 0:ea44dc9ed014 740 }
joeverbout 0:ea44dc9ed014 741 };
joeverbout 0:ea44dc9ed014 742
joeverbout 0:ea44dc9ed014 743 /*
joeverbout 0:ea44dc9ed014 744 * Manhattan distance (city block distance) functor
joeverbout 0:ea44dc9ed014 745 */
joeverbout 0:ea44dc9ed014 746 template<class T>
joeverbout 0:ea44dc9ed014 747 struct CV_EXPORTS L1
joeverbout 0:ea44dc9ed014 748 {
joeverbout 0:ea44dc9ed014 749 enum { normType = NORM_L1 };
joeverbout 0:ea44dc9ed014 750 typedef T ValueType;
joeverbout 0:ea44dc9ed014 751 typedef typename Accumulator<T>::Type ResultType;
joeverbout 0:ea44dc9ed014 752
joeverbout 0:ea44dc9ed014 753 ResultType operator()( const T* a, const T* b, int size ) const
joeverbout 0:ea44dc9ed014 754 {
joeverbout 0:ea44dc9ed014 755 return normL1<ValueType, ResultType>(a, b, size);
joeverbout 0:ea44dc9ed014 756 }
joeverbout 0:ea44dc9ed014 757 };
joeverbout 0:ea44dc9ed014 758
joeverbout 0:ea44dc9ed014 759 /****************************************************************************************\
joeverbout 0:ea44dc9ed014 760 * DescriptorMatcher *
joeverbout 0:ea44dc9ed014 761 \****************************************************************************************/
joeverbout 0:ea44dc9ed014 762
joeverbout 0:ea44dc9ed014 763 //! @addtogroup features2d_match
joeverbout 0:ea44dc9ed014 764 //! @{
joeverbout 0:ea44dc9ed014 765
joeverbout 0:ea44dc9ed014 766 /** @brief Abstract base class for matching keypoint descriptors.
joeverbout 0:ea44dc9ed014 767
joeverbout 0:ea44dc9ed014 768 It has two groups of match methods: for matching descriptors of an image with another image or with
joeverbout 0:ea44dc9ed014 769 an image set.
joeverbout 0:ea44dc9ed014 770 */
joeverbout 0:ea44dc9ed014 771 class CV_EXPORTS_W DescriptorMatcher : public Algorithm
joeverbout 0:ea44dc9ed014 772 {
joeverbout 0:ea44dc9ed014 773 public:
joeverbout 0:ea44dc9ed014 774 virtual ~DescriptorMatcher();
joeverbout 0:ea44dc9ed014 775
joeverbout 0:ea44dc9ed014 776 /** @brief Adds descriptors to train a CPU(trainDescCollectionis) or GPU(utrainDescCollectionis) descriptor
joeverbout 0:ea44dc9ed014 777 collection.
joeverbout 0:ea44dc9ed014 778
joeverbout 0:ea44dc9ed014 779 If the collection is not empty, the new descriptors are added to existing train descriptors.
joeverbout 0:ea44dc9ed014 780
joeverbout 0:ea44dc9ed014 781 @param descriptors Descriptors to add. Each descriptors[i] is a set of descriptors from the same
joeverbout 0:ea44dc9ed014 782 train image.
joeverbout 0:ea44dc9ed014 783 */
joeverbout 0:ea44dc9ed014 784 CV_WRAP virtual void add( InputArrayOfArrays descriptors );
joeverbout 0:ea44dc9ed014 785
joeverbout 0:ea44dc9ed014 786 /** @brief Returns a constant link to the train descriptor collection trainDescCollection .
joeverbout 0:ea44dc9ed014 787 */
joeverbout 0:ea44dc9ed014 788 CV_WRAP const std::vector<Mat>& getTrainDescriptors() const;
joeverbout 0:ea44dc9ed014 789
joeverbout 0:ea44dc9ed014 790 /** @brief Clears the train descriptor collections.
joeverbout 0:ea44dc9ed014 791 */
joeverbout 0:ea44dc9ed014 792 CV_WRAP virtual void clear();
joeverbout 0:ea44dc9ed014 793
joeverbout 0:ea44dc9ed014 794 /** @brief Returns true if there are no train descriptors in the both collections.
joeverbout 0:ea44dc9ed014 795 */
joeverbout 0:ea44dc9ed014 796 CV_WRAP virtual bool empty() const;
joeverbout 0:ea44dc9ed014 797
joeverbout 0:ea44dc9ed014 798 /** @brief Returns true if the descriptor matcher supports masking permissible matches.
joeverbout 0:ea44dc9ed014 799 */
joeverbout 0:ea44dc9ed014 800 CV_WRAP virtual bool isMaskSupported() const = 0;
joeverbout 0:ea44dc9ed014 801
joeverbout 0:ea44dc9ed014 802 /** @brief Trains a descriptor matcher
joeverbout 0:ea44dc9ed014 803
joeverbout 0:ea44dc9ed014 804 Trains a descriptor matcher (for example, the flann index). In all methods to match, the method
joeverbout 0:ea44dc9ed014 805 train() is run every time before matching. Some descriptor matchers (for example, BruteForceMatcher)
joeverbout 0:ea44dc9ed014 806 have an empty implementation of this method. Other matchers really train their inner structures (for
joeverbout 0:ea44dc9ed014 807 example, FlannBasedMatcher trains flann::Index ).
joeverbout 0:ea44dc9ed014 808 */
joeverbout 0:ea44dc9ed014 809 CV_WRAP virtual void train();
joeverbout 0:ea44dc9ed014 810
joeverbout 0:ea44dc9ed014 811 /** @brief Finds the best match for each descriptor from a query set.
joeverbout 0:ea44dc9ed014 812
joeverbout 0:ea44dc9ed014 813 @param queryDescriptors Query set of descriptors.
joeverbout 0:ea44dc9ed014 814 @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors
joeverbout 0:ea44dc9ed014 815 collection stored in the class object.
joeverbout 0:ea44dc9ed014 816 @param matches Matches. If a query descriptor is masked out in mask , no match is added for this
joeverbout 0:ea44dc9ed014 817 descriptor. So, matches size may be smaller than the query descriptors count.
joeverbout 0:ea44dc9ed014 818 @param mask Mask specifying permissible matches between an input query and train matrices of
joeverbout 0:ea44dc9ed014 819 descriptors.
joeverbout 0:ea44dc9ed014 820
joeverbout 0:ea44dc9ed014 821 In the first variant of this method, the train descriptors are passed as an input argument. In the
joeverbout 0:ea44dc9ed014 822 second variant of the method, train descriptors collection that was set by DescriptorMatcher::add is
joeverbout 0:ea44dc9ed014 823 used. Optional mask (or masks) can be passed to specify which query and training descriptors can be
joeverbout 0:ea44dc9ed014 824 matched. Namely, queryDescriptors[i] can be matched with trainDescriptors[j] only if
joeverbout 0:ea44dc9ed014 825 mask.at\<uchar\>(i,j) is non-zero.
joeverbout 0:ea44dc9ed014 826 */
joeverbout 0:ea44dc9ed014 827 CV_WRAP void match( InputArray queryDescriptors, InputArray trainDescriptors,
joeverbout 0:ea44dc9ed014 828 CV_OUT std::vector<DMatch>& matches, InputArray mask=noArray() ) const;
joeverbout 0:ea44dc9ed014 829
joeverbout 0:ea44dc9ed014 830 /** @brief Finds the k best matches for each descriptor from a query set.
joeverbout 0:ea44dc9ed014 831
joeverbout 0:ea44dc9ed014 832 @param queryDescriptors Query set of descriptors.
joeverbout 0:ea44dc9ed014 833 @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors
joeverbout 0:ea44dc9ed014 834 collection stored in the class object.
joeverbout 0:ea44dc9ed014 835 @param mask Mask specifying permissible matches between an input query and train matrices of
joeverbout 0:ea44dc9ed014 836 descriptors.
joeverbout 0:ea44dc9ed014 837 @param matches Matches. Each matches[i] is k or less matches for the same query descriptor.
joeverbout 0:ea44dc9ed014 838 @param k Count of best matches found per each query descriptor or less if a query descriptor has
joeverbout 0:ea44dc9ed014 839 less than k possible matches in total.
joeverbout 0:ea44dc9ed014 840 @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is
joeverbout 0:ea44dc9ed014 841 false, the matches vector has the same size as queryDescriptors rows. If compactResult is true,
joeverbout 0:ea44dc9ed014 842 the matches vector does not contain matches for fully masked-out query descriptors.
joeverbout 0:ea44dc9ed014 843
joeverbout 0:ea44dc9ed014 844 These extended variants of DescriptorMatcher::match methods find several best matches for each query
joeverbout 0:ea44dc9ed014 845 descriptor. The matches are returned in the distance increasing order. See DescriptorMatcher::match
joeverbout 0:ea44dc9ed014 846 for the details about query and train descriptors.
joeverbout 0:ea44dc9ed014 847 */
joeverbout 0:ea44dc9ed014 848 CV_WRAP void knnMatch( InputArray queryDescriptors, InputArray trainDescriptors,
joeverbout 0:ea44dc9ed014 849 CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
joeverbout 0:ea44dc9ed014 850 InputArray mask=noArray(), bool compactResult=false ) const;
joeverbout 0:ea44dc9ed014 851
joeverbout 0:ea44dc9ed014 852 /** @brief For each query descriptor, finds the training descriptors not farther than the specified distance.
joeverbout 0:ea44dc9ed014 853
joeverbout 0:ea44dc9ed014 854 @param queryDescriptors Query set of descriptors.
joeverbout 0:ea44dc9ed014 855 @param trainDescriptors Train set of descriptors. This set is not added to the train descriptors
joeverbout 0:ea44dc9ed014 856 collection stored in the class object.
joeverbout 0:ea44dc9ed014 857 @param matches Found matches.
joeverbout 0:ea44dc9ed014 858 @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is
joeverbout 0:ea44dc9ed014 859 false, the matches vector has the same size as queryDescriptors rows. If compactResult is true,
joeverbout 0:ea44dc9ed014 860 the matches vector does not contain matches for fully masked-out query descriptors.
joeverbout 0:ea44dc9ed014 861 @param maxDistance Threshold for the distance between matched descriptors. Distance means here
joeverbout 0:ea44dc9ed014 862 metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured
joeverbout 0:ea44dc9ed014 863 in Pixels)!
joeverbout 0:ea44dc9ed014 864 @param mask Mask specifying permissible matches between an input query and train matrices of
joeverbout 0:ea44dc9ed014 865 descriptors.
joeverbout 0:ea44dc9ed014 866
joeverbout 0:ea44dc9ed014 867 For each query descriptor, the methods find such training descriptors that the distance between the
joeverbout 0:ea44dc9ed014 868 query descriptor and the training descriptor is equal or smaller than maxDistance. Found matches are
joeverbout 0:ea44dc9ed014 869 returned in the distance increasing order.
joeverbout 0:ea44dc9ed014 870 */
joeverbout 0:ea44dc9ed014 871 void radiusMatch( InputArray queryDescriptors, InputArray trainDescriptors,
joeverbout 0:ea44dc9ed014 872 std::vector<std::vector<DMatch> >& matches, float maxDistance,
joeverbout 0:ea44dc9ed014 873 InputArray mask=noArray(), bool compactResult=false ) const;
joeverbout 0:ea44dc9ed014 874
joeverbout 0:ea44dc9ed014 875 /** @overload
joeverbout 0:ea44dc9ed014 876 @param queryDescriptors Query set of descriptors.
joeverbout 0:ea44dc9ed014 877 @param matches Matches. If a query descriptor is masked out in mask , no match is added for this
joeverbout 0:ea44dc9ed014 878 descriptor. So, matches size may be smaller than the query descriptors count.
joeverbout 0:ea44dc9ed014 879 @param masks Set of masks. Each masks[i] specifies permissible matches between the input query
joeverbout 0:ea44dc9ed014 880 descriptors and stored train descriptors from the i-th image trainDescCollection[i].
joeverbout 0:ea44dc9ed014 881 */
joeverbout 0:ea44dc9ed014 882 CV_WRAP void match( InputArray queryDescriptors, CV_OUT std::vector<DMatch>& matches,
joeverbout 0:ea44dc9ed014 883 InputArrayOfArrays masks=noArray() );
joeverbout 0:ea44dc9ed014 884 /** @overload
joeverbout 0:ea44dc9ed014 885 @param queryDescriptors Query set of descriptors.
joeverbout 0:ea44dc9ed014 886 @param matches Matches. Each matches[i] is k or less matches for the same query descriptor.
joeverbout 0:ea44dc9ed014 887 @param k Count of best matches found per each query descriptor or less if a query descriptor has
joeverbout 0:ea44dc9ed014 888 less than k possible matches in total.
joeverbout 0:ea44dc9ed014 889 @param masks Set of masks. Each masks[i] specifies permissible matches between the input query
joeverbout 0:ea44dc9ed014 890 descriptors and stored train descriptors from the i-th image trainDescCollection[i].
joeverbout 0:ea44dc9ed014 891 @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is
joeverbout 0:ea44dc9ed014 892 false, the matches vector has the same size as queryDescriptors rows. If compactResult is true,
joeverbout 0:ea44dc9ed014 893 the matches vector does not contain matches for fully masked-out query descriptors.
joeverbout 0:ea44dc9ed014 894 */
joeverbout 0:ea44dc9ed014 895 CV_WRAP void knnMatch( InputArray queryDescriptors, CV_OUT std::vector<std::vector<DMatch> >& matches, int k,
joeverbout 0:ea44dc9ed014 896 InputArrayOfArrays masks=noArray(), bool compactResult=false );
joeverbout 0:ea44dc9ed014 897 /** @overload
joeverbout 0:ea44dc9ed014 898 @param queryDescriptors Query set of descriptors.
joeverbout 0:ea44dc9ed014 899 @param matches Found matches.
joeverbout 0:ea44dc9ed014 900 @param maxDistance Threshold for the distance between matched descriptors. Distance means here
joeverbout 0:ea44dc9ed014 901 metric distance (e.g. Hamming distance), not the distance between coordinates (which is measured
joeverbout 0:ea44dc9ed014 902 in Pixels)!
joeverbout 0:ea44dc9ed014 903 @param masks Set of masks. Each masks[i] specifies permissible matches between the input query
joeverbout 0:ea44dc9ed014 904 descriptors and stored train descriptors from the i-th image trainDescCollection[i].
joeverbout 0:ea44dc9ed014 905 @param compactResult Parameter used when the mask (or masks) is not empty. If compactResult is
joeverbout 0:ea44dc9ed014 906 false, the matches vector has the same size as queryDescriptors rows. If compactResult is true,
joeverbout 0:ea44dc9ed014 907 the matches vector does not contain matches for fully masked-out query descriptors.
joeverbout 0:ea44dc9ed014 908 */
joeverbout 0:ea44dc9ed014 909 void radiusMatch( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
joeverbout 0:ea44dc9ed014 910 InputArrayOfArrays masks=noArray(), bool compactResult=false );
joeverbout 0:ea44dc9ed014 911
joeverbout 0:ea44dc9ed014 912 // Reads matcher object from a file node
joeverbout 0:ea44dc9ed014 913 virtual void read( const FileNode& );
joeverbout 0:ea44dc9ed014 914 // Writes matcher object to a file storage
joeverbout 0:ea44dc9ed014 915 virtual void write( FileStorage& ) const;
joeverbout 0:ea44dc9ed014 916
joeverbout 0:ea44dc9ed014 917 /** @brief Clones the matcher.
joeverbout 0:ea44dc9ed014 918
joeverbout 0:ea44dc9ed014 919 @param emptyTrainData If emptyTrainData is false, the method creates a deep copy of the object,
joeverbout 0:ea44dc9ed014 920 that is, copies both parameters and train data. If emptyTrainData is true, the method creates an
joeverbout 0:ea44dc9ed014 921 object copy with the current parameters but with empty train data.
joeverbout 0:ea44dc9ed014 922 */
joeverbout 0:ea44dc9ed014 923 virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const = 0;
joeverbout 0:ea44dc9ed014 924
joeverbout 0:ea44dc9ed014 925 /** @brief Creates a descriptor matcher of a given type with the default parameters (using default
joeverbout 0:ea44dc9ed014 926 constructor).
joeverbout 0:ea44dc9ed014 927
joeverbout 0:ea44dc9ed014 928 @param descriptorMatcherType Descriptor matcher type. Now the following matcher types are
joeverbout 0:ea44dc9ed014 929 supported:
joeverbout 0:ea44dc9ed014 930 - `BruteForce` (it uses L2 )
joeverbout 0:ea44dc9ed014 931 - `BruteForce-L1`
joeverbout 0:ea44dc9ed014 932 - `BruteForce-Hamming`
joeverbout 0:ea44dc9ed014 933 - `BruteForce-Hamming(2)`
joeverbout 0:ea44dc9ed014 934 - `FlannBased`
joeverbout 0:ea44dc9ed014 935 */
joeverbout 0:ea44dc9ed014 936 CV_WRAP static Ptr<DescriptorMatcher> create( const String& descriptorMatcherType );
joeverbout 0:ea44dc9ed014 937 protected:
joeverbout 0:ea44dc9ed014 938 /**
joeverbout 0:ea44dc9ed014 939 * Class to work with descriptors from several images as with one merged matrix.
joeverbout 0:ea44dc9ed014 940 * It is used e.g. in FlannBasedMatcher.
joeverbout 0:ea44dc9ed014 941 */
joeverbout 0:ea44dc9ed014 942 class CV_EXPORTS DescriptorCollection
joeverbout 0:ea44dc9ed014 943 {
joeverbout 0:ea44dc9ed014 944 public:
joeverbout 0:ea44dc9ed014 945 DescriptorCollection();
joeverbout 0:ea44dc9ed014 946 DescriptorCollection( const DescriptorCollection& collection );
joeverbout 0:ea44dc9ed014 947 virtual ~DescriptorCollection();
joeverbout 0:ea44dc9ed014 948
joeverbout 0:ea44dc9ed014 949 // Vector of matrices "descriptors" will be merged to one matrix "mergedDescriptors" here.
joeverbout 0:ea44dc9ed014 950 void set( const std::vector<Mat>& descriptors );
joeverbout 0:ea44dc9ed014 951 virtual void clear();
joeverbout 0:ea44dc9ed014 952
joeverbout 0:ea44dc9ed014 953 const Mat& getDescriptors() const;
joeverbout 0:ea44dc9ed014 954 const Mat getDescriptor( int imgIdx, int localDescIdx ) const;
joeverbout 0:ea44dc9ed014 955 const Mat getDescriptor( int globalDescIdx ) const;
joeverbout 0:ea44dc9ed014 956 void getLocalIdx( int globalDescIdx, int& imgIdx, int& localDescIdx ) const;
joeverbout 0:ea44dc9ed014 957
joeverbout 0:ea44dc9ed014 958 int size() const;
joeverbout 0:ea44dc9ed014 959
joeverbout 0:ea44dc9ed014 960 protected:
joeverbout 0:ea44dc9ed014 961 Mat mergedDescriptors;
joeverbout 0:ea44dc9ed014 962 std::vector<int> startIdxs;
joeverbout 0:ea44dc9ed014 963 };
joeverbout 0:ea44dc9ed014 964
joeverbout 0:ea44dc9ed014 965 //! In fact the matching is implemented only by the following two methods. These methods suppose
joeverbout 0:ea44dc9ed014 966 //! that the class object has been trained already. Public match methods call these methods
joeverbout 0:ea44dc9ed014 967 //! after calling train().
joeverbout 0:ea44dc9ed014 968 virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
joeverbout 0:ea44dc9ed014 969 InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
joeverbout 0:ea44dc9ed014 970 virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
joeverbout 0:ea44dc9ed014 971 InputArrayOfArrays masks=noArray(), bool compactResult=false ) = 0;
joeverbout 0:ea44dc9ed014 972
joeverbout 0:ea44dc9ed014 973 static bool isPossibleMatch( InputArray mask, int queryIdx, int trainIdx );
joeverbout 0:ea44dc9ed014 974 static bool isMaskedOut( InputArrayOfArrays masks, int queryIdx );
joeverbout 0:ea44dc9ed014 975
joeverbout 0:ea44dc9ed014 976 static Mat clone_op( Mat m ) { return m.clone(); }
joeverbout 0:ea44dc9ed014 977 void checkMasks( InputArrayOfArrays masks, int queryDescriptorsCount ) const;
joeverbout 0:ea44dc9ed014 978
joeverbout 0:ea44dc9ed014 979 //! Collection of descriptors from train images.
joeverbout 0:ea44dc9ed014 980 std::vector<Mat> trainDescCollection;
joeverbout 0:ea44dc9ed014 981 std::vector<UMat> utrainDescCollection;
joeverbout 0:ea44dc9ed014 982 };
joeverbout 0:ea44dc9ed014 983
joeverbout 0:ea44dc9ed014 984 /** @brief Brute-force descriptor matcher.
joeverbout 0:ea44dc9ed014 985
joeverbout 0:ea44dc9ed014 986 For each descriptor in the first set, this matcher finds the closest descriptor in the second set
joeverbout 0:ea44dc9ed014 987 by trying each one. This descriptor matcher supports masking permissible matches of descriptor
joeverbout 0:ea44dc9ed014 988 sets.
joeverbout 0:ea44dc9ed014 989 */
joeverbout 0:ea44dc9ed014 990 class CV_EXPORTS_W BFMatcher : public DescriptorMatcher
joeverbout 0:ea44dc9ed014 991 {
joeverbout 0:ea44dc9ed014 992 public:
joeverbout 0:ea44dc9ed014 993 /** @brief Brute-force matcher constructor.
joeverbout 0:ea44dc9ed014 994
joeverbout 0:ea44dc9ed014 995 @param normType One of NORM_L1, NORM_L2, NORM_HAMMING, NORM_HAMMING2. L1 and L2 norms are
joeverbout 0:ea44dc9ed014 996 preferable choices for SIFT and SURF descriptors, NORM_HAMMING should be used with ORB, BRISK and
joeverbout 0:ea44dc9ed014 997 BRIEF, NORM_HAMMING2 should be used with ORB when WTA_K==3 or 4 (see ORB::ORB constructor
joeverbout 0:ea44dc9ed014 998 description).
joeverbout 0:ea44dc9ed014 999 @param crossCheck If it is false, this is will be default BFMatcher behaviour when it finds the k
joeverbout 0:ea44dc9ed014 1000 nearest neighbors for each query descriptor. If crossCheck==true, then the knnMatch() method with
joeverbout 0:ea44dc9ed014 1001 k=1 will only return pairs (i,j) such that for i-th query descriptor the j-th descriptor in the
joeverbout 0:ea44dc9ed014 1002 matcher's collection is the nearest and vice versa, i.e. the BFMatcher will only return consistent
joeverbout 0:ea44dc9ed014 1003 pairs. Such technique usually produces best results with minimal number of outliers when there are
joeverbout 0:ea44dc9ed014 1004 enough matches. This is alternative to the ratio test, used by D. Lowe in SIFT paper.
joeverbout 0:ea44dc9ed014 1005 */
joeverbout 0:ea44dc9ed014 1006 CV_WRAP BFMatcher( int normType=NORM_L2, bool crossCheck=false );
joeverbout 0:ea44dc9ed014 1007 virtual ~BFMatcher() {}
joeverbout 0:ea44dc9ed014 1008
joeverbout 0:ea44dc9ed014 1009 virtual bool isMaskSupported() const { return true; }
joeverbout 0:ea44dc9ed014 1010
joeverbout 0:ea44dc9ed014 1011 virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
joeverbout 0:ea44dc9ed014 1012 protected:
joeverbout 0:ea44dc9ed014 1013 virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
joeverbout 0:ea44dc9ed014 1014 InputArrayOfArrays masks=noArray(), bool compactResult=false );
joeverbout 0:ea44dc9ed014 1015 virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
joeverbout 0:ea44dc9ed014 1016 InputArrayOfArrays masks=noArray(), bool compactResult=false );
joeverbout 0:ea44dc9ed014 1017
joeverbout 0:ea44dc9ed014 1018 int normType;
joeverbout 0:ea44dc9ed014 1019 bool crossCheck;
joeverbout 0:ea44dc9ed014 1020 };
joeverbout 0:ea44dc9ed014 1021
joeverbout 0:ea44dc9ed014 1022
joeverbout 0:ea44dc9ed014 1023 /** @brief Flann-based descriptor matcher.
joeverbout 0:ea44dc9ed014 1024
joeverbout 0:ea44dc9ed014 1025 This matcher trains flann::Index_ on a train descriptor collection and calls its nearest search
joeverbout 0:ea44dc9ed014 1026 methods to find the best matches. So, this matcher may be faster when matching a large train
joeverbout 0:ea44dc9ed014 1027 collection than the brute force matcher. FlannBasedMatcher does not support masking permissible
joeverbout 0:ea44dc9ed014 1028 matches of descriptor sets because flann::Index does not support this. :
joeverbout 0:ea44dc9ed014 1029 */
joeverbout 0:ea44dc9ed014 1030 class CV_EXPORTS_W FlannBasedMatcher : public DescriptorMatcher
joeverbout 0:ea44dc9ed014 1031 {
joeverbout 0:ea44dc9ed014 1032 public:
joeverbout 0:ea44dc9ed014 1033 CV_WRAP FlannBasedMatcher( const Ptr<flann::IndexParams>& indexParams=makePtr<flann::KDTreeIndexParams>(),
joeverbout 0:ea44dc9ed014 1034 const Ptr<flann::SearchParams>& searchParams=makePtr<flann::SearchParams>() );
joeverbout 0:ea44dc9ed014 1035
joeverbout 0:ea44dc9ed014 1036 virtual void add( InputArrayOfArrays descriptors );
joeverbout 0:ea44dc9ed014 1037 virtual void clear();
joeverbout 0:ea44dc9ed014 1038
joeverbout 0:ea44dc9ed014 1039 // Reads matcher object from a file node
joeverbout 0:ea44dc9ed014 1040 virtual void read( const FileNode& );
joeverbout 0:ea44dc9ed014 1041 // Writes matcher object to a file storage
joeverbout 0:ea44dc9ed014 1042 virtual void write( FileStorage& ) const;
joeverbout 0:ea44dc9ed014 1043
joeverbout 0:ea44dc9ed014 1044 virtual void train();
joeverbout 0:ea44dc9ed014 1045 virtual bool isMaskSupported() const;
joeverbout 0:ea44dc9ed014 1046
joeverbout 0:ea44dc9ed014 1047 virtual Ptr<DescriptorMatcher> clone( bool emptyTrainData=false ) const;
joeverbout 0:ea44dc9ed014 1048 protected:
joeverbout 0:ea44dc9ed014 1049 static void convertToDMatches( const DescriptorCollection& descriptors,
joeverbout 0:ea44dc9ed014 1050 const Mat& indices, const Mat& distances,
joeverbout 0:ea44dc9ed014 1051 std::vector<std::vector<DMatch> >& matches );
joeverbout 0:ea44dc9ed014 1052
joeverbout 0:ea44dc9ed014 1053 virtual void knnMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, int k,
joeverbout 0:ea44dc9ed014 1054 InputArrayOfArrays masks=noArray(), bool compactResult=false );
joeverbout 0:ea44dc9ed014 1055 virtual void radiusMatchImpl( InputArray queryDescriptors, std::vector<std::vector<DMatch> >& matches, float maxDistance,
joeverbout 0:ea44dc9ed014 1056 InputArrayOfArrays masks=noArray(), bool compactResult=false );
joeverbout 0:ea44dc9ed014 1057
joeverbout 0:ea44dc9ed014 1058 Ptr<flann::IndexParams> indexParams;
joeverbout 0:ea44dc9ed014 1059 Ptr<flann::SearchParams> searchParams;
joeverbout 0:ea44dc9ed014 1060 Ptr<flann::Index> flannIndex;
joeverbout 0:ea44dc9ed014 1061
joeverbout 0:ea44dc9ed014 1062 DescriptorCollection mergedDescriptors;
joeverbout 0:ea44dc9ed014 1063 int addedDescCount;
joeverbout 0:ea44dc9ed014 1064 };
joeverbout 0:ea44dc9ed014 1065
joeverbout 0:ea44dc9ed014 1066 //! @} features2d_match
joeverbout 0:ea44dc9ed014 1067
joeverbout 0:ea44dc9ed014 1068 /****************************************************************************************\
joeverbout 0:ea44dc9ed014 1069 * Drawing functions *
joeverbout 0:ea44dc9ed014 1070 \****************************************************************************************/
joeverbout 0:ea44dc9ed014 1071
joeverbout 0:ea44dc9ed014 1072 //! @addtogroup features2d_draw
joeverbout 0:ea44dc9ed014 1073 //! @{
joeverbout 0:ea44dc9ed014 1074
joeverbout 0:ea44dc9ed014 1075 struct CV_EXPORTS DrawMatchesFlags
joeverbout 0:ea44dc9ed014 1076 {
joeverbout 0:ea44dc9ed014 1077 enum{ DEFAULT = 0, //!< Output image matrix will be created (Mat::create),
joeverbout 0:ea44dc9ed014 1078 //!< i.e. existing memory of output image may be reused.
joeverbout 0:ea44dc9ed014 1079 //!< Two source image, matches and single keypoints will be drawn.
joeverbout 0:ea44dc9ed014 1080 //!< For each keypoint only the center point will be drawn (without
joeverbout 0:ea44dc9ed014 1081 //!< the circle around keypoint with keypoint size and orientation).
joeverbout 0:ea44dc9ed014 1082 DRAW_OVER_OUTIMG = 1, //!< Output image matrix will not be created (Mat::create).
joeverbout 0:ea44dc9ed014 1083 //!< Matches will be drawn on existing content of output image.
joeverbout 0:ea44dc9ed014 1084 NOT_DRAW_SINGLE_POINTS = 2, //!< Single keypoints will not be drawn.
joeverbout 0:ea44dc9ed014 1085 DRAW_RICH_KEYPOINTS = 4 //!< For each keypoint the circle around keypoint with keypoint size and
joeverbout 0:ea44dc9ed014 1086 //!< orientation will be drawn.
joeverbout 0:ea44dc9ed014 1087 };
joeverbout 0:ea44dc9ed014 1088 };
joeverbout 0:ea44dc9ed014 1089
joeverbout 0:ea44dc9ed014 1090 /** @brief Draws keypoints.
joeverbout 0:ea44dc9ed014 1091
joeverbout 0:ea44dc9ed014 1092 @param image Source image.
joeverbout 0:ea44dc9ed014 1093 @param keypoints Keypoints from the source image.
joeverbout 0:ea44dc9ed014 1094 @param outImage Output image. Its content depends on the flags value defining what is drawn in the
joeverbout 0:ea44dc9ed014 1095 output image. See possible flags bit values below.
joeverbout 0:ea44dc9ed014 1096 @param color Color of keypoints.
joeverbout 0:ea44dc9ed014 1097 @param flags Flags setting drawing features. Possible flags bit values are defined by
joeverbout 0:ea44dc9ed014 1098 DrawMatchesFlags. See details above in drawMatches .
joeverbout 0:ea44dc9ed014 1099
joeverbout 0:ea44dc9ed014 1100 @note
joeverbout 0:ea44dc9ed014 1101 For Python API, flags are modified as cv2.DRAW_MATCHES_FLAGS_DEFAULT,
joeverbout 0:ea44dc9ed014 1102 cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS, cv2.DRAW_MATCHES_FLAGS_DRAW_OVER_OUTIMG,
joeverbout 0:ea44dc9ed014 1103 cv2.DRAW_MATCHES_FLAGS_NOT_DRAW_SINGLE_POINTS
joeverbout 0:ea44dc9ed014 1104 */
joeverbout 0:ea44dc9ed014 1105 CV_EXPORTS_W void drawKeypoints( InputArray image, const std::vector<KeyPoint>& keypoints, InputOutputArray outImage,
joeverbout 0:ea44dc9ed014 1106 const Scalar& color=Scalar::all(-1), int flags=DrawMatchesFlags::DEFAULT );
joeverbout 0:ea44dc9ed014 1107
joeverbout 0:ea44dc9ed014 1108 /** @brief Draws the found matches of keypoints from two images.
joeverbout 0:ea44dc9ed014 1109
joeverbout 0:ea44dc9ed014 1110 @param img1 First source image.
joeverbout 0:ea44dc9ed014 1111 @param keypoints1 Keypoints from the first source image.
joeverbout 0:ea44dc9ed014 1112 @param img2 Second source image.
joeverbout 0:ea44dc9ed014 1113 @param keypoints2 Keypoints from the second source image.
joeverbout 0:ea44dc9ed014 1114 @param matches1to2 Matches from the first image to the second one, which means that keypoints1[i]
joeverbout 0:ea44dc9ed014 1115 has a corresponding point in keypoints2[matches[i]] .
joeverbout 0:ea44dc9ed014 1116 @param outImg Output image. Its content depends on the flags value defining what is drawn in the
joeverbout 0:ea44dc9ed014 1117 output image. See possible flags bit values below.
joeverbout 0:ea44dc9ed014 1118 @param matchColor Color of matches (lines and connected keypoints). If matchColor==Scalar::all(-1)
joeverbout 0:ea44dc9ed014 1119 , the color is generated randomly.
joeverbout 0:ea44dc9ed014 1120 @param singlePointColor Color of single keypoints (circles), which means that keypoints do not
joeverbout 0:ea44dc9ed014 1121 have the matches. If singlePointColor==Scalar::all(-1) , the color is generated randomly.
joeverbout 0:ea44dc9ed014 1122 @param matchesMask Mask determining which matches are drawn. If the mask is empty, all matches are
joeverbout 0:ea44dc9ed014 1123 drawn.
joeverbout 0:ea44dc9ed014 1124 @param flags Flags setting drawing features. Possible flags bit values are defined by
joeverbout 0:ea44dc9ed014 1125 DrawMatchesFlags.
joeverbout 0:ea44dc9ed014 1126
joeverbout 0:ea44dc9ed014 1127 This function draws matches of keypoints from two images in the output image. Match is a line
joeverbout 0:ea44dc9ed014 1128 connecting two keypoints (circles). See cv::DrawMatchesFlags.
joeverbout 0:ea44dc9ed014 1129 */
joeverbout 0:ea44dc9ed014 1130 CV_EXPORTS_W void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
joeverbout 0:ea44dc9ed014 1131 InputArray img2, const std::vector<KeyPoint>& keypoints2,
joeverbout 0:ea44dc9ed014 1132 const std::vector<DMatch>& matches1to2, InputOutputArray outImg,
joeverbout 0:ea44dc9ed014 1133 const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
joeverbout 0:ea44dc9ed014 1134 const std::vector<char>& matchesMask=std::vector<char>(), int flags=DrawMatchesFlags::DEFAULT );
joeverbout 0:ea44dc9ed014 1135
joeverbout 0:ea44dc9ed014 1136 /** @overload */
joeverbout 0:ea44dc9ed014 1137 CV_EXPORTS_AS(drawMatchesKnn) void drawMatches( InputArray img1, const std::vector<KeyPoint>& keypoints1,
joeverbout 0:ea44dc9ed014 1138 InputArray img2, const std::vector<KeyPoint>& keypoints2,
joeverbout 0:ea44dc9ed014 1139 const std::vector<std::vector<DMatch> >& matches1to2, InputOutputArray outImg,
joeverbout 0:ea44dc9ed014 1140 const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
joeverbout 0:ea44dc9ed014 1141 const std::vector<std::vector<char> >& matchesMask=std::vector<std::vector<char> >(), int flags=DrawMatchesFlags::DEFAULT );
joeverbout 0:ea44dc9ed014 1142
joeverbout 0:ea44dc9ed014 1143 //! @} features2d_draw
joeverbout 0:ea44dc9ed014 1144
joeverbout 0:ea44dc9ed014 1145 /****************************************************************************************\
joeverbout 0:ea44dc9ed014 1146 * Functions to evaluate the feature detectors and [generic] descriptor extractors *
joeverbout 0:ea44dc9ed014 1147 \****************************************************************************************/
joeverbout 0:ea44dc9ed014 1148
joeverbout 0:ea44dc9ed014 1149 CV_EXPORTS void evaluateFeatureDetector( const Mat& img1, const Mat& img2, const Mat& H1to2,
joeverbout 0:ea44dc9ed014 1150 std::vector<KeyPoint>* keypoints1, std::vector<KeyPoint>* keypoints2,
joeverbout 0:ea44dc9ed014 1151 float& repeatability, int& correspCount,
joeverbout 0:ea44dc9ed014 1152 const Ptr<FeatureDetector>& fdetector=Ptr<FeatureDetector>() );
joeverbout 0:ea44dc9ed014 1153
joeverbout 0:ea44dc9ed014 1154 CV_EXPORTS void computeRecallPrecisionCurve( const std::vector<std::vector<DMatch> >& matches1to2,
joeverbout 0:ea44dc9ed014 1155 const std::vector<std::vector<uchar> >& correctMatches1to2Mask,
joeverbout 0:ea44dc9ed014 1156 std::vector<Point2f>& recallPrecisionCurve );
joeverbout 0:ea44dc9ed014 1157
joeverbout 0:ea44dc9ed014 1158 CV_EXPORTS float getRecall( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
joeverbout 0:ea44dc9ed014 1159 CV_EXPORTS int getNearestPoint( const std::vector<Point2f>& recallPrecisionCurve, float l_precision );
joeverbout 0:ea44dc9ed014 1160
joeverbout 0:ea44dc9ed014 1161 /****************************************************************************************\
joeverbout 0:ea44dc9ed014 1162 * Bag of visual words *
joeverbout 0:ea44dc9ed014 1163 \****************************************************************************************/
joeverbout 0:ea44dc9ed014 1164
joeverbout 0:ea44dc9ed014 1165 //! @addtogroup features2d_category
joeverbout 0:ea44dc9ed014 1166 //! @{
joeverbout 0:ea44dc9ed014 1167
joeverbout 0:ea44dc9ed014 1168 /** @brief Abstract base class for training the *bag of visual words* vocabulary from a set of descriptors.
joeverbout 0:ea44dc9ed014 1169
joeverbout 0:ea44dc9ed014 1170 For details, see, for example, *Visual Categorization with Bags of Keypoints* by Gabriella Csurka,
joeverbout 0:ea44dc9ed014 1171 Christopher R. Dance, Lixin Fan, Jutta Willamowski, Cedric Bray, 2004. :
joeverbout 0:ea44dc9ed014 1172 */
joeverbout 0:ea44dc9ed014 1173 class CV_EXPORTS_W BOWTrainer
joeverbout 0:ea44dc9ed014 1174 {
joeverbout 0:ea44dc9ed014 1175 public:
joeverbout 0:ea44dc9ed014 1176 BOWTrainer();
joeverbout 0:ea44dc9ed014 1177 virtual ~BOWTrainer();
joeverbout 0:ea44dc9ed014 1178
joeverbout 0:ea44dc9ed014 1179 /** @brief Adds descriptors to a training set.
joeverbout 0:ea44dc9ed014 1180
joeverbout 0:ea44dc9ed014 1181 @param descriptors Descriptors to add to a training set. Each row of the descriptors matrix is a
joeverbout 0:ea44dc9ed014 1182 descriptor.
joeverbout 0:ea44dc9ed014 1183
joeverbout 0:ea44dc9ed014 1184 The training set is clustered using clustermethod to construct the vocabulary.
joeverbout 0:ea44dc9ed014 1185 */
joeverbout 0:ea44dc9ed014 1186 CV_WRAP void add( const Mat& descriptors );
joeverbout 0:ea44dc9ed014 1187
joeverbout 0:ea44dc9ed014 1188 /** @brief Returns a training set of descriptors.
joeverbout 0:ea44dc9ed014 1189 */
joeverbout 0:ea44dc9ed014 1190 CV_WRAP const std::vector<Mat>& getDescriptors() const;
joeverbout 0:ea44dc9ed014 1191
joeverbout 0:ea44dc9ed014 1192 /** @brief Returns the count of all descriptors stored in the training set.
joeverbout 0:ea44dc9ed014 1193 */
joeverbout 0:ea44dc9ed014 1194 CV_WRAP int descriptorsCount() const;
joeverbout 0:ea44dc9ed014 1195
joeverbout 0:ea44dc9ed014 1196 CV_WRAP virtual void clear();
joeverbout 0:ea44dc9ed014 1197
joeverbout 0:ea44dc9ed014 1198 /** @overload */
joeverbout 0:ea44dc9ed014 1199 CV_WRAP virtual Mat cluster() const = 0;
joeverbout 0:ea44dc9ed014 1200
joeverbout 0:ea44dc9ed014 1201 /** @brief Clusters train descriptors.
joeverbout 0:ea44dc9ed014 1202
joeverbout 0:ea44dc9ed014 1203 @param descriptors Descriptors to cluster. Each row of the descriptors matrix is a descriptor.
joeverbout 0:ea44dc9ed014 1204 Descriptors are not added to the inner train descriptor set.
joeverbout 0:ea44dc9ed014 1205
joeverbout 0:ea44dc9ed014 1206 The vocabulary consists of cluster centers. So, this method returns the vocabulary. In the first
joeverbout 0:ea44dc9ed014 1207 variant of the method, train descriptors stored in the object are clustered. In the second variant,
joeverbout 0:ea44dc9ed014 1208 input descriptors are clustered.
joeverbout 0:ea44dc9ed014 1209 */
joeverbout 0:ea44dc9ed014 1210 CV_WRAP virtual Mat cluster( const Mat& descriptors ) const = 0;
joeverbout 0:ea44dc9ed014 1211
joeverbout 0:ea44dc9ed014 1212 protected:
joeverbout 0:ea44dc9ed014 1213 std::vector<Mat> descriptors;
joeverbout 0:ea44dc9ed014 1214 int size;
joeverbout 0:ea44dc9ed014 1215 };
joeverbout 0:ea44dc9ed014 1216
joeverbout 0:ea44dc9ed014 1217 /** @brief kmeans -based class to train visual vocabulary using the *bag of visual words* approach. :
joeverbout 0:ea44dc9ed014 1218 */
joeverbout 0:ea44dc9ed014 1219 class CV_EXPORTS_W BOWKMeansTrainer : public BOWTrainer
joeverbout 0:ea44dc9ed014 1220 {
joeverbout 0:ea44dc9ed014 1221 public:
joeverbout 0:ea44dc9ed014 1222 /** @brief The constructor.
joeverbout 0:ea44dc9ed014 1223
joeverbout 0:ea44dc9ed014 1224 @see cv::kmeans
joeverbout 0:ea44dc9ed014 1225 */
joeverbout 0:ea44dc9ed014 1226 CV_WRAP BOWKMeansTrainer( int clusterCount, const TermCriteria& termcrit=TermCriteria(),
joeverbout 0:ea44dc9ed014 1227 int attempts=3, int flags=KMEANS_PP_CENTERS );
joeverbout 0:ea44dc9ed014 1228 virtual ~BOWKMeansTrainer();
joeverbout 0:ea44dc9ed014 1229
joeverbout 0:ea44dc9ed014 1230 // Returns trained vocabulary (i.e. cluster centers).
joeverbout 0:ea44dc9ed014 1231 CV_WRAP virtual Mat cluster() const;
joeverbout 0:ea44dc9ed014 1232 CV_WRAP virtual Mat cluster( const Mat& descriptors ) const;
joeverbout 0:ea44dc9ed014 1233
joeverbout 0:ea44dc9ed014 1234 protected:
joeverbout 0:ea44dc9ed014 1235
joeverbout 0:ea44dc9ed014 1236 int clusterCount;
joeverbout 0:ea44dc9ed014 1237 TermCriteria termcrit;
joeverbout 0:ea44dc9ed014 1238 int attempts;
joeverbout 0:ea44dc9ed014 1239 int flags;
joeverbout 0:ea44dc9ed014 1240 };
joeverbout 0:ea44dc9ed014 1241
joeverbout 0:ea44dc9ed014 1242 /** @brief Class to compute an image descriptor using the *bag of visual words*.
joeverbout 0:ea44dc9ed014 1243
joeverbout 0:ea44dc9ed014 1244 Such a computation consists of the following steps:
joeverbout 0:ea44dc9ed014 1245
joeverbout 0:ea44dc9ed014 1246 1. Compute descriptors for a given image and its keypoints set.
joeverbout 0:ea44dc9ed014 1247 2. Find the nearest visual words from the vocabulary for each keypoint descriptor.
joeverbout 0:ea44dc9ed014 1248 3. Compute the bag-of-words image descriptor as is a normalized histogram of vocabulary words
joeverbout 0:ea44dc9ed014 1249 encountered in the image. The i-th bin of the histogram is a frequency of i-th word of the
joeverbout 0:ea44dc9ed014 1250 vocabulary in the given image.
joeverbout 0:ea44dc9ed014 1251 */
joeverbout 0:ea44dc9ed014 1252 class CV_EXPORTS_W BOWImgDescriptorExtractor
joeverbout 0:ea44dc9ed014 1253 {
joeverbout 0:ea44dc9ed014 1254 public:
joeverbout 0:ea44dc9ed014 1255 /** @brief The constructor.
joeverbout 0:ea44dc9ed014 1256
joeverbout 0:ea44dc9ed014 1257 @param dextractor Descriptor extractor that is used to compute descriptors for an input image and
joeverbout 0:ea44dc9ed014 1258 its keypoints.
joeverbout 0:ea44dc9ed014 1259 @param dmatcher Descriptor matcher that is used to find the nearest word of the trained vocabulary
joeverbout 0:ea44dc9ed014 1260 for each keypoint descriptor of the image.
joeverbout 0:ea44dc9ed014 1261 */
joeverbout 0:ea44dc9ed014 1262 CV_WRAP BOWImgDescriptorExtractor( const Ptr<DescriptorExtractor>& dextractor,
joeverbout 0:ea44dc9ed014 1263 const Ptr<DescriptorMatcher>& dmatcher );
joeverbout 0:ea44dc9ed014 1264 /** @overload */
joeverbout 0:ea44dc9ed014 1265 BOWImgDescriptorExtractor( const Ptr<DescriptorMatcher>& dmatcher );
joeverbout 0:ea44dc9ed014 1266 virtual ~BOWImgDescriptorExtractor();
joeverbout 0:ea44dc9ed014 1267
joeverbout 0:ea44dc9ed014 1268 /** @brief Sets a visual vocabulary.
joeverbout 0:ea44dc9ed014 1269
joeverbout 0:ea44dc9ed014 1270 @param vocabulary Vocabulary (can be trained using the inheritor of BOWTrainer ). Each row of the
joeverbout 0:ea44dc9ed014 1271 vocabulary is a visual word (cluster center).
joeverbout 0:ea44dc9ed014 1272 */
joeverbout 0:ea44dc9ed014 1273 CV_WRAP void setVocabulary( const Mat& vocabulary );
joeverbout 0:ea44dc9ed014 1274
joeverbout 0:ea44dc9ed014 1275 /** @brief Returns the set vocabulary.
joeverbout 0:ea44dc9ed014 1276 */
joeverbout 0:ea44dc9ed014 1277 CV_WRAP const Mat& getVocabulary() const;
joeverbout 0:ea44dc9ed014 1278
joeverbout 0:ea44dc9ed014 1279 /** @brief Computes an image descriptor using the set visual vocabulary.
joeverbout 0:ea44dc9ed014 1280
joeverbout 0:ea44dc9ed014 1281 @param image Image, for which the descriptor is computed.
joeverbout 0:ea44dc9ed014 1282 @param keypoints Keypoints detected in the input image.
joeverbout 0:ea44dc9ed014 1283 @param imgDescriptor Computed output image descriptor.
joeverbout 0:ea44dc9ed014 1284 @param pointIdxsOfClusters Indices of keypoints that belong to the cluster. This means that
joeverbout 0:ea44dc9ed014 1285 pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary)
joeverbout 0:ea44dc9ed014 1286 returned if it is non-zero.
joeverbout 0:ea44dc9ed014 1287 @param descriptors Descriptors of the image keypoints that are returned if they are non-zero.
joeverbout 0:ea44dc9ed014 1288 */
joeverbout 0:ea44dc9ed014 1289 void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray imgDescriptor,
joeverbout 0:ea44dc9ed014 1290 std::vector<std::vector<int> >* pointIdxsOfClusters=0, Mat* descriptors=0 );
joeverbout 0:ea44dc9ed014 1291 /** @overload
joeverbout 0:ea44dc9ed014 1292 @param keypointDescriptors Computed descriptors to match with vocabulary.
joeverbout 0:ea44dc9ed014 1293 @param imgDescriptor Computed output image descriptor.
joeverbout 0:ea44dc9ed014 1294 @param pointIdxsOfClusters Indices of keypoints that belong to the cluster. This means that
joeverbout 0:ea44dc9ed014 1295 pointIdxsOfClusters[i] are keypoint indices that belong to the i -th cluster (word of vocabulary)
joeverbout 0:ea44dc9ed014 1296 returned if it is non-zero.
joeverbout 0:ea44dc9ed014 1297 */
joeverbout 0:ea44dc9ed014 1298 void compute( InputArray keypointDescriptors, OutputArray imgDescriptor,
joeverbout 0:ea44dc9ed014 1299 std::vector<std::vector<int> >* pointIdxsOfClusters=0 );
joeverbout 0:ea44dc9ed014 1300 // compute() is not constant because DescriptorMatcher::match is not constant
joeverbout 0:ea44dc9ed014 1301
joeverbout 0:ea44dc9ed014 1302 CV_WRAP_AS(compute) void compute2( const Mat& image, std::vector<KeyPoint>& keypoints, CV_OUT Mat& imgDescriptor )
joeverbout 0:ea44dc9ed014 1303 { compute(image,keypoints,imgDescriptor); }
joeverbout 0:ea44dc9ed014 1304
joeverbout 0:ea44dc9ed014 1305 /** @brief Returns an image descriptor size if the vocabulary is set. Otherwise, it returns 0.
joeverbout 0:ea44dc9ed014 1306 */
joeverbout 0:ea44dc9ed014 1307 CV_WRAP int descriptorSize() const;
joeverbout 0:ea44dc9ed014 1308
joeverbout 0:ea44dc9ed014 1309 /** @brief Returns an image descriptor type.
joeverbout 0:ea44dc9ed014 1310 */
joeverbout 0:ea44dc9ed014 1311 CV_WRAP int descriptorType() const;
joeverbout 0:ea44dc9ed014 1312
joeverbout 0:ea44dc9ed014 1313 protected:
joeverbout 0:ea44dc9ed014 1314 Mat vocabulary;
joeverbout 0:ea44dc9ed014 1315 Ptr<DescriptorExtractor> dextractor;
joeverbout 0:ea44dc9ed014 1316 Ptr<DescriptorMatcher> dmatcher;
joeverbout 0:ea44dc9ed014 1317 };
joeverbout 0:ea44dc9ed014 1318
joeverbout 0:ea44dc9ed014 1319 //! @} features2d_category
joeverbout 0:ea44dc9ed014 1320
joeverbout 0:ea44dc9ed014 1321 //! @} features2d
joeverbout 0:ea44dc9ed014 1322
joeverbout 0:ea44dc9ed014 1323 } /* namespace cv */
joeverbout 0:ea44dc9ed014 1324
joeverbout 0:ea44dc9ed014 1325 #endif
joeverbout 0:ea44dc9ed014 1326