openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

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