xfeatures2d.hpp 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998
  1. /*
  2. By downloading, copying, installing or using the software you agree to this
  3. license. If you do not agree to this license, do not download, install,
  4. copy or use the software.
  5. License Agreement
  6. For Open Source Computer Vision Library
  7. (3-clause BSD License)
  8. Copyright (C) 2013, OpenCV Foundation, all rights reserved.
  9. Third party copyrights are property of their respective owners.
  10. Redistribution and use in source and binary forms, with or without modification,
  11. are permitted provided that the following conditions are met:
  12. * Redistributions of source code must retain the above copyright notice,
  13. this list of conditions and the following disclaimer.
  14. * Redistributions in binary form must reproduce the above copyright notice,
  15. this list of conditions and the following disclaimer in the documentation
  16. and/or other materials provided with the distribution.
  17. * Neither the names of the copyright holders nor the names of the contributors
  18. may be used to endorse or promote products derived from this software
  19. without specific prior written permission.
  20. This software is provided by the copyright holders and contributors "as is" and
  21. any express or implied warranties, including, but not limited to, the implied
  22. warranties of merchantability and fitness for a particular purpose are
  23. disclaimed. In no event shall copyright holders or contributors be liable for
  24. any direct, indirect, incidental, special, exemplary, or consequential damages
  25. (including, but not limited to, procurement of substitute goods or services;
  26. loss of use, data, or profits; or business interruption) however caused
  27. and on any theory of liability, whether in contract, strict liability,
  28. or tort (including negligence or otherwise) arising in any way out of
  29. the use of this software, even if advised of the possibility of such damage.
  30. */
  31. #ifndef __OPENCV_XFEATURES2D_HPP__
  32. #define __OPENCV_XFEATURES2D_HPP__
  33. #include "opencv2/features2d.hpp"
  34. #include "opencv2/xfeatures2d/nonfree.hpp"
  35. /** @defgroup xfeatures2d Extra 2D Features Framework
  36. @{
  37. @defgroup xfeatures2d_experiment Experimental 2D Features Algorithms
  38. This section describes experimental algorithms for 2d feature detection.
  39. @defgroup xfeatures2d_nonfree Non-free 2D Features Algorithms
  40. This section describes two popular algorithms for 2d feature detection, SIFT and SURF, that are
  41. known to be patented. You need to set the OPENCV_ENABLE_NONFREE option in cmake to use those. Use them at your own risk.
  42. @defgroup xfeatures2d_match Experimental 2D Features Matching Algorithm
  43. This section describes the GMS (Grid-based Motion Statistics) matching strategy.
  44. @}
  45. */
  46. namespace cv
  47. {
  48. namespace xfeatures2d
  49. {
  50. //! @addtogroup xfeatures2d_experiment
  51. //! @{
  52. /** @brief Class implementing the FREAK (*Fast Retina Keypoint*) keypoint descriptor, described in @cite AOV12 .
  53. The algorithm propose a novel keypoint descriptor inspired by the human visual system and more
  54. precisely the retina, coined Fast Retina Key- point (FREAK). A cascade of binary strings is
  55. computed by efficiently comparing image intensities over a retinal sampling pattern. FREAKs are in
  56. general faster to compute with lower memory load and also more robust than SIFT, SURF or BRISK.
  57. They are competitive alternatives to existing keypoints in particular for embedded applications.
  58. @note
  59. - An example on how to use the FREAK descriptor can be found at
  60. opencv_source_code/samples/cpp/freak_demo.cpp
  61. */
  62. class CV_EXPORTS_W FREAK : public Feature2D
  63. {
  64. public:
  65. enum
  66. {
  67. NB_SCALES = 64, NB_PAIRS = 512, NB_ORIENPAIRS = 45
  68. };
  69. /**
  70. @param orientationNormalized Enable orientation normalization.
  71. @param scaleNormalized Enable scale normalization.
  72. @param patternScale Scaling of the description pattern.
  73. @param nOctaves Number of octaves covered by the detected keypoints.
  74. @param selectedPairs (Optional) user defined selected pairs indexes,
  75. */
  76. CV_WRAP static Ptr<FREAK> create(bool orientationNormalized = true,
  77. bool scaleNormalized = true,
  78. float patternScale = 22.0f,
  79. int nOctaves = 4,
  80. const std::vector<int>& selectedPairs = std::vector<int>());
  81. };
  82. /** @brief The class implements the keypoint detector introduced by @cite Agrawal08, synonym of StarDetector. :
  83. */
  84. class CV_EXPORTS_W StarDetector : public Feature2D
  85. {
  86. public:
  87. //! the full constructor
  88. CV_WRAP static Ptr<StarDetector> create(int maxSize=45, int responseThreshold=30,
  89. int lineThresholdProjected=10,
  90. int lineThresholdBinarized=8,
  91. int suppressNonmaxSize=5);
  92. };
  93. /*
  94. * BRIEF Descriptor
  95. */
  96. /** @brief Class for computing BRIEF descriptors described in @cite calon2010 .
  97. @param bytes legth of the descriptor in bytes, valid values are: 16, 32 (default) or 64 .
  98. @param use_orientation sample patterns using keypoints orientation, disabled by default.
  99. */
  100. class CV_EXPORTS_W BriefDescriptorExtractor : public Feature2D
  101. {
  102. public:
  103. CV_WRAP static Ptr<BriefDescriptorExtractor> create( int bytes = 32, bool use_orientation = false );
  104. };
  105. /** @brief Class implementing the locally uniform comparison image descriptor, described in @cite LUCID
  106. An image descriptor that can be computed very fast, while being
  107. about as robust as, for example, SURF or BRIEF.
  108. @note It requires a color image as input.
  109. */
  110. class CV_EXPORTS_W LUCID : public Feature2D
  111. {
  112. public:
  113. /**
  114. * @param lucid_kernel kernel for descriptor construction, where 1=3x3, 2=5x5, 3=7x7 and so forth
  115. * @param blur_kernel kernel for blurring image prior to descriptor construction, where 1=3x3, 2=5x5, 3=7x7 and so forth
  116. */
  117. CV_WRAP static Ptr<LUCID> create(const int lucid_kernel = 1, const int blur_kernel = 2);
  118. };
  119. /*
  120. * LATCH Descriptor
  121. */
  122. /** latch Class for computing the LATCH descriptor.
  123. If you find this code useful, please add a reference to the following paper in your work:
  124. Gil Levi and Tal Hassner, "LATCH: Learned Arrangements of Three Patch Codes", arXiv preprint arXiv:1501.03719, 15 Jan. 2015
  125. LATCH is a binary descriptor based on learned comparisons of triplets of image patches.
  126. * bytes is the size of the descriptor - can be 64, 32, 16, 8, 4, 2 or 1
  127. * rotationInvariance - whether or not the descriptor should compansate for orientation changes.
  128. * half_ssd_size - the size of half of the mini-patches size. For example, if we would like to compare triplets of patches of size 7x7x
  129. then the half_ssd_size should be (7-1)/2 = 3.
  130. * sigma - sigma value for GaussianBlur smoothing of the source image. Source image will be used without smoothing in case sigma value is 0.
  131. Note: the descriptor can be coupled with any keypoint extractor. The only demand is that if you use set rotationInvariance = True then
  132. you will have to use an extractor which estimates the patch orientation (in degrees). Examples for such extractors are ORB and SIFT.
  133. Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures2D/latch_match.cpp
  134. */
  135. class CV_EXPORTS_W LATCH : public Feature2D
  136. {
  137. public:
  138. CV_WRAP static Ptr<LATCH> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3, double sigma = 2.0);
  139. };
  140. /** @brief Class implementing DAISY descriptor, described in @cite Tola10
  141. @param radius radius of the descriptor at the initial scale
  142. @param q_radius amount of radial range division quantity
  143. @param q_theta amount of angular range division quantity
  144. @param q_hist amount of gradient orientations range division quantity
  145. @param norm choose descriptors normalization type, where
  146. DAISY::NRM_NONE will not do any normalization (default),
  147. DAISY::NRM_PARTIAL mean that histograms are normalized independently for L2 norm equal to 1.0,
  148. DAISY::NRM_FULL mean that descriptors are normalized for L2 norm equal to 1.0,
  149. DAISY::NRM_SIFT mean that descriptors are normalized for L2 norm equal to 1.0 but no individual one is bigger than 0.154 as in SIFT
  150. @param H optional 3x3 homography matrix used to warp the grid of daisy but sampling keypoints remains unwarped on image
  151. @param interpolation switch to disable interpolation for speed improvement at minor quality loss
  152. @param use_orientation sample patterns using keypoints orientation, disabled by default.
  153. */
  154. class CV_EXPORTS_W DAISY : public Feature2D
  155. {
  156. public:
  157. enum
  158. {
  159. NRM_NONE = 100, NRM_PARTIAL = 101, NRM_FULL = 102, NRM_SIFT = 103,
  160. };
  161. CV_WRAP static Ptr<DAISY> create( float radius = 15, int q_radius = 3, int q_theta = 8,
  162. int q_hist = 8, int norm = DAISY::NRM_NONE, InputArray H = noArray(),
  163. bool interpolation = true, bool use_orientation = false );
  164. /** @overload
  165. * @param image image to extract descriptors
  166. * @param keypoints of interest within image
  167. * @param descriptors resulted descriptors array
  168. */
  169. virtual void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray descriptors ) CV_OVERRIDE = 0;
  170. virtual void compute( InputArrayOfArrays images,
  171. std::vector<std::vector<KeyPoint> >& keypoints,
  172. OutputArrayOfArrays descriptors ) CV_OVERRIDE;
  173. /** @overload
  174. * @param image image to extract descriptors
  175. * @param roi region of interest within image
  176. * @param descriptors resulted descriptors array for roi image pixels
  177. */
  178. virtual void compute( InputArray image, Rect roi, OutputArray descriptors ) = 0;
  179. /**@overload
  180. * @param image image to extract descriptors
  181. * @param descriptors resulted descriptors array for all image pixels
  182. */
  183. virtual void compute( InputArray image, OutputArray descriptors ) = 0;
  184. /**
  185. * @param y position y on image
  186. * @param x position x on image
  187. * @param orientation orientation on image (0->360)
  188. * @param descriptor supplied array for descriptor storage
  189. */
  190. virtual void GetDescriptor( double y, double x, int orientation, float* descriptor ) const = 0;
  191. /**
  192. * @param y position y on image
  193. * @param x position x on image
  194. * @param orientation orientation on image (0->360)
  195. * @param descriptor supplied array for descriptor storage
  196. * @param H homography matrix for warped grid
  197. */
  198. virtual bool GetDescriptor( double y, double x, int orientation, float* descriptor, double* H ) const = 0;
  199. /**
  200. * @param y position y on image
  201. * @param x position x on image
  202. * @param orientation orientation on image (0->360)
  203. * @param descriptor supplied array for descriptor storage
  204. */
  205. virtual void GetUnnormalizedDescriptor( double y, double x, int orientation, float* descriptor ) const = 0;
  206. /**
  207. * @param y position y on image
  208. * @param x position x on image
  209. * @param orientation orientation on image (0->360)
  210. * @param descriptor supplied array for descriptor storage
  211. * @param H homography matrix for warped grid
  212. */
  213. virtual bool GetUnnormalizedDescriptor( double y, double x, int orientation, float* descriptor , double *H ) const = 0;
  214. };
  215. /** @brief Class implementing the MSD (*Maximal Self-Dissimilarity*) keypoint detector, described in @cite Tombari14.
  216. The algorithm implements a novel interest point detector stemming from the intuition that image patches
  217. which are highly dissimilar over a relatively large extent of their surroundings hold the property of
  218. being repeatable and distinctive. This concept of "contextual self-dissimilarity" reverses the key
  219. paradigm of recent successful techniques such as the Local Self-Similarity descriptor and the Non-Local
  220. Means filter, which build upon the presence of similar - rather than dissimilar - patches. Moreover,
  221. it extends to contextual information the local self-dissimilarity notion embedded in established
  222. detectors of corner-like interest points, thereby achieving enhanced repeatability, distinctiveness and
  223. localization accuracy.
  224. */
  225. class CV_EXPORTS_W MSDDetector : public Feature2D {
  226. public:
  227. CV_WRAP static Ptr<MSDDetector> create(int m_patch_radius = 3, int m_search_area_radius = 5,
  228. int m_nms_radius = 5, int m_nms_scale_radius = 0, float m_th_saliency = 250.0f, int m_kNN = 4,
  229. float m_scale_factor = 1.25f, int m_n_scales = -1, bool m_compute_orientation = false);
  230. };
  231. /** @brief Class implementing VGG (Oxford Visual Geometry Group) descriptor trained end to end
  232. using "Descriptor Learning Using Convex Optimisation" (DLCO) aparatus described in @cite Simonyan14.
  233. @param desc type of descriptor to use, VGG::VGG_120 is default (120 dimensions float)
  234. Available types are VGG::VGG_120, VGG::VGG_80, VGG::VGG_64, VGG::VGG_48
  235. @param isigma gaussian kernel value for image blur (default is 1.4f)
  236. @param img_normalize use image sample intensity normalization (enabled by default)
  237. @param use_orientation sample patterns using keypoints orientation, enabled by default
  238. @param scale_factor adjust the sampling window of detected keypoints to 64.0f (VGG sampling window)
  239. 6.25f is default and fits for KAZE, SURF detected keypoints window ratio
  240. 6.75f should be the scale for SIFT detected keypoints window ratio
  241. 5.00f should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints window ratio
  242. 0.75f should be the scale for ORB keypoints ratio
  243. @param dsc_normalize clamp descriptors to 255 and convert to uchar CV_8UC1 (disabled by default)
  244. */
  245. class CV_EXPORTS_W VGG : public Feature2D
  246. {
  247. public:
  248. CV_WRAP enum
  249. {
  250. VGG_120 = 100, VGG_80 = 101, VGG_64 = 102, VGG_48 = 103,
  251. };
  252. CV_WRAP static Ptr<VGG> create( int desc = VGG::VGG_120, float isigma = 1.4f,
  253. bool img_normalize = true, bool use_scale_orientation = true,
  254. float scale_factor = 6.25f, bool dsc_normalize = false );
  255. CV_WRAP virtual void setSigma(const float isigma) = 0;
  256. CV_WRAP virtual float getSigma() const = 0;
  257. CV_WRAP virtual void setUseNormalizeImage(const bool img_normalize) = 0;
  258. CV_WRAP virtual bool getUseNormalizeImage() const = 0;
  259. CV_WRAP virtual void setUseScaleOrientation(const bool use_scale_orientation) = 0;
  260. CV_WRAP virtual bool getUseScaleOrientation() const = 0;
  261. CV_WRAP virtual void setScaleFactor(const float scale_factor) = 0;
  262. CV_WRAP virtual float getScaleFactor() const = 0;
  263. CV_WRAP virtual void setUseNormalizeDescriptor(const bool dsc_normalize) = 0;
  264. CV_WRAP virtual bool getUseNormalizeDescriptor() const = 0;
  265. };
  266. /** @brief Class implementing BoostDesc (Learning Image Descriptors with Boosting), described in
  267. @cite Trzcinski13a and @cite Trzcinski13b.
  268. @param desc type of descriptor to use, BoostDesc::BINBOOST_256 is default (256 bit long dimension)
  269. Available types are: BoostDesc::BGM, BoostDesc::BGM_HARD, BoostDesc::BGM_BILINEAR, BoostDesc::LBGM,
  270. BoostDesc::BINBOOST_64, BoostDesc::BINBOOST_128, BoostDesc::BINBOOST_256
  271. @param use_orientation sample patterns using keypoints orientation, enabled by default
  272. @param scale_factor adjust the sampling window of detected keypoints
  273. 6.25f is default and fits for KAZE, SURF detected keypoints window ratio
  274. 6.75f should be the scale for SIFT detected keypoints window ratio
  275. 5.00f should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints window ratio
  276. 0.75f should be the scale for ORB keypoints ratio
  277. 1.50f was the default in original implementation
  278. @note BGM is the base descriptor where each binary dimension is computed as the output of a single weak learner.
  279. BGM_HARD and BGM_BILINEAR refers to same BGM but use different type of gradient binning. In the BGM_HARD that
  280. use ASSIGN_HARD binning type the gradient is assigned to the nearest orientation bin. In the BGM_BILINEAR that use
  281. ASSIGN_BILINEAR binning type the gradient is assigned to the two neighbouring bins. In the BGM and all other modes that use
  282. ASSIGN_SOFT binning type the gradient is assigned to 8 nearest bins according to the cosine value between the gradient
  283. angle and the bin center. LBGM (alias FP-Boost) is the floating point extension where each dimension is computed
  284. as a linear combination of the weak learner responses. BINBOOST and subvariants are the binary extensions of LBGM
  285. where each bit is computed as a thresholded linear combination of a set of weak learners.
  286. BoostDesc header files (boostdesc_*.i) was exported from original binaries with export-boostdesc.py script from
  287. samples subfolder.
  288. */
  289. class CV_EXPORTS_W BoostDesc : public Feature2D
  290. {
  291. public:
  292. CV_WRAP enum
  293. {
  294. BGM = 100, BGM_HARD = 101, BGM_BILINEAR = 102, LBGM = 200,
  295. BINBOOST_64 = 300, BINBOOST_128 = 301, BINBOOST_256 = 302
  296. };
  297. CV_WRAP static Ptr<BoostDesc> create( int desc = BoostDesc::BINBOOST_256,
  298. bool use_scale_orientation = true, float scale_factor = 6.25f );
  299. CV_WRAP virtual void setUseScaleOrientation(const bool use_scale_orientation) = 0;
  300. CV_WRAP virtual bool getUseScaleOrientation() const = 0;
  301. CV_WRAP virtual void setScaleFactor(const float scale_factor) = 0;
  302. CV_WRAP virtual float getScaleFactor() const = 0;
  303. };
  304. /*
  305. * Position-Color-Texture signatures
  306. */
  307. /**
  308. * @brief Class implementing PCT (position-color-texture) signature extraction
  309. * as described in @cite KrulisLS16.
  310. * The algorithm is divided to a feature sampler and a clusterizer.
  311. * Feature sampler produces samples at given set of coordinates.
  312. * Clusterizer then produces clusters of these samples using k-means algorithm.
  313. * Resulting set of clusters is the signature of the input image.
  314. *
  315. * A signature is an array of SIGNATURE_DIMENSION-dimensional points.
  316. * Used dimensions are:
  317. * weight, x, y position; lab color, contrast, entropy.
  318. * @cite KrulisLS16
  319. * @cite BeecksUS10
  320. */
  321. class CV_EXPORTS_W PCTSignatures : public Algorithm
  322. {
  323. public:
  324. /**
  325. * @brief Lp distance function selector.
  326. */
  327. enum DistanceFunction
  328. {
  329. L0_25, L0_5, L1, L2, L2SQUARED, L5, L_INFINITY
  330. };
  331. /**
  332. * @brief Point distributions supported by random point generator.
  333. */
  334. enum PointDistribution
  335. {
  336. UNIFORM, //!< Generate numbers uniformly.
  337. REGULAR, //!< Generate points in a regular grid.
  338. NORMAL //!< Generate points with normal (gaussian) distribution.
  339. };
  340. /**
  341. * @brief Similarity function selector.
  342. * @see
  343. * Christian Beecks, Merih Seran Uysal, Thomas Seidl.
  344. * Signature quadratic form distance.
  345. * In Proceedings of the ACM International Conference on Image and Video Retrieval, pages 438-445.
  346. * ACM, 2010.
  347. * @cite BeecksUS10
  348. * @note For selected distance function: \f[ d(c_i, c_j) \f] and parameter: \f[ \alpha \f]
  349. */
  350. enum SimilarityFunction
  351. {
  352. MINUS, //!< \f[ -d(c_i, c_j) \f]
  353. GAUSSIAN, //!< \f[ e^{ -\alpha * d^2(c_i, c_j)} \f]
  354. HEURISTIC //!< \f[ \frac{1}{\alpha + d(c_i, c_j)} \f]
  355. };
  356. /**
  357. * @brief Creates PCTSignatures algorithm using sample and seed count.
  358. * It generates its own sets of sampling points and clusterization seed indexes.
  359. * @param initSampleCount Number of points used for image sampling.
  360. * @param initSeedCount Number of initial clusterization seeds.
  361. * Must be lower or equal to initSampleCount
  362. * @param pointDistribution Distribution of generated points. Default: UNIFORM.
  363. * Available: UNIFORM, REGULAR, NORMAL.
  364. * @return Created algorithm.
  365. */
  366. CV_WRAP static Ptr<PCTSignatures> create(
  367. const int initSampleCount = 2000,
  368. const int initSeedCount = 400,
  369. const int pointDistribution = 0);
  370. /**
  371. * @brief Creates PCTSignatures algorithm using pre-generated sampling points
  372. * and number of clusterization seeds. It uses the provided
  373. * sampling points and generates its own clusterization seed indexes.
  374. * @param initSamplingPoints Sampling points used in image sampling.
  375. * @param initSeedCount Number of initial clusterization seeds.
  376. * Must be lower or equal to initSamplingPoints.size().
  377. * @return Created algorithm.
  378. */
  379. CV_WRAP static Ptr<PCTSignatures> create(
  380. const std::vector<Point2f>& initSamplingPoints,
  381. const int initSeedCount);
  382. /**
  383. * @brief Creates PCTSignatures algorithm using pre-generated sampling points
  384. * and clusterization seeds indexes.
  385. * @param initSamplingPoints Sampling points used in image sampling.
  386. * @param initClusterSeedIndexes Indexes of initial clusterization seeds.
  387. * Its size must be lower or equal to initSamplingPoints.size().
  388. * @return Created algorithm.
  389. */
  390. CV_WRAP static Ptr<PCTSignatures> create(
  391. const std::vector<Point2f>& initSamplingPoints,
  392. const std::vector<int>& initClusterSeedIndexes);
  393. /**
  394. * @brief Computes signature of given image.
  395. * @param image Input image of CV_8U type.
  396. * @param signature Output computed signature.
  397. */
  398. CV_WRAP virtual void computeSignature(
  399. InputArray image,
  400. OutputArray signature) const = 0;
  401. /**
  402. * @brief Computes signatures for multiple images in parallel.
  403. * @param images Vector of input images of CV_8U type.
  404. * @param signatures Vector of computed signatures.
  405. */
  406. CV_WRAP virtual void computeSignatures(
  407. const std::vector<Mat>& images,
  408. std::vector<Mat>& signatures) const = 0;
  409. /**
  410. * @brief Draws signature in the source image and outputs the result.
  411. * Signatures are visualized as a circle
  412. * with radius based on signature weight
  413. * and color based on signature color.
  414. * Contrast and entropy are not visualized.
  415. * @param source Source image.
  416. * @param signature Image signature.
  417. * @param result Output result.
  418. * @param radiusToShorterSideRatio Determines maximal radius of signature in the output image.
  419. * @param borderThickness Border thickness of the visualized signature.
  420. */
  421. CV_WRAP static void drawSignature(
  422. InputArray source,
  423. InputArray signature,
  424. OutputArray result,
  425. float radiusToShorterSideRatio = 1.0 / 8,
  426. int borderThickness = 1);
  427. /**
  428. * @brief Generates initial sampling points according to selected point distribution.
  429. * @param initPoints Output vector where the generated points will be saved.
  430. * @param count Number of points to generate.
  431. * @param pointDistribution Point distribution selector.
  432. * Available: UNIFORM, REGULAR, NORMAL.
  433. * @note Generated coordinates are in range [0..1)
  434. */
  435. CV_WRAP static void generateInitPoints(
  436. std::vector<Point2f>& initPoints,
  437. const int count,
  438. int pointDistribution);
  439. /**** sampler ****/
  440. /**
  441. * @brief Number of initial samples taken from the image.
  442. */
  443. CV_WRAP virtual int getSampleCount() const = 0;
  444. /**
  445. * @brief Color resolution of the greyscale bitmap represented in allocated bits
  446. * (i.e., value 4 means that 16 shades of grey are used).
  447. * The greyscale bitmap is used for computing contrast and entropy values.
  448. */
  449. CV_WRAP virtual int getGrayscaleBits() const = 0;
  450. /**
  451. * @brief Color resolution of the greyscale bitmap represented in allocated bits
  452. * (i.e., value 4 means that 16 shades of grey are used).
  453. * The greyscale bitmap is used for computing contrast and entropy values.
  454. */
  455. CV_WRAP virtual void setGrayscaleBits(int grayscaleBits) = 0;
  456. /**
  457. * @brief Size of the texture sampling window used to compute contrast and entropy
  458. * (center of the window is always in the pixel selected by x,y coordinates
  459. * of the corresponding feature sample).
  460. */
  461. CV_WRAP virtual int getWindowRadius() const = 0;
  462. /**
  463. * @brief Size of the texture sampling window used to compute contrast and entropy
  464. * (center of the window is always in the pixel selected by x,y coordinates
  465. * of the corresponding feature sample).
  466. */
  467. CV_WRAP virtual void setWindowRadius(int radius) = 0;
  468. /**
  469. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  470. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  471. */
  472. CV_WRAP virtual float getWeightX() const = 0;
  473. /**
  474. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  475. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  476. */
  477. CV_WRAP virtual void setWeightX(float weight) = 0;
  478. /**
  479. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  480. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  481. */
  482. CV_WRAP virtual float getWeightY() const = 0;
  483. /**
  484. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  485. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  486. */
  487. CV_WRAP virtual void setWeightY(float weight) = 0;
  488. /**
  489. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  490. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  491. */
  492. CV_WRAP virtual float getWeightL() const = 0;
  493. /**
  494. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  495. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  496. */
  497. CV_WRAP virtual void setWeightL(float weight) = 0;
  498. /**
  499. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  500. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  501. */
  502. CV_WRAP virtual float getWeightA() const = 0;
  503. /**
  504. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  505. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  506. */
  507. CV_WRAP virtual void setWeightA(float weight) = 0;
  508. /**
  509. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  510. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  511. */
  512. CV_WRAP virtual float getWeightB() const = 0;
  513. /**
  514. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  515. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  516. */
  517. CV_WRAP virtual void setWeightB(float weight) = 0;
  518. /**
  519. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  520. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  521. */
  522. CV_WRAP virtual float getWeightContrast() const = 0;
  523. /**
  524. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  525. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  526. */
  527. CV_WRAP virtual void setWeightContrast(float weight) = 0;
  528. /**
  529. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  530. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  531. */
  532. CV_WRAP virtual float getWeightEntropy() const = 0;
  533. /**
  534. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  535. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  536. */
  537. CV_WRAP virtual void setWeightEntropy(float weight) = 0;
  538. /**
  539. * @brief Initial samples taken from the image.
  540. * These sampled features become the input for clustering.
  541. */
  542. CV_WRAP virtual std::vector<Point2f> getSamplingPoints() const = 0;
  543. /**
  544. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space.
  545. * @param idx ID of the weight
  546. * @param value Value of the weight
  547. * @note
  548. * WEIGHT_IDX = 0;
  549. * X_IDX = 1;
  550. * Y_IDX = 2;
  551. * L_IDX = 3;
  552. * A_IDX = 4;
  553. * B_IDX = 5;
  554. * CONTRAST_IDX = 6;
  555. * ENTROPY_IDX = 7;
  556. */
  557. CV_WRAP virtual void setWeight(int idx, float value) = 0;
  558. /**
  559. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space.
  560. * @param weights Values of all weights.
  561. * @note
  562. * WEIGHT_IDX = 0;
  563. * X_IDX = 1;
  564. * Y_IDX = 2;
  565. * L_IDX = 3;
  566. * A_IDX = 4;
  567. * B_IDX = 5;
  568. * CONTRAST_IDX = 6;
  569. * ENTROPY_IDX = 7;
  570. */
  571. CV_WRAP virtual void setWeights(const std::vector<float>& weights) = 0;
  572. /**
  573. * @brief Translations of the individual axes of the feature space.
  574. * @param idx ID of the translation
  575. * @param value Value of the translation
  576. * @note
  577. * WEIGHT_IDX = 0;
  578. * X_IDX = 1;
  579. * Y_IDX = 2;
  580. * L_IDX = 3;
  581. * A_IDX = 4;
  582. * B_IDX = 5;
  583. * CONTRAST_IDX = 6;
  584. * ENTROPY_IDX = 7;
  585. */
  586. CV_WRAP virtual void setTranslation(int idx, float value) = 0;
  587. /**
  588. * @brief Translations of the individual axes of the feature space.
  589. * @param translations Values of all translations.
  590. * @note
  591. * WEIGHT_IDX = 0;
  592. * X_IDX = 1;
  593. * Y_IDX = 2;
  594. * L_IDX = 3;
  595. * A_IDX = 4;
  596. * B_IDX = 5;
  597. * CONTRAST_IDX = 6;
  598. * ENTROPY_IDX = 7;
  599. */
  600. CV_WRAP virtual void setTranslations(const std::vector<float>& translations) = 0;
  601. /**
  602. * @brief Sets sampling points used to sample the input image.
  603. * @param samplingPoints Vector of sampling points in range [0..1)
  604. * @note Number of sampling points must be greater or equal to clusterization seed count.
  605. */
  606. CV_WRAP virtual void setSamplingPoints(std::vector<Point2f> samplingPoints) = 0;
  607. /**** clusterizer ****/
  608. /**
  609. * @brief Initial seeds (initial number of clusters) for the k-means algorithm.
  610. */
  611. CV_WRAP virtual std::vector<int> getInitSeedIndexes() const = 0;
  612. /**
  613. * @brief Initial seed indexes for the k-means algorithm.
  614. */
  615. CV_WRAP virtual void setInitSeedIndexes(std::vector<int> initSeedIndexes) = 0;
  616. /**
  617. * @brief Number of initial seeds (initial number of clusters) for the k-means algorithm.
  618. */
  619. CV_WRAP virtual int getInitSeedCount() const = 0;
  620. /**
  621. * @brief Number of iterations of the k-means clustering.
  622. * We use fixed number of iterations, since the modified clustering is pruning clusters
  623. * (not iteratively refining k clusters).
  624. */
  625. CV_WRAP virtual int getIterationCount() const = 0;
  626. /**
  627. * @brief Number of iterations of the k-means clustering.
  628. * We use fixed number of iterations, since the modified clustering is pruning clusters
  629. * (not iteratively refining k clusters).
  630. */
  631. CV_WRAP virtual void setIterationCount(int iterationCount) = 0;
  632. /**
  633. * @brief Maximal number of generated clusters. If the number is exceeded,
  634. * the clusters are sorted by their weights and the smallest clusters are cropped.
  635. */
  636. CV_WRAP virtual int getMaxClustersCount() const = 0;
  637. /**
  638. * @brief Maximal number of generated clusters. If the number is exceeded,
  639. * the clusters are sorted by their weights and the smallest clusters are cropped.
  640. */
  641. CV_WRAP virtual void setMaxClustersCount(int maxClustersCount) = 0;
  642. /**
  643. * @brief This parameter multiplied by the index of iteration gives lower limit for cluster size.
  644. * Clusters containing fewer points than specified by the limit have their centroid dismissed
  645. * and points are reassigned.
  646. */
  647. CV_WRAP virtual int getClusterMinSize() const = 0;
  648. /**
  649. * @brief This parameter multiplied by the index of iteration gives lower limit for cluster size.
  650. * Clusters containing fewer points than specified by the limit have their centroid dismissed
  651. * and points are reassigned.
  652. */
  653. CV_WRAP virtual void setClusterMinSize(int clusterMinSize) = 0;
  654. /**
  655. * @brief Threshold euclidean distance between two centroids.
  656. * If two cluster centers are closer than this distance,
  657. * one of the centroid is dismissed and points are reassigned.
  658. */
  659. CV_WRAP virtual float getJoiningDistance() const = 0;
  660. /**
  661. * @brief Threshold euclidean distance between two centroids.
  662. * If two cluster centers are closer than this distance,
  663. * one of the centroid is dismissed and points are reassigned.
  664. */
  665. CV_WRAP virtual void setJoiningDistance(float joiningDistance) = 0;
  666. /**
  667. * @brief Remove centroids in k-means whose weight is lesser or equal to given threshold.
  668. */
  669. CV_WRAP virtual float getDropThreshold() const = 0;
  670. /**
  671. * @brief Remove centroids in k-means whose weight is lesser or equal to given threshold.
  672. */
  673. CV_WRAP virtual void setDropThreshold(float dropThreshold) = 0;
  674. /**
  675. * @brief Distance function selector used for measuring distance between two points in k-means.
  676. */
  677. CV_WRAP virtual int getDistanceFunction() const = 0;
  678. /**
  679. * @brief Distance function selector used for measuring distance between two points in k-means.
  680. * Available: L0_25, L0_5, L1, L2, L2SQUARED, L5, L_INFINITY.
  681. */
  682. CV_WRAP virtual void setDistanceFunction(int distanceFunction) = 0;
  683. };
  684. /**
  685. * @brief Class implementing Signature Quadratic Form Distance (SQFD).
  686. * @see Christian Beecks, Merih Seran Uysal, Thomas Seidl.
  687. * Signature quadratic form distance.
  688. * In Proceedings of the ACM International Conference on Image and Video Retrieval, pages 438-445.
  689. * ACM, 2010.
  690. * @cite BeecksUS10
  691. */
  692. class CV_EXPORTS_W PCTSignaturesSQFD : public Algorithm
  693. {
  694. public:
  695. /**
  696. * @brief Creates the algorithm instance using selected distance function,
  697. * similarity function and similarity function parameter.
  698. * @param distanceFunction Distance function selector. Default: L2
  699. * Available: L0_25, L0_5, L1, L2, L2SQUARED, L5, L_INFINITY
  700. * @param similarityFunction Similarity function selector. Default: HEURISTIC
  701. * Available: MINUS, GAUSSIAN, HEURISTIC
  702. * @param similarityParameter Parameter of the similarity function.
  703. */
  704. CV_WRAP static Ptr<PCTSignaturesSQFD> create(
  705. const int distanceFunction = 3,
  706. const int similarityFunction = 2,
  707. const float similarityParameter = 1.0f);
  708. /**
  709. * @brief Computes Signature Quadratic Form Distance of two signatures.
  710. * @param _signature0 The first signature.
  711. * @param _signature1 The second signature.
  712. */
  713. CV_WRAP virtual float computeQuadraticFormDistance(
  714. InputArray _signature0,
  715. InputArray _signature1) const = 0;
  716. /**
  717. * @brief Computes Signature Quadratic Form Distance between the reference signature
  718. * and each of the other image signatures.
  719. * @param sourceSignature The signature to measure distance of other signatures from.
  720. * @param imageSignatures Vector of signatures to measure distance from the source signature.
  721. * @param distances Output vector of measured distances.
  722. */
  723. CV_WRAP virtual void computeQuadraticFormDistances(
  724. const Mat& sourceSignature,
  725. const std::vector<Mat>& imageSignatures,
  726. std::vector<float>& distances) const = 0;
  727. };
  728. /**
  729. * @brief Elliptic region around an interest point.
  730. */
  731. class CV_EXPORTS Elliptic_KeyPoint : public KeyPoint
  732. {
  733. public:
  734. Size_<float> axes; //!< the lengths of the major and minor ellipse axes
  735. float si; //!< the integration scale at which the parameters were estimated
  736. Matx23f transf; //!< the transformation between image space and local patch space
  737. Elliptic_KeyPoint();
  738. Elliptic_KeyPoint(Point2f pt, float angle, Size axes, float size, float si);
  739. virtual ~Elliptic_KeyPoint();
  740. };
  741. /**
  742. * @brief Class implementing the Harris-Laplace feature detector as described in @cite Mikolajczyk2004.
  743. */
  744. class CV_EXPORTS_W HarrisLaplaceFeatureDetector : public Feature2D
  745. {
  746. public:
  747. /**
  748. * @brief Creates a new implementation instance.
  749. *
  750. * @param numOctaves the number of octaves in the scale-space pyramid
  751. * @param corn_thresh the threshold for the Harris cornerness measure
  752. * @param DOG_thresh the threshold for the Difference-of-Gaussians scale selection
  753. * @param maxCorners the maximum number of corners to consider
  754. * @param num_layers the number of intermediate scales per octave
  755. */
  756. CV_WRAP static Ptr<HarrisLaplaceFeatureDetector> create(
  757. int numOctaves=6,
  758. float corn_thresh=0.01f,
  759. float DOG_thresh=0.01f,
  760. int maxCorners=5000,
  761. int num_layers=4);
  762. };
  763. /**
  764. * @brief Class implementing affine adaptation for key points.
  765. *
  766. * A @ref FeatureDetector and a @ref DescriptorExtractor are wrapped to augment the
  767. * detected points with their affine invariant elliptic region and to compute
  768. * the feature descriptors on the regions after warping them into circles.
  769. *
  770. * The interface is equivalent to @ref Feature2D, adding operations for
  771. * @ref Elliptic_KeyPoint "Elliptic_KeyPoints" instead of @ref KeyPoint "KeyPoints".
  772. */
  773. class CV_EXPORTS AffineFeature2D : public Feature2D
  774. {
  775. public:
  776. /**
  777. * @brief Creates an instance wrapping the given keypoint detector and
  778. * descriptor extractor.
  779. */
  780. static Ptr<AffineFeature2D> create(
  781. Ptr<FeatureDetector> keypoint_detector,
  782. Ptr<DescriptorExtractor> descriptor_extractor);
  783. /**
  784. * @brief Creates an instance where keypoint detector and descriptor
  785. * extractor are identical.
  786. */
  787. static Ptr<AffineFeature2D> create(
  788. Ptr<FeatureDetector> keypoint_detector)
  789. {
  790. return create(keypoint_detector, keypoint_detector);
  791. }
  792. using Feature2D::detect; // overload, don't hide
  793. /**
  794. * @brief Detects keypoints in the image using the wrapped detector and
  795. * performs affine adaptation to augment them with their elliptic regions.
  796. */
  797. virtual void detect(
  798. InputArray image,
  799. CV_OUT std::vector<Elliptic_KeyPoint>& keypoints,
  800. InputArray mask=noArray() ) = 0;
  801. using Feature2D::detectAndCompute; // overload, don't hide
  802. /**
  803. * @brief Detects keypoints and computes descriptors for their surrounding
  804. * regions, after warping them into circles.
  805. */
  806. virtual void detectAndCompute(
  807. InputArray image,
  808. InputArray mask,
  809. CV_OUT std::vector<Elliptic_KeyPoint>& keypoints,
  810. OutputArray descriptors,
  811. bool useProvidedKeypoints=false ) = 0;
  812. };
  813. /** @brief Estimates cornerness for prespecified KeyPoints using the FAST algorithm
  814. @param image grayscale image where keypoints (corners) are detected.
  815. @param keypoints keypoints which should be tested to fit the FAST criteria. Keypoints not being
  816. detected as corners are removed.
  817. @param threshold threshold on difference between intensity of the central pixel and pixels of a
  818. circle around this pixel.
  819. @param nonmaxSuppression if true, non-maximum suppression is applied to detected corners
  820. (keypoints).
  821. @param type one of the three neighborhoods as defined in the paper:
  822. FastFeatureDetector::TYPE_9_16, FastFeatureDetector::TYPE_7_12,
  823. FastFeatureDetector::TYPE_5_8
  824. Detects corners using the FAST algorithm by @cite Rosten06 .
  825. */
  826. CV_EXPORTS void FASTForPointSet( InputArray image, CV_IN_OUT std::vector<KeyPoint>& keypoints,
  827. int threshold, bool nonmaxSuppression=true, int type=FastFeatureDetector::TYPE_9_16);
  828. //! @}
  829. //! @addtogroup xfeatures2d_match
  830. //! @{
  831. /** @brief GMS (Grid-based Motion Statistics) feature matching strategy by @cite Bian2017gms .
  832. @param size1 Input size of image1.
  833. @param size2 Input size of image2.
  834. @param keypoints1 Input keypoints of image1.
  835. @param keypoints2 Input keypoints of image2.
  836. @param matches1to2 Input 1-nearest neighbor matches.
  837. @param matchesGMS Matches returned by the GMS matching strategy.
  838. @param withRotation Take rotation transformation into account.
  839. @param withScale Take scale transformation into account.
  840. @param thresholdFactor The higher, the less matches.
  841. @note
  842. Since GMS works well when the number of features is large, we recommend to use the ORB feature and set FastThreshold to 0 to get as many as possible features quickly.
  843. If matching results are not satisfying, please add more features. (We use 10000 for images with 640 X 480).
  844. If your images have big rotation and scale changes, please set withRotation or withScale to true.
  845. */
  846. CV_EXPORTS_W void matchGMS( const Size& size1, const Size& size2, const std::vector<KeyPoint>& keypoints1, const std::vector<KeyPoint>& keypoints2,
  847. const std::vector<DMatch>& matches1to2, CV_OUT std::vector<DMatch>& matchesGMS, const bool withRotation = false,
  848. const bool withScale = false, const double thresholdFactor = 6.0 );
  849. //! @}
  850. }
  851. }
  852. #endif