xfeatures2d.hpp 41 KB

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