BEBLID.cs 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.Features2dModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.Xfeatures2dModule
  8. {
  9. // C++: class BEBLID
  10. /**
  11. * Class implementing BEBLID (Boosted Efficient Binary Local Image Descriptor),
  12. * described in CITE: Suarez2020BEBLID .
  13. *
  14. * BEBLID \cite Suarez2020BEBLID is a efficient binary descriptor learned with boosting.
  15. * It is able to describe keypoints from any detector just by changing the scale_factor parameter.
  16. * In several benchmarks it has proved to largely improve other binary descriptors like ORB or
  17. * BRISK with the same efficiency. BEBLID describes using the difference of mean gray values in
  18. * different regions of the image around the KeyPoint, the descriptor is specifically optimized for
  19. * image matching and patch retrieval addressing the asymmetries of these problems.
  20. *
  21. * If you find this code useful, please add a reference to the following paper:
  22. * <BLOCKQUOTE> Iago Suárez, Ghesn Sfeir, José M. Buenaposada, and Luis Baumela.
  23. * BEBLID: Boosted efficient binary local image descriptor.
  24. * Pattern Recognition Letters, 133:366–372, 2020. </BLOCKQUOTE>
  25. *
  26. * The descriptor was trained using 1 million of randomly sampled pairs of patches
  27. * (20% positives and 80% negatives) from the Liberty split of the UBC datasets
  28. * \cite winder2007learning as described in the paper CITE: Suarez2020BEBLID.
  29. * You can check in the [AKAZE example](https://raw.githubusercontent.com/opencv/opencv/master/samples/cpp/tutorial_code/features2D/AKAZE_match.cpp)
  30. * how well BEBLID works. Detecting 10000 keypoints with ORB and describing with BEBLID obtains
  31. * 561 inliers (75%) whereas describing with ORB obtains only 493 inliers (63%).
  32. */
  33. public class BEBLID : Feature2D
  34. {
  35. protected override void Dispose(bool disposing)
  36. {
  37. try
  38. {
  39. if (disposing)
  40. {
  41. }
  42. if (IsEnabledDispose)
  43. {
  44. if (nativeObj != IntPtr.Zero)
  45. xfeatures2d_BEBLID_delete(nativeObj);
  46. nativeObj = IntPtr.Zero;
  47. }
  48. }
  49. finally
  50. {
  51. base.Dispose(disposing);
  52. }
  53. }
  54. protected internal BEBLID(IntPtr addr) : base(addr) { }
  55. // internal usage only
  56. public static new BEBLID __fromPtr__(IntPtr addr) { return new BEBLID(addr); }
  57. // C++: enum cv.xfeatures2d.BEBLID.BeblidSize
  58. public const int SIZE_512_BITS = 100;
  59. public const int SIZE_256_BITS = 101;
  60. //
  61. // C++: static Ptr_BEBLID cv::xfeatures2d::BEBLID::create(float scale_factor, int n_bits = BEBLID::SIZE_512_BITS)
  62. //
  63. /**
  64. * Creates the BEBLID descriptor.
  65. * param scale_factor Adjust the sampling window around detected keypoints:
  66. * <ul>
  67. * <li>
  68. * &lt;b&gt; 1.00f &lt;/b&gt; should be the scale for ORB keypoints
  69. * </li>
  70. * <li>
  71. * &lt;b&gt; 6.75f &lt;/b&gt; should be the scale for SIFT detected keypoints
  72. * </li>
  73. * <li>
  74. * &lt;b&gt; 6.25f &lt;/b&gt; is default and fits for KAZE, SURF detected keypoints
  75. * </li>
  76. * <li>
  77. * &lt;b&gt; 5.00f &lt;/b&gt; should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
  78. * </li>
  79. * </ul>
  80. * param n_bits Determine the number of bits in the descriptor. Should be either
  81. * BEBLID::SIZE_512_BITS or BEBLID::SIZE_256_BITS.
  82. * return automatically generated
  83. */
  84. public static BEBLID create(float scale_factor, int n_bits)
  85. {
  86. return BEBLID.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BEBLID_create_10(scale_factor, n_bits)));
  87. }
  88. /**
  89. * Creates the BEBLID descriptor.
  90. * param scale_factor Adjust the sampling window around detected keypoints:
  91. * <ul>
  92. * <li>
  93. * &lt;b&gt; 1.00f &lt;/b&gt; should be the scale for ORB keypoints
  94. * </li>
  95. * <li>
  96. * &lt;b&gt; 6.75f &lt;/b&gt; should be the scale for SIFT detected keypoints
  97. * </li>
  98. * <li>
  99. * &lt;b&gt; 6.25f &lt;/b&gt; is default and fits for KAZE, SURF detected keypoints
  100. * </li>
  101. * <li>
  102. * &lt;b&gt; 5.00f &lt;/b&gt; should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints
  103. * </li>
  104. * </ul>
  105. * BEBLID::SIZE_512_BITS or BEBLID::SIZE_256_BITS.
  106. * return automatically generated
  107. */
  108. public static BEBLID create(float scale_factor)
  109. {
  110. return BEBLID.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BEBLID_create_11(scale_factor)));
  111. }
  112. //
  113. // C++: void cv::xfeatures2d::BEBLID::setScaleFactor(float scale_factor)
  114. //
  115. public void setScaleFactor(float scale_factor)
  116. {
  117. ThrowIfDisposed();
  118. xfeatures2d_BEBLID_setScaleFactor_10(nativeObj, scale_factor);
  119. }
  120. //
  121. // C++: float cv::xfeatures2d::BEBLID::getScaleFactor()
  122. //
  123. public float getScaleFactor()
  124. {
  125. ThrowIfDisposed();
  126. return xfeatures2d_BEBLID_getScaleFactor_10(nativeObj);
  127. }
  128. //
  129. // C++: String cv::xfeatures2d::BEBLID::getDefaultName()
  130. //
  131. public override string getDefaultName()
  132. {
  133. ThrowIfDisposed();
  134. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BEBLID_getDefaultName_10(nativeObj)));
  135. return retVal;
  136. }
  137. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  138. const string LIBNAME = "__Internal";
  139. #else
  140. const string LIBNAME = "opencvforunity";
  141. #endif
  142. // C++: static Ptr_BEBLID cv::xfeatures2d::BEBLID::create(float scale_factor, int n_bits = BEBLID::SIZE_512_BITS)
  143. [DllImport(LIBNAME)]
  144. private static extern IntPtr xfeatures2d_BEBLID_create_10(float scale_factor, int n_bits);
  145. [DllImport(LIBNAME)]
  146. private static extern IntPtr xfeatures2d_BEBLID_create_11(float scale_factor);
  147. // C++: void cv::xfeatures2d::BEBLID::setScaleFactor(float scale_factor)
  148. [DllImport(LIBNAME)]
  149. private static extern void xfeatures2d_BEBLID_setScaleFactor_10(IntPtr nativeObj, float scale_factor);
  150. // C++: float cv::xfeatures2d::BEBLID::getScaleFactor()
  151. [DllImport(LIBNAME)]
  152. private static extern float xfeatures2d_BEBLID_getScaleFactor_10(IntPtr nativeObj);
  153. // C++: String cv::xfeatures2d::BEBLID::getDefaultName()
  154. [DllImport(LIBNAME)]
  155. private static extern IntPtr xfeatures2d_BEBLID_getDefaultName_10(IntPtr nativeObj);
  156. // native support for java finalize()
  157. [DllImport(LIBNAME)]
  158. private static extern void xfeatures2d_BEBLID_delete(IntPtr nativeObj);
  159. }
  160. }