xfeatures2d.hpp 53 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279
  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 following matching strategies:
  44. - GMS: Grid-based Motion Statistics, @cite Bian2017gms
  45. - LOGOS: Local geometric support for high-outlier spatial verification, @cite Lowry2018LOGOSLG
  46. @}
  47. */
  48. namespace cv
  49. {
  50. namespace xfeatures2d
  51. {
  52. //! @addtogroup xfeatures2d_experiment
  53. //! @{
  54. /** @brief Class implementing the FREAK (*Fast Retina Keypoint*) keypoint descriptor, described in @cite AOV12 .
  55. The algorithm propose a novel keypoint descriptor inspired by the human visual system and more
  56. precisely the retina, coined Fast Retina Key- point (FREAK). A cascade of binary strings is
  57. computed by efficiently comparing image intensities over a retinal sampling pattern. FREAKs are in
  58. general faster to compute with lower memory load and also more robust than SIFT, SURF or BRISK.
  59. They are competitive alternatives to existing keypoints in particular for embedded applications.
  60. @note
  61. - An example on how to use the FREAK descriptor can be found at
  62. opencv_source_code/samples/cpp/freak_demo.cpp
  63. */
  64. class CV_EXPORTS_W FREAK : public Feature2D
  65. {
  66. public:
  67. static const int NB_SCALES = 64;
  68. static const int NB_PAIRS = 512;
  69. static const int NB_ORIENPAIRS = 45;
  70. /**
  71. @param orientationNormalized Enable orientation normalization.
  72. @param scaleNormalized Enable scale normalization.
  73. @param patternScale Scaling of the description pattern.
  74. @param nOctaves Number of octaves covered by the detected keypoints.
  75. @param selectedPairs (Optional) user defined selected pairs indexes,
  76. */
  77. CV_WRAP static Ptr<FREAK> create(bool orientationNormalized = true,
  78. bool scaleNormalized = true,
  79. float patternScale = 22.0f,
  80. int nOctaves = 4,
  81. const std::vector<int>& selectedPairs = std::vector<int>());
  82. CV_WRAP virtual void setOrientationNormalized(bool orientationNormalized) = 0;
  83. CV_WRAP virtual bool getOrientationNormalized() const = 0;
  84. CV_WRAP virtual void setScaleNormalized(bool scaleNormalized) = 0;
  85. CV_WRAP virtual bool getScaleNormalized() const = 0;
  86. CV_WRAP virtual void setPatternScale(double patternScale) = 0;
  87. CV_WRAP virtual double getPatternScale() const = 0;
  88. CV_WRAP virtual void setNOctaves(int nOctaves) = 0;
  89. CV_WRAP virtual int getNOctaves() const = 0;
  90. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  91. };
  92. /** @brief The class implements the keypoint detector introduced by @cite Agrawal08, synonym of StarDetector. :
  93. */
  94. class CV_EXPORTS_W StarDetector : public Feature2D
  95. {
  96. public:
  97. //! the full constructor
  98. CV_WRAP static Ptr<StarDetector> create(int maxSize=45, int responseThreshold=30,
  99. int lineThresholdProjected=10,
  100. int lineThresholdBinarized=8,
  101. int suppressNonmaxSize=5);
  102. CV_WRAP virtual void setMaxSize(int _maxSize) = 0;
  103. CV_WRAP virtual int getMaxSize() const = 0;
  104. CV_WRAP virtual void setResponseThreshold(int _responseThreshold) = 0;
  105. CV_WRAP virtual int getResponseThreshold() const = 0;
  106. CV_WRAP virtual void setLineThresholdProjected(int _lineThresholdProjected) = 0;
  107. CV_WRAP virtual int getLineThresholdProjected() const = 0;
  108. CV_WRAP virtual void setLineThresholdBinarized(int _lineThresholdBinarized) = 0;
  109. CV_WRAP virtual int getLineThresholdBinarized() const = 0;
  110. CV_WRAP virtual void setSuppressNonmaxSize(int _suppressNonmaxSize) = 0;
  111. CV_WRAP virtual int getSuppressNonmaxSize() const = 0;
  112. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  113. };
  114. /*
  115. * BRIEF Descriptor
  116. */
  117. /** @brief Class for computing BRIEF descriptors described in @cite calon2010 .
  118. @param bytes legth of the descriptor in bytes, valid values are: 16, 32 (default) or 64 .
  119. @param use_orientation sample patterns using keypoints orientation, disabled by default.
  120. */
  121. class CV_EXPORTS_W BriefDescriptorExtractor : public Feature2D
  122. {
  123. public:
  124. CV_WRAP static Ptr<BriefDescriptorExtractor> create( int bytes = 32, bool use_orientation = false );
  125. CV_WRAP virtual void setDescriptorSize(int bytes) = 0;
  126. CV_WRAP virtual int getDescriptorSize() const = 0;
  127. CV_WRAP virtual void setUseOrientation(bool use_orientation) = 0;
  128. CV_WRAP virtual bool getUseOrientation() const = 0;
  129. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  130. };
  131. /** @brief Class implementing the locally uniform comparison image descriptor, described in @cite LUCID
  132. An image descriptor that can be computed very fast, while being
  133. about as robust as, for example, SURF or BRIEF.
  134. @note It requires a color image as input.
  135. */
  136. class CV_EXPORTS_W LUCID : public Feature2D
  137. {
  138. public:
  139. /**
  140. * @param lucid_kernel kernel for descriptor construction, where 1=3x3, 2=5x5, 3=7x7 and so forth
  141. * @param blur_kernel kernel for blurring image prior to descriptor construction, where 1=3x3, 2=5x5, 3=7x7 and so forth
  142. */
  143. CV_WRAP static Ptr<LUCID> create(const int lucid_kernel = 1, const int blur_kernel = 2);
  144. CV_WRAP virtual void setLucidKernel(int lucid_kernel) = 0;
  145. CV_WRAP virtual int getLucidKernel() const = 0;
  146. CV_WRAP virtual void setBlurKernel(int blur_kernel) = 0;
  147. CV_WRAP virtual int getBlurKernel() const = 0;
  148. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  149. };
  150. /*
  151. * LATCH Descriptor
  152. */
  153. /** latch Class for computing the LATCH descriptor.
  154. If you find this code useful, please add a reference to the following paper in your work:
  155. Gil Levi and Tal Hassner, "LATCH: Learned Arrangements of Three Patch Codes", arXiv preprint arXiv:1501.03719, 15 Jan. 2015
  156. LATCH is a binary descriptor based on learned comparisons of triplets of image patches.
  157. * bytes is the size of the descriptor - can be 64, 32, 16, 8, 4, 2 or 1
  158. * rotationInvariance - whether or not the descriptor should compansate for orientation changes.
  159. * 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
  160. then the half_ssd_size should be (7-1)/2 = 3.
  161. * sigma - sigma value for GaussianBlur smoothing of the source image. Source image will be used without smoothing in case sigma value is 0.
  162. Note: the descriptor can be coupled with any keypoint extractor. The only demand is that if you use set rotationInvariance = True then
  163. you will have to use an extractor which estimates the patch orientation (in degrees). Examples for such extractors are ORB and SIFT.
  164. Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures2D/latch_match.cpp
  165. */
  166. class CV_EXPORTS_W LATCH : public Feature2D
  167. {
  168. public:
  169. CV_WRAP static Ptr<LATCH> create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3, double sigma = 2.0);
  170. CV_WRAP virtual void setBytes(int bytes) = 0;
  171. CV_WRAP virtual int getBytes() const = 0;
  172. CV_WRAP virtual void setRotationInvariance(bool rotationInvariance) = 0;
  173. CV_WRAP virtual bool getRotationInvariance() const = 0;
  174. CV_WRAP virtual void setHalfSSDsize(int half_ssd_size) = 0;
  175. CV_WRAP virtual int getHalfSSDsize() const = 0;
  176. CV_WRAP virtual void setSigma(double sigma) = 0;
  177. CV_WRAP virtual double getSigma() const = 0;
  178. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  179. };
  180. /** @brief Class implementing BEBLID (Boosted Efficient Binary Local Image Descriptor),
  181. * described in @cite Suarez2020BEBLID .
  182. BEBLID \cite Suarez2020BEBLID is a efficient binary descriptor learned with boosting.
  183. It is able to describe keypoints from any detector just by changing the scale_factor parameter.
  184. In several benchmarks it has proved to largely improve other binary descriptors like ORB or
  185. BRISK with the same efficiency. BEBLID describes using the difference of mean gray values in
  186. different regions of the image around the KeyPoint, the descriptor is specifically optimized for
  187. image matching and patch retrieval addressing the asymmetries of these problems.
  188. If you find this code useful, please add a reference to the following paper:
  189. <BLOCKQUOTE> Iago Suárez, Ghesn Sfeir, José M. Buenaposada, and Luis Baumela.
  190. BEBLID: Boosted efficient binary local image descriptor.
  191. Pattern Recognition Letters, 133:366–372, 2020. </BLOCKQUOTE>
  192. The descriptor was trained using 1 million of randomly sampled pairs of patches
  193. (20% positives and 80% negatives) from the Liberty split of the UBC datasets
  194. \cite winder2007learning as described in the paper @cite Suarez2020BEBLID.
  195. You can check in the [AKAZE example](https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp)
  196. how well BEBLID works. Detecting 10000 keypoints with ORB and describing with BEBLID obtains
  197. 561 inliers (75%) whereas describing with ORB obtains only 493 inliers (63%).
  198. */
  199. class CV_EXPORTS_W BEBLID : public Feature2D
  200. {
  201. public:
  202. /**
  203. * @brief Descriptor number of bits, each bit is a boosting weak-learner.
  204. * The user can choose between 512 or 256 bits.
  205. */
  206. enum BeblidSize
  207. {
  208. SIZE_512_BITS = 100, SIZE_256_BITS = 101,
  209. };
  210. /** @brief Creates the BEBLID descriptor.
  211. @param scale_factor Adjust the sampling window around detected keypoints:
  212. - <b> 1.00f </b> should be the scale for ORB keypoints
  213. - <b> 6.75f </b> should be the scale for SIFT detected keypoints
  214. - <b> 6.25f </b> is default and fits for KAZE, SURF detected keypoints
  215. - <b> 5.00f </b> should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
  216. @param n_bits Determine the number of bits in the descriptor. Should be either
  217. BEBLID::SIZE_512_BITS or BEBLID::SIZE_256_BITS.
  218. */
  219. CV_WRAP static Ptr<BEBLID> create(float scale_factor, int n_bits = BEBLID::SIZE_512_BITS);
  220. CV_WRAP virtual void setScaleFactor(float scale_factor) = 0;
  221. CV_WRAP virtual float getScaleFactor() const = 0;
  222. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  223. };
  224. /** @brief Class implementing TEBLID (Triplet-based Efficient Binary Local Image Descriptor),
  225. * described in @cite Suarez2021TEBLID.
  226. TEBLID stands for Triplet-based Efficient Binary Local Image Descriptor, although originally it was called BAD
  227. \cite Suarez2021TEBLID. It is an improvement over BEBLID \cite Suarez2020BEBLID, that uses triplet loss,
  228. hard negative mining, and anchor swap to improve the image matching results.
  229. It is able to describe keypoints from any detector just by changing the scale_factor parameter.
  230. TEBLID is as efficient as ORB, BEBLID or BRISK, but the triplet-based training objective selected more
  231. discriminative features that explain the accuracy gain. It is also more compact than BEBLID,
  232. when running the [AKAZE example](https://github.com/opencv/opencv/blob/4.x/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp)
  233. with 10000 keypoints detected by ORB, BEBLID obtains 561 inliers (75%) with 512 bits, whereas
  234. TEBLID obtains 621 (75.2%) with 256 bits. ORB obtains only 493 inliers (63%).
  235. If you find this code useful, please add a reference to the following paper:
  236. <BLOCKQUOTE> Iago Suárez, José M. Buenaposada, and Luis Baumela.
  237. Revisiting Binary Local Image Description for Resource Limited Devices.
  238. IEEE Robotics and Automation Letters, vol. 6, no. 4, pp. 8317-8324, Oct. 2021. </BLOCKQUOTE>
  239. The descriptor was trained in Liberty split of the UBC datasets \cite winder2007learning .
  240. */
  241. class CV_EXPORTS_W TEBLID : public Feature2D
  242. {
  243. public:
  244. /**
  245. * @brief Descriptor number of bits, each bit is a box average difference.
  246. * The user can choose between 256 or 512 bits.
  247. */
  248. enum TeblidSize
  249. {
  250. SIZE_256_BITS = 102, SIZE_512_BITS = 103,
  251. };
  252. /** @brief Creates the TEBLID descriptor.
  253. @param scale_factor Adjust the sampling window around detected keypoints:
  254. - <b> 1.00f </b> should be the scale for ORB keypoints
  255. - <b> 6.75f </b> should be the scale for SIFT detected keypoints
  256. - <b> 6.25f </b> is default and fits for KAZE, SURF detected keypoints
  257. - <b> 5.00f </b> should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
  258. @param n_bits Determine the number of bits in the descriptor. Should be either
  259. TEBLID::SIZE_256_BITS or TEBLID::SIZE_512_BITS.
  260. */
  261. CV_WRAP static Ptr<TEBLID> create(float scale_factor, int n_bits = TEBLID::SIZE_256_BITS);
  262. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  263. };
  264. /** @brief Class implementing DAISY descriptor, described in @cite Tola10
  265. @param radius radius of the descriptor at the initial scale
  266. @param q_radius amount of radial range division quantity
  267. @param q_theta amount of angular range division quantity
  268. @param q_hist amount of gradient orientations range division quantity
  269. @param norm choose descriptors normalization type, where
  270. DAISY::NRM_NONE will not do any normalization (default),
  271. DAISY::NRM_PARTIAL mean that histograms are normalized independently for L2 norm equal to 1.0,
  272. DAISY::NRM_FULL mean that descriptors are normalized for L2 norm equal to 1.0,
  273. 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
  274. @param H optional 3x3 homography matrix used to warp the grid of daisy but sampling keypoints remains unwarped on image
  275. @param interpolation switch to disable interpolation for speed improvement at minor quality loss
  276. @param use_orientation sample patterns using keypoints orientation, disabled by default.
  277. */
  278. class CV_EXPORTS_W DAISY : public Feature2D
  279. {
  280. public:
  281. enum NormalizationType
  282. {
  283. NRM_NONE = 100, NRM_PARTIAL = 101, NRM_FULL = 102, NRM_SIFT = 103,
  284. };
  285. CV_WRAP static Ptr<DAISY> create( float radius = 15, int q_radius = 3, int q_theta = 8,
  286. int q_hist = 8, DAISY::NormalizationType norm = DAISY::NRM_NONE, InputArray H = noArray(),
  287. bool interpolation = true, bool use_orientation = false );
  288. CV_WRAP virtual void setRadius(float radius) = 0;
  289. CV_WRAP virtual float getRadius() const = 0;
  290. CV_WRAP virtual void setQRadius(int q_radius) = 0;
  291. CV_WRAP virtual int getQRadius() const = 0;
  292. CV_WRAP virtual void setQTheta(int q_theta) = 0;
  293. CV_WRAP virtual int getQTheta() const = 0;
  294. CV_WRAP virtual void setQHist(int q_hist) = 0;
  295. CV_WRAP virtual int getQHist() const = 0;
  296. CV_WRAP virtual void setNorm(int norm) = 0;
  297. CV_WRAP virtual int getNorm() const = 0;
  298. CV_WRAP virtual void setH(InputArray H) = 0;
  299. CV_WRAP virtual cv::Mat getH() const = 0;
  300. CV_WRAP virtual void setInterpolation(bool interpolation) = 0;
  301. CV_WRAP virtual bool getInterpolation() const = 0;
  302. CV_WRAP virtual void setUseOrientation(bool use_orientation) = 0;
  303. CV_WRAP virtual bool getUseOrientation() const = 0;
  304. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  305. /** @overload
  306. * @param image image to extract descriptors
  307. * @param keypoints of interest within image
  308. * @param descriptors resulted descriptors array
  309. */
  310. virtual void compute( InputArray image, std::vector<KeyPoint>& keypoints, OutputArray descriptors ) CV_OVERRIDE = 0;
  311. virtual void compute( InputArrayOfArrays images,
  312. std::vector<std::vector<KeyPoint> >& keypoints,
  313. OutputArrayOfArrays descriptors ) CV_OVERRIDE;
  314. /** @overload
  315. * @param image image to extract descriptors
  316. * @param roi region of interest within image
  317. * @param descriptors resulted descriptors array for roi image pixels
  318. */
  319. virtual void compute( InputArray image, Rect roi, OutputArray descriptors ) = 0;
  320. /**@overload
  321. * @param image image to extract descriptors
  322. * @param descriptors resulted descriptors array for all image pixels
  323. */
  324. virtual void compute( InputArray image, OutputArray descriptors ) = 0;
  325. /**
  326. * @param y position y on image
  327. * @param x position x on image
  328. * @param orientation orientation on image (0->360)
  329. * @param descriptor supplied array for descriptor storage
  330. */
  331. virtual void GetDescriptor( double y, double x, int orientation, float* descriptor ) const = 0;
  332. /**
  333. * @param y position y on image
  334. * @param x position x on image
  335. * @param orientation orientation on image (0->360)
  336. * @param descriptor supplied array for descriptor storage
  337. * @param H homography matrix for warped grid
  338. */
  339. virtual bool GetDescriptor( double y, double x, int orientation, float* descriptor, double* H ) const = 0;
  340. /**
  341. * @param y position y on image
  342. * @param x position x on image
  343. * @param orientation orientation on image (0->360)
  344. * @param descriptor supplied array for descriptor storage
  345. */
  346. virtual void GetUnnormalizedDescriptor( double y, double x, int orientation, float* descriptor ) const = 0;
  347. /**
  348. * @param y position y on image
  349. * @param x position x on image
  350. * @param orientation orientation on image (0->360)
  351. * @param descriptor supplied array for descriptor storage
  352. * @param H homography matrix for warped grid
  353. */
  354. virtual bool GetUnnormalizedDescriptor( double y, double x, int orientation, float* descriptor , double *H ) const = 0;
  355. };
  356. /** @brief Class implementing the MSD (*Maximal Self-Dissimilarity*) keypoint detector, described in @cite Tombari14.
  357. The algorithm implements a novel interest point detector stemming from the intuition that image patches
  358. which are highly dissimilar over a relatively large extent of their surroundings hold the property of
  359. being repeatable and distinctive. This concept of "contextual self-dissimilarity" reverses the key
  360. paradigm of recent successful techniques such as the Local Self-Similarity descriptor and the Non-Local
  361. Means filter, which build upon the presence of similar - rather than dissimilar - patches. Moreover,
  362. it extends to contextual information the local self-dissimilarity notion embedded in established
  363. detectors of corner-like interest points, thereby achieving enhanced repeatability, distinctiveness and
  364. localization accuracy.
  365. */
  366. class CV_EXPORTS_W MSDDetector : public Feature2D {
  367. public:
  368. CV_WRAP static Ptr<MSDDetector> create(int m_patch_radius = 3, int m_search_area_radius = 5,
  369. int m_nms_radius = 5, int m_nms_scale_radius = 0, float m_th_saliency = 250.0f, int m_kNN = 4,
  370. float m_scale_factor = 1.25f, int m_n_scales = -1, bool m_compute_orientation = false);
  371. CV_WRAP virtual void setPatchRadius(int patch_radius) = 0;
  372. CV_WRAP virtual int getPatchRadius() const = 0;
  373. CV_WRAP virtual void setSearchAreaRadius(int use_orientation) = 0;
  374. CV_WRAP virtual int getSearchAreaRadius() const = 0;
  375. CV_WRAP virtual void setNmsRadius(int nms_radius) = 0;
  376. CV_WRAP virtual int getNmsRadius() const = 0;
  377. CV_WRAP virtual void setNmsScaleRadius(int nms_scale_radius) = 0;
  378. CV_WRAP virtual int getNmsScaleRadius() const = 0;
  379. CV_WRAP virtual void setThSaliency(float th_saliency) = 0;
  380. CV_WRAP virtual float getThSaliency() const = 0;
  381. CV_WRAP virtual void setKNN(int kNN) = 0;
  382. CV_WRAP virtual int getKNN() const = 0;
  383. CV_WRAP virtual void setScaleFactor(float scale_factor) = 0;
  384. CV_WRAP virtual float getScaleFactor() const = 0;
  385. CV_WRAP virtual void setNScales(int use_orientation) = 0;
  386. CV_WRAP virtual int getNScales() const = 0;
  387. CV_WRAP virtual void setComputeOrientation(bool compute_orientation) = 0;
  388. CV_WRAP virtual bool getComputeOrientation() const = 0;
  389. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  390. };
  391. /** @brief Class implementing VGG (Oxford Visual Geometry Group) descriptor trained end to end
  392. using "Descriptor Learning Using Convex Optimisation" (DLCO) aparatus described in @cite Simonyan14.
  393. @param desc type of descriptor to use, VGG::VGG_120 is default (120 dimensions float)
  394. Available types are VGG::VGG_120, VGG::VGG_80, VGG::VGG_64, VGG::VGG_48
  395. @param isigma gaussian kernel value for image blur (default is 1.4f)
  396. @param img_normalize use image sample intensity normalization (enabled by default)
  397. @param use_orientation sample patterns using keypoints orientation, enabled by default
  398. @param scale_factor adjust the sampling window of detected keypoints to 64.0f (VGG sampling window)
  399. 6.25f is default and fits for KAZE, SURF detected keypoints window ratio
  400. 6.75f should be the scale for SIFT detected keypoints window ratio
  401. 5.00f should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints window ratio
  402. 0.75f should be the scale for ORB keypoints ratio
  403. @param dsc_normalize clamp descriptors to 255 and convert to uchar CV_8UC1 (disabled by default)
  404. */
  405. class CV_EXPORTS_W VGG : public Feature2D
  406. {
  407. public:
  408. CV_WRAP enum
  409. {
  410. VGG_120 = 100, VGG_80 = 101, VGG_64 = 102, VGG_48 = 103,
  411. };
  412. CV_WRAP static Ptr<VGG> create( int desc = VGG::VGG_120, float isigma = 1.4f,
  413. bool img_normalize = true, bool use_scale_orientation = true,
  414. float scale_factor = 6.25f, bool dsc_normalize = false );
  415. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  416. CV_WRAP virtual void setSigma(const float isigma) = 0;
  417. CV_WRAP virtual float getSigma() const = 0;
  418. CV_WRAP virtual void setUseNormalizeImage(const bool img_normalize) = 0;
  419. CV_WRAP virtual bool getUseNormalizeImage() const = 0;
  420. CV_WRAP virtual void setUseScaleOrientation(const bool use_scale_orientation) = 0;
  421. CV_WRAP virtual bool getUseScaleOrientation() const = 0;
  422. CV_WRAP virtual void setScaleFactor(const float scale_factor) = 0;
  423. CV_WRAP virtual float getScaleFactor() const = 0;
  424. CV_WRAP virtual void setUseNormalizeDescriptor(const bool dsc_normalize) = 0;
  425. CV_WRAP virtual bool getUseNormalizeDescriptor() const = 0;
  426. };
  427. /** @brief Class implementing BoostDesc (Learning Image Descriptors with Boosting), described in
  428. @cite Trzcinski13a and @cite Trzcinski13b.
  429. @param desc type of descriptor to use, BoostDesc::BINBOOST_256 is default (256 bit long dimension)
  430. Available types are: BoostDesc::BGM, BoostDesc::BGM_HARD, BoostDesc::BGM_BILINEAR, BoostDesc::LBGM,
  431. BoostDesc::BINBOOST_64, BoostDesc::BINBOOST_128, BoostDesc::BINBOOST_256
  432. @param use_orientation sample patterns using keypoints orientation, enabled by default
  433. @param scale_factor adjust the sampling window of detected keypoints
  434. 6.25f is default and fits for KAZE, SURF detected keypoints window ratio
  435. 6.75f should be the scale for SIFT detected keypoints window ratio
  436. 5.00f should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints window ratio
  437. 0.75f should be the scale for ORB keypoints ratio
  438. 1.50f was the default in original implementation
  439. @note BGM is the base descriptor where each binary dimension is computed as the output of a single weak learner.
  440. BGM_HARD and BGM_BILINEAR refers to same BGM but use different type of gradient binning. In the BGM_HARD that
  441. use ASSIGN_HARD binning type the gradient is assigned to the nearest orientation bin. In the BGM_BILINEAR that use
  442. ASSIGN_BILINEAR binning type the gradient is assigned to the two neighbouring bins. In the BGM and all other modes that use
  443. ASSIGN_SOFT binning type the gradient is assigned to 8 nearest bins according to the cosine value between the gradient
  444. angle and the bin center. LBGM (alias FP-Boost) is the floating point extension where each dimension is computed
  445. as a linear combination of the weak learner responses. BINBOOST and subvariants are the binary extensions of LBGM
  446. where each bit is computed as a thresholded linear combination of a set of weak learners.
  447. BoostDesc header files (boostdesc_*.i) was exported from original binaries with export-boostdesc.py script from
  448. samples subfolder.
  449. */
  450. class CV_EXPORTS_W BoostDesc : public Feature2D
  451. {
  452. public:
  453. CV_WRAP enum
  454. {
  455. BGM = 100, BGM_HARD = 101, BGM_BILINEAR = 102, LBGM = 200,
  456. BINBOOST_64 = 300, BINBOOST_128 = 301, BINBOOST_256 = 302
  457. };
  458. CV_WRAP static Ptr<BoostDesc> create( int desc = BoostDesc::BINBOOST_256,
  459. bool use_scale_orientation = true, float scale_factor = 6.25f );
  460. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  461. CV_WRAP virtual void setUseScaleOrientation(const bool use_scale_orientation) = 0;
  462. CV_WRAP virtual bool getUseScaleOrientation() const = 0;
  463. CV_WRAP virtual void setScaleFactor(const float scale_factor) = 0;
  464. CV_WRAP virtual float getScaleFactor() const = 0;
  465. };
  466. /*
  467. * Position-Color-Texture signatures
  468. */
  469. /**
  470. * @brief Class implementing PCT (position-color-texture) signature extraction
  471. * as described in @cite KrulisLS16.
  472. * The algorithm is divided to a feature sampler and a clusterizer.
  473. * Feature sampler produces samples at given set of coordinates.
  474. * Clusterizer then produces clusters of these samples using k-means algorithm.
  475. * Resulting set of clusters is the signature of the input image.
  476. *
  477. * A signature is an array of SIGNATURE_DIMENSION-dimensional points.
  478. * Used dimensions are:
  479. * weight, x, y position; lab color, contrast, entropy.
  480. * @cite KrulisLS16
  481. * @cite BeecksUS10
  482. */
  483. class CV_EXPORTS_W PCTSignatures : public Algorithm
  484. {
  485. public:
  486. /**
  487. * @brief Lp distance function selector.
  488. */
  489. enum DistanceFunction
  490. {
  491. L0_25, L0_5, L1, L2, L2SQUARED, L5, L_INFINITY
  492. };
  493. /**
  494. * @brief Point distributions supported by random point generator.
  495. */
  496. enum PointDistribution
  497. {
  498. UNIFORM, //!< Generate numbers uniformly.
  499. REGULAR, //!< Generate points in a regular grid.
  500. NORMAL //!< Generate points with normal (gaussian) distribution.
  501. };
  502. /**
  503. * @brief Similarity function selector.
  504. * @see
  505. * Christian Beecks, Merih Seran Uysal, Thomas Seidl.
  506. * Signature quadratic form distance.
  507. * In Proceedings of the ACM International Conference on Image and Video Retrieval, pages 438-445.
  508. * ACM, 2010.
  509. * @cite BeecksUS10
  510. * @note For selected distance function: \f[ d(c_i, c_j) \f] and parameter: \f[ \alpha \f]
  511. */
  512. enum SimilarityFunction
  513. {
  514. MINUS, //!< \f[ -d(c_i, c_j) \f]
  515. GAUSSIAN, //!< \f[ e^{ -\alpha * d^2(c_i, c_j)} \f]
  516. HEURISTIC //!< \f[ \frac{1}{\alpha + d(c_i, c_j)} \f]
  517. };
  518. /**
  519. * @brief Creates PCTSignatures algorithm using sample and seed count.
  520. * It generates its own sets of sampling points and clusterization seed indexes.
  521. * @param initSampleCount Number of points used for image sampling.
  522. * @param initSeedCount Number of initial clusterization seeds.
  523. * Must be lower or equal to initSampleCount
  524. * @param pointDistribution Distribution of generated points. Default: UNIFORM.
  525. * Available: UNIFORM, REGULAR, NORMAL.
  526. * @return Created algorithm.
  527. */
  528. CV_WRAP static Ptr<PCTSignatures> create(
  529. const int initSampleCount = 2000,
  530. const int initSeedCount = 400,
  531. const int pointDistribution = 0);
  532. /**
  533. * @brief Creates PCTSignatures algorithm using pre-generated sampling points
  534. * and number of clusterization seeds. It uses the provided
  535. * sampling points and generates its own clusterization seed indexes.
  536. * @param initSamplingPoints Sampling points used in image sampling.
  537. * @param initSeedCount Number of initial clusterization seeds.
  538. * Must be lower or equal to initSamplingPoints.size().
  539. * @return Created algorithm.
  540. */
  541. CV_WRAP static Ptr<PCTSignatures> create(
  542. const std::vector<Point2f>& initSamplingPoints,
  543. const int initSeedCount);
  544. /**
  545. * @brief Creates PCTSignatures algorithm using pre-generated sampling points
  546. * and clusterization seeds indexes.
  547. * @param initSamplingPoints Sampling points used in image sampling.
  548. * @param initClusterSeedIndexes Indexes of initial clusterization seeds.
  549. * Its size must be lower or equal to initSamplingPoints.size().
  550. * @return Created algorithm.
  551. */
  552. CV_WRAP static Ptr<PCTSignatures> create(
  553. const std::vector<Point2f>& initSamplingPoints,
  554. const std::vector<int>& initClusterSeedIndexes);
  555. /**
  556. * @brief Computes signature of given image.
  557. * @param image Input image of CV_8U type.
  558. * @param signature Output computed signature.
  559. */
  560. CV_WRAP virtual void computeSignature(
  561. InputArray image,
  562. OutputArray signature) const = 0;
  563. /**
  564. * @brief Computes signatures for multiple images in parallel.
  565. * @param images Vector of input images of CV_8U type.
  566. * @param signatures Vector of computed signatures.
  567. */
  568. CV_WRAP virtual void computeSignatures(
  569. const std::vector<Mat>& images,
  570. std::vector<Mat>& signatures) const = 0;
  571. /**
  572. * @brief Draws signature in the source image and outputs the result.
  573. * Signatures are visualized as a circle
  574. * with radius based on signature weight
  575. * and color based on signature color.
  576. * Contrast and entropy are not visualized.
  577. * @param source Source image.
  578. * @param signature Image signature.
  579. * @param result Output result.
  580. * @param radiusToShorterSideRatio Determines maximal radius of signature in the output image.
  581. * @param borderThickness Border thickness of the visualized signature.
  582. */
  583. CV_WRAP static void drawSignature(
  584. InputArray source,
  585. InputArray signature,
  586. OutputArray result,
  587. float radiusToShorterSideRatio = 1.0 / 8,
  588. int borderThickness = 1);
  589. /**
  590. * @brief Generates initial sampling points according to selected point distribution.
  591. * @param initPoints Output vector where the generated points will be saved.
  592. * @param count Number of points to generate.
  593. * @param pointDistribution Point distribution selector.
  594. * Available: UNIFORM, REGULAR, NORMAL.
  595. * @note Generated coordinates are in range [0..1)
  596. */
  597. CV_WRAP static void generateInitPoints(
  598. std::vector<Point2f>& initPoints,
  599. const int count,
  600. int pointDistribution);
  601. /**** sampler ****/
  602. /**
  603. * @brief Number of initial samples taken from the image.
  604. */
  605. CV_WRAP virtual int getSampleCount() const = 0;
  606. /**
  607. * @brief Color resolution of the greyscale bitmap represented in allocated bits
  608. * (i.e., value 4 means that 16 shades of grey are used).
  609. * The greyscale bitmap is used for computing contrast and entropy values.
  610. */
  611. CV_WRAP virtual int getGrayscaleBits() const = 0;
  612. /**
  613. * @brief Color resolution of the greyscale bitmap represented in allocated bits
  614. * (i.e., value 4 means that 16 shades of grey are used).
  615. * The greyscale bitmap is used for computing contrast and entropy values.
  616. */
  617. CV_WRAP virtual void setGrayscaleBits(int grayscaleBits) = 0;
  618. /**
  619. * @brief Size of the texture sampling window used to compute contrast and entropy
  620. * (center of the window is always in the pixel selected by x,y coordinates
  621. * of the corresponding feature sample).
  622. */
  623. CV_WRAP virtual int getWindowRadius() const = 0;
  624. /**
  625. * @brief Size of the texture sampling window used to compute contrast and entropy
  626. * (center of the window is always in the pixel selected by x,y coordinates
  627. * of the corresponding feature sample).
  628. */
  629. CV_WRAP virtual void setWindowRadius(int radius) = 0;
  630. /**
  631. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  632. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  633. */
  634. CV_WRAP virtual float getWeightX() const = 0;
  635. /**
  636. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  637. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  638. */
  639. CV_WRAP virtual void setWeightX(float weight) = 0;
  640. /**
  641. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  642. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  643. */
  644. CV_WRAP virtual float getWeightY() const = 0;
  645. /**
  646. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  647. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  648. */
  649. CV_WRAP virtual void setWeightY(float weight) = 0;
  650. /**
  651. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  652. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  653. */
  654. CV_WRAP virtual float getWeightL() const = 0;
  655. /**
  656. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  657. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  658. */
  659. CV_WRAP virtual void setWeightL(float weight) = 0;
  660. /**
  661. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  662. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  663. */
  664. CV_WRAP virtual float getWeightA() const = 0;
  665. /**
  666. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  667. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  668. */
  669. CV_WRAP virtual void setWeightA(float weight) = 0;
  670. /**
  671. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  672. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  673. */
  674. CV_WRAP virtual float getWeightB() const = 0;
  675. /**
  676. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  677. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  678. */
  679. CV_WRAP virtual void setWeightB(float weight) = 0;
  680. /**
  681. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  682. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  683. */
  684. CV_WRAP virtual float getWeightContrast() const = 0;
  685. /**
  686. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  687. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  688. */
  689. CV_WRAP virtual void setWeightContrast(float weight) = 0;
  690. /**
  691. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  692. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  693. */
  694. CV_WRAP virtual float getWeightEntropy() const = 0;
  695. /**
  696. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space
  697. * (x,y = position; L,a,b = color in CIE Lab space; c = contrast. e = entropy)
  698. */
  699. CV_WRAP virtual void setWeightEntropy(float weight) = 0;
  700. /**
  701. * @brief Initial samples taken from the image.
  702. * These sampled features become the input for clustering.
  703. */
  704. CV_WRAP virtual std::vector<Point2f> getSamplingPoints() const = 0;
  705. /**
  706. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space.
  707. * @param idx ID of the weight
  708. * @param value Value of the weight
  709. * @note
  710. * WEIGHT_IDX = 0;
  711. * X_IDX = 1;
  712. * Y_IDX = 2;
  713. * L_IDX = 3;
  714. * A_IDX = 4;
  715. * B_IDX = 5;
  716. * CONTRAST_IDX = 6;
  717. * ENTROPY_IDX = 7;
  718. */
  719. CV_WRAP virtual void setWeight(int idx, float value) = 0;
  720. /**
  721. * @brief Weights (multiplicative constants) that linearly stretch individual axes of the feature space.
  722. * @param weights Values of all weights.
  723. * @note
  724. * WEIGHT_IDX = 0;
  725. * X_IDX = 1;
  726. * Y_IDX = 2;
  727. * L_IDX = 3;
  728. * A_IDX = 4;
  729. * B_IDX = 5;
  730. * CONTRAST_IDX = 6;
  731. * ENTROPY_IDX = 7;
  732. */
  733. CV_WRAP virtual void setWeights(const std::vector<float>& weights) = 0;
  734. /**
  735. * @brief Translations of the individual axes of the feature space.
  736. * @param idx ID of the translation
  737. * @param value Value of the translation
  738. * @note
  739. * WEIGHT_IDX = 0;
  740. * X_IDX = 1;
  741. * Y_IDX = 2;
  742. * L_IDX = 3;
  743. * A_IDX = 4;
  744. * B_IDX = 5;
  745. * CONTRAST_IDX = 6;
  746. * ENTROPY_IDX = 7;
  747. */
  748. CV_WRAP virtual void setTranslation(int idx, float value) = 0;
  749. /**
  750. * @brief Translations of the individual axes of the feature space.
  751. * @param translations Values of all translations.
  752. * @note
  753. * WEIGHT_IDX = 0;
  754. * X_IDX = 1;
  755. * Y_IDX = 2;
  756. * L_IDX = 3;
  757. * A_IDX = 4;
  758. * B_IDX = 5;
  759. * CONTRAST_IDX = 6;
  760. * ENTROPY_IDX = 7;
  761. */
  762. CV_WRAP virtual void setTranslations(const std::vector<float>& translations) = 0;
  763. /**
  764. * @brief Sets sampling points used to sample the input image.
  765. * @param samplingPoints Vector of sampling points in range [0..1)
  766. * @note Number of sampling points must be greater or equal to clusterization seed count.
  767. */
  768. CV_WRAP virtual void setSamplingPoints(std::vector<Point2f> samplingPoints) = 0;
  769. /**** clusterizer ****/
  770. /**
  771. * @brief Initial seeds (initial number of clusters) for the k-means algorithm.
  772. */
  773. CV_WRAP virtual std::vector<int> getInitSeedIndexes() const = 0;
  774. /**
  775. * @brief Initial seed indexes for the k-means algorithm.
  776. */
  777. CV_WRAP virtual void setInitSeedIndexes(std::vector<int> initSeedIndexes) = 0;
  778. /**
  779. * @brief Number of initial seeds (initial number of clusters) for the k-means algorithm.
  780. */
  781. CV_WRAP virtual int getInitSeedCount() const = 0;
  782. /**
  783. * @brief Number of iterations of the k-means clustering.
  784. * We use fixed number of iterations, since the modified clustering is pruning clusters
  785. * (not iteratively refining k clusters).
  786. */
  787. CV_WRAP virtual int getIterationCount() const = 0;
  788. /**
  789. * @brief Number of iterations of the k-means clustering.
  790. * We use fixed number of iterations, since the modified clustering is pruning clusters
  791. * (not iteratively refining k clusters).
  792. */
  793. CV_WRAP virtual void setIterationCount(int iterationCount) = 0;
  794. /**
  795. * @brief Maximal number of generated clusters. If the number is exceeded,
  796. * the clusters are sorted by their weights and the smallest clusters are cropped.
  797. */
  798. CV_WRAP virtual int getMaxClustersCount() const = 0;
  799. /**
  800. * @brief Maximal number of generated clusters. If the number is exceeded,
  801. * the clusters are sorted by their weights and the smallest clusters are cropped.
  802. */
  803. CV_WRAP virtual void setMaxClustersCount(int maxClustersCount) = 0;
  804. /**
  805. * @brief This parameter multiplied by the index of iteration gives lower limit for cluster size.
  806. * Clusters containing fewer points than specified by the limit have their centroid dismissed
  807. * and points are reassigned.
  808. */
  809. CV_WRAP virtual int getClusterMinSize() const = 0;
  810. /**
  811. * @brief This parameter multiplied by the index of iteration gives lower limit for cluster size.
  812. * Clusters containing fewer points than specified by the limit have their centroid dismissed
  813. * and points are reassigned.
  814. */
  815. CV_WRAP virtual void setClusterMinSize(int clusterMinSize) = 0;
  816. /**
  817. * @brief Threshold euclidean distance between two centroids.
  818. * If two cluster centers are closer than this distance,
  819. * one of the centroid is dismissed and points are reassigned.
  820. */
  821. CV_WRAP virtual float getJoiningDistance() const = 0;
  822. /**
  823. * @brief Threshold euclidean distance between two centroids.
  824. * If two cluster centers are closer than this distance,
  825. * one of the centroid is dismissed and points are reassigned.
  826. */
  827. CV_WRAP virtual void setJoiningDistance(float joiningDistance) = 0;
  828. /**
  829. * @brief Remove centroids in k-means whose weight is lesser or equal to given threshold.
  830. */
  831. CV_WRAP virtual float getDropThreshold() const = 0;
  832. /**
  833. * @brief Remove centroids in k-means whose weight is lesser or equal to given threshold.
  834. */
  835. CV_WRAP virtual void setDropThreshold(float dropThreshold) = 0;
  836. /**
  837. * @brief Distance function selector used for measuring distance between two points in k-means.
  838. */
  839. CV_WRAP virtual int getDistanceFunction() const = 0;
  840. /**
  841. * @brief Distance function selector used for measuring distance between two points in k-means.
  842. * Available: L0_25, L0_5, L1, L2, L2SQUARED, L5, L_INFINITY.
  843. */
  844. CV_WRAP virtual void setDistanceFunction(int distanceFunction) = 0;
  845. };
  846. /**
  847. * @brief Class implementing Signature Quadratic Form Distance (SQFD).
  848. * @see Christian Beecks, Merih Seran Uysal, Thomas Seidl.
  849. * Signature quadratic form distance.
  850. * In Proceedings of the ACM International Conference on Image and Video Retrieval, pages 438-445.
  851. * ACM, 2010.
  852. * @cite BeecksUS10
  853. */
  854. class CV_EXPORTS_W PCTSignaturesSQFD : public Algorithm
  855. {
  856. public:
  857. /**
  858. * @brief Creates the algorithm instance using selected distance function,
  859. * similarity function and similarity function parameter.
  860. * @param distanceFunction Distance function selector. Default: L2
  861. * Available: L0_25, L0_5, L1, L2, L2SQUARED, L5, L_INFINITY
  862. * @param similarityFunction Similarity function selector. Default: HEURISTIC
  863. * Available: MINUS, GAUSSIAN, HEURISTIC
  864. * @param similarityParameter Parameter of the similarity function.
  865. */
  866. CV_WRAP static Ptr<PCTSignaturesSQFD> create(
  867. const int distanceFunction = 3,
  868. const int similarityFunction = 2,
  869. const float similarityParameter = 1.0f);
  870. /**
  871. * @brief Computes Signature Quadratic Form Distance of two signatures.
  872. * @param _signature0 The first signature.
  873. * @param _signature1 The second signature.
  874. */
  875. CV_WRAP virtual float computeQuadraticFormDistance(
  876. InputArray _signature0,
  877. InputArray _signature1) const = 0;
  878. /**
  879. * @brief Computes Signature Quadratic Form Distance between the reference signature
  880. * and each of the other image signatures.
  881. * @param sourceSignature The signature to measure distance of other signatures from.
  882. * @param imageSignatures Vector of signatures to measure distance from the source signature.
  883. * @param distances Output vector of measured distances.
  884. */
  885. CV_WRAP virtual void computeQuadraticFormDistances(
  886. const Mat& sourceSignature,
  887. const std::vector<Mat>& imageSignatures,
  888. std::vector<float>& distances) const = 0;
  889. };
  890. /**
  891. * @brief Elliptic region around an interest point.
  892. */
  893. class CV_EXPORTS Elliptic_KeyPoint : public KeyPoint
  894. {
  895. public:
  896. Size_<float> axes; //!< the lengths of the major and minor ellipse axes
  897. float si; //!< the integration scale at which the parameters were estimated
  898. Matx23f transf; //!< the transformation between image space and local patch space
  899. Elliptic_KeyPoint();
  900. Elliptic_KeyPoint(Point2f pt, float angle, Size axes, float size, float si);
  901. virtual ~Elliptic_KeyPoint();
  902. };
  903. /**
  904. * @brief Class implementing the Harris-Laplace feature detector as described in @cite Mikolajczyk2004.
  905. */
  906. class CV_EXPORTS_W HarrisLaplaceFeatureDetector : public Feature2D
  907. {
  908. public:
  909. /**
  910. * @brief Creates a new implementation instance.
  911. *
  912. * @param numOctaves the number of octaves in the scale-space pyramid
  913. * @param corn_thresh the threshold for the Harris cornerness measure
  914. * @param DOG_thresh the threshold for the Difference-of-Gaussians scale selection
  915. * @param maxCorners the maximum number of corners to consider
  916. * @param num_layers the number of intermediate scales per octave
  917. */
  918. CV_WRAP static Ptr<HarrisLaplaceFeatureDetector> create(
  919. int numOctaves=6,
  920. float corn_thresh=0.01f,
  921. float DOG_thresh=0.01f,
  922. int maxCorners=5000,
  923. int num_layers=4);
  924. CV_WRAP virtual void setNumOctaves(int numOctaves_) = 0;
  925. CV_WRAP virtual int getNumOctaves() const = 0;
  926. CV_WRAP virtual void setCornThresh(float corn_thresh_) = 0;
  927. CV_WRAP virtual float getCornThresh() const = 0;
  928. CV_WRAP virtual void setDOGThresh(float DOG_thresh_) = 0;
  929. CV_WRAP virtual float getDOGThresh() const = 0;
  930. CV_WRAP virtual void setMaxCorners(int maxCorners_) = 0;
  931. CV_WRAP virtual int getMaxCorners() const = 0;
  932. CV_WRAP virtual void setNumLayers(int num_layers_) = 0;
  933. CV_WRAP virtual int getNumLayers() const = 0;
  934. CV_WRAP String getDefaultName() const CV_OVERRIDE;
  935. };
  936. /**
  937. * @brief Class implementing affine adaptation for key points.
  938. *
  939. * A @ref FeatureDetector and a @ref DescriptorExtractor are wrapped to augment the
  940. * detected points with their affine invariant elliptic region and to compute
  941. * the feature descriptors on the regions after warping them into circles.
  942. *
  943. * The interface is equivalent to @ref Feature2D, adding operations for
  944. * @ref Elliptic_KeyPoint "Elliptic_KeyPoints" instead of @ref KeyPoint "KeyPoints".
  945. */
  946. class CV_EXPORTS_W AffineFeature2D : public Feature2D
  947. {
  948. public:
  949. /**
  950. * @brief Creates an instance wrapping the given keypoint detector and
  951. * descriptor extractor.
  952. */
  953. static Ptr<AffineFeature2D> create(
  954. Ptr<FeatureDetector> keypoint_detector,
  955. Ptr<DescriptorExtractor> descriptor_extractor);
  956. /**
  957. * @brief Creates an instance where keypoint detector and descriptor
  958. * extractor are identical.
  959. */
  960. static Ptr<AffineFeature2D> create(
  961. Ptr<FeatureDetector> keypoint_detector)
  962. {
  963. return create(keypoint_detector, keypoint_detector);
  964. }
  965. using Feature2D::detect; // overload, don't hide
  966. /**
  967. * @brief Detects keypoints in the image using the wrapped detector and
  968. * performs affine adaptation to augment them with their elliptic regions.
  969. */
  970. virtual void detect(
  971. InputArray image,
  972. CV_OUT std::vector<Elliptic_KeyPoint>& keypoints,
  973. InputArray mask=noArray() ) = 0;
  974. using Feature2D::detectAndCompute; // overload, don't hide
  975. /**
  976. * @brief Detects keypoints and computes descriptors for their surrounding
  977. * regions, after warping them into circles.
  978. */
  979. virtual void detectAndCompute(
  980. InputArray image,
  981. InputArray mask,
  982. CV_OUT std::vector<Elliptic_KeyPoint>& keypoints,
  983. OutputArray descriptors,
  984. bool useProvidedKeypoints=false ) = 0;
  985. };
  986. /**
  987. @brief Class implementing the Tree Based Morse Regions (TBMR) as described in
  988. @cite Najman2014 extended with scaled extraction ability.
  989. @param min_area prune areas smaller than minArea
  990. @param max_area_relative prune areas bigger than maxArea = max_area_relative *
  991. input_image_size
  992. @param scale_factor scale factor for scaled extraction.
  993. @param n_scales number of applications of the scale factor (octaves).
  994. @note This algorithm is based on Component Tree (Min/Max) as well as MSER but
  995. uses a Morse-theory approach to extract features.
  996. Features are ellipses (similar to MSER, however a MSER feature can never be a
  997. TBMR feature and vice versa).
  998. */
  999. class CV_EXPORTS_W TBMR : public AffineFeature2D
  1000. {
  1001. public:
  1002. CV_WRAP static Ptr<TBMR> create(int min_area = 60,
  1003. float max_area_relative = 0.01f,
  1004. float scale_factor = 1.25f,
  1005. int n_scales = -1);
  1006. CV_WRAP virtual void setMinArea(int minArea) = 0;
  1007. CV_WRAP virtual int getMinArea() const = 0;
  1008. CV_WRAP virtual void setMaxAreaRelative(float maxArea) = 0;
  1009. CV_WRAP virtual float getMaxAreaRelative() const = 0;
  1010. CV_WRAP virtual void setScaleFactor(float scale_factor) = 0;
  1011. CV_WRAP virtual float getScaleFactor() const = 0;
  1012. CV_WRAP virtual void setNScales(int n_scales) = 0;
  1013. CV_WRAP virtual int getNScales() const = 0;
  1014. };
  1015. /** @brief Estimates cornerness for prespecified KeyPoints using the FAST algorithm
  1016. @param image grayscale image where keypoints (corners) are detected.
  1017. @param keypoints keypoints which should be tested to fit the FAST criteria. Keypoints not being
  1018. detected as corners are removed.
  1019. @param threshold threshold on difference between intensity of the central pixel and pixels of a
  1020. circle around this pixel.
  1021. @param nonmaxSuppression if true, non-maximum suppression is applied to detected corners
  1022. (keypoints).
  1023. @param type one of the three neighborhoods as defined in the paper:
  1024. FastFeatureDetector::TYPE_9_16, FastFeatureDetector::TYPE_7_12,
  1025. FastFeatureDetector::TYPE_5_8
  1026. Detects corners using the FAST algorithm by @cite Rosten06 .
  1027. */
  1028. CV_EXPORTS void FASTForPointSet( InputArray image, CV_IN_OUT std::vector<KeyPoint>& keypoints,
  1029. int threshold, bool nonmaxSuppression=true, cv::FastFeatureDetector::DetectorType type=FastFeatureDetector::TYPE_9_16);
  1030. //! @}
  1031. //! @addtogroup xfeatures2d_match
  1032. //! @{
  1033. /** @brief GMS (Grid-based Motion Statistics) feature matching strategy described in @cite Bian2017gms .
  1034. @param size1 Input size of image1.
  1035. @param size2 Input size of image2.
  1036. @param keypoints1 Input keypoints of image1.
  1037. @param keypoints2 Input keypoints of image2.
  1038. @param matches1to2 Input 1-nearest neighbor matches.
  1039. @param matchesGMS Matches returned by the GMS matching strategy.
  1040. @param withRotation Take rotation transformation into account.
  1041. @param withScale Take scale transformation into account.
  1042. @param thresholdFactor The higher, the less matches.
  1043. @note
  1044. 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.
  1045. If matching results are not satisfying, please add more features. (We use 10000 for images with 640 X 480).
  1046. If your images have big rotation and scale changes, please set withRotation or withScale to true.
  1047. */
  1048. CV_EXPORTS_W void matchGMS(const Size& size1, const Size& size2, const std::vector<KeyPoint>& keypoints1, const std::vector<KeyPoint>& keypoints2,
  1049. const std::vector<DMatch>& matches1to2, CV_OUT std::vector<DMatch>& matchesGMS, const bool withRotation = false,
  1050. const bool withScale = false, const double thresholdFactor = 6.0);
  1051. /** @brief LOGOS (Local geometric support for high-outlier spatial verification) feature matching strategy described in @cite Lowry2018LOGOSLG .
  1052. @param keypoints1 Input keypoints of image1.
  1053. @param keypoints2 Input keypoints of image2.
  1054. @param nn1 Index to the closest BoW centroid for each descriptors of image1.
  1055. @param nn2 Index to the closest BoW centroid for each descriptors of image2.
  1056. @param matches1to2 Matches returned by the LOGOS matching strategy.
  1057. @note
  1058. This matching strategy is suitable for features matching against large scale database.
  1059. First step consists in constructing the bag-of-words (BoW) from a representative image database.
  1060. Image descriptors are then represented by their closest codevector (nearest BoW centroid).
  1061. */
  1062. CV_EXPORTS_W void matchLOGOS(const std::vector<KeyPoint>& keypoints1, const std::vector<KeyPoint>& keypoints2,
  1063. const std::vector<int>& nn1, const std::vector<int>& nn2,
  1064. std::vector<DMatch>& matches1to2);
  1065. //! @}
  1066. }
  1067. }
  1068. #endif