BoostDesc.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  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 BoostDesc
  10. /**
  11. * Class implementing BoostDesc (Learning Image Descriptors with Boosting), described in
  12. * CITE: Trzcinski13a and CITE: Trzcinski13b.
  13. *
  14. * desc type of descriptor to use, BoostDesc::BINBOOST_256 is default (256 bit long dimension)
  15. * Available types are: BoostDesc::BGM, BoostDesc::BGM_HARD, BoostDesc::BGM_BILINEAR, BoostDesc::LBGM,
  16. * BoostDesc::BINBOOST_64, BoostDesc::BINBOOST_128, BoostDesc::BINBOOST_256
  17. * use_orientation sample patterns using keypoints orientation, enabled by default
  18. * scale_factor adjust the sampling window of detected keypoints
  19. * 6.25f is default and fits for KAZE, SURF detected keypoints window ratio
  20. * 6.75f should be the scale for SIFT detected keypoints window ratio
  21. * 5.00f should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints window ratio
  22. * 0.75f should be the scale for ORB keypoints ratio
  23. * 1.50f was the default in original implementation
  24. *
  25. * <b>Note:</b> BGM is the base descriptor where each binary dimension is computed as the output of a single weak learner.
  26. * BGM_HARD and BGM_BILINEAR refers to same BGM but use different type of gradient binning. In the BGM_HARD that
  27. * use ASSIGN_HARD binning type the gradient is assigned to the nearest orientation bin. In the BGM_BILINEAR that use
  28. * ASSIGN_BILINEAR binning type the gradient is assigned to the two neighbouring bins. In the BGM and all other modes that use
  29. * ASSIGN_SOFT binning type the gradient is assigned to 8 nearest bins according to the cosine value between the gradient
  30. * angle and the bin center. LBGM (alias FP-Boost) is the floating point extension where each dimension is computed
  31. * as a linear combination of the weak learner responses. BINBOOST and subvariants are the binary extensions of LBGM
  32. * where each bit is computed as a thresholded linear combination of a set of weak learners.
  33. * BoostDesc header files (boostdesc_*.i) was exported from original binaries with export-boostdesc.py script from
  34. * samples subfolder.
  35. */
  36. public class BoostDesc : Feature2D
  37. {
  38. protected override void Dispose(bool disposing)
  39. {
  40. try
  41. {
  42. if (disposing)
  43. {
  44. }
  45. if (IsEnabledDispose)
  46. {
  47. if (nativeObj != IntPtr.Zero)
  48. xfeatures2d_BoostDesc_delete(nativeObj);
  49. nativeObj = IntPtr.Zero;
  50. }
  51. }
  52. finally
  53. {
  54. base.Dispose(disposing);
  55. }
  56. }
  57. protected internal BoostDesc(IntPtr addr) : base(addr) { }
  58. // internal usage only
  59. public static new BoostDesc __fromPtr__(IntPtr addr) { return new BoostDesc(addr); }
  60. //
  61. // C++: static Ptr_BoostDesc cv::xfeatures2d::BoostDesc::create(int desc = BoostDesc::BINBOOST_256, bool use_scale_orientation = true, float scale_factor = 6.25f)
  62. //
  63. public static BoostDesc create(int desc, bool use_scale_orientation, float scale_factor)
  64. {
  65. return BoostDesc.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BoostDesc_create_10(desc, use_scale_orientation, scale_factor)));
  66. }
  67. public static BoostDesc create(int desc, bool use_scale_orientation)
  68. {
  69. return BoostDesc.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BoostDesc_create_11(desc, use_scale_orientation)));
  70. }
  71. public static BoostDesc create(int desc)
  72. {
  73. return BoostDesc.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BoostDesc_create_12(desc)));
  74. }
  75. public static BoostDesc create()
  76. {
  77. return BoostDesc.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BoostDesc_create_13()));
  78. }
  79. //
  80. // C++: String cv::xfeatures2d::BoostDesc::getDefaultName()
  81. //
  82. public override string getDefaultName()
  83. {
  84. ThrowIfDisposed();
  85. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_BoostDesc_getDefaultName_10(nativeObj)));
  86. return retVal;
  87. }
  88. //
  89. // C++: void cv::xfeatures2d::BoostDesc::setUseScaleOrientation(bool use_scale_orientation)
  90. //
  91. public void setUseScaleOrientation(bool use_scale_orientation)
  92. {
  93. ThrowIfDisposed();
  94. xfeatures2d_BoostDesc_setUseScaleOrientation_10(nativeObj, use_scale_orientation);
  95. }
  96. //
  97. // C++: bool cv::xfeatures2d::BoostDesc::getUseScaleOrientation()
  98. //
  99. public bool getUseScaleOrientation()
  100. {
  101. ThrowIfDisposed();
  102. return xfeatures2d_BoostDesc_getUseScaleOrientation_10(nativeObj);
  103. }
  104. //
  105. // C++: void cv::xfeatures2d::BoostDesc::setScaleFactor(float scale_factor)
  106. //
  107. public void setScaleFactor(float scale_factor)
  108. {
  109. ThrowIfDisposed();
  110. xfeatures2d_BoostDesc_setScaleFactor_10(nativeObj, scale_factor);
  111. }
  112. //
  113. // C++: float cv::xfeatures2d::BoostDesc::getScaleFactor()
  114. //
  115. public float getScaleFactor()
  116. {
  117. ThrowIfDisposed();
  118. return xfeatures2d_BoostDesc_getScaleFactor_10(nativeObj);
  119. }
  120. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  121. const string LIBNAME = "__Internal";
  122. #else
  123. const string LIBNAME = "opencvforunity";
  124. #endif
  125. // C++: static Ptr_BoostDesc cv::xfeatures2d::BoostDesc::create(int desc = BoostDesc::BINBOOST_256, bool use_scale_orientation = true, float scale_factor = 6.25f)
  126. [DllImport(LIBNAME)]
  127. private static extern IntPtr xfeatures2d_BoostDesc_create_10(int desc, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation, float scale_factor);
  128. [DllImport(LIBNAME)]
  129. private static extern IntPtr xfeatures2d_BoostDesc_create_11(int desc, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation);
  130. [DllImport(LIBNAME)]
  131. private static extern IntPtr xfeatures2d_BoostDesc_create_12(int desc);
  132. [DllImport(LIBNAME)]
  133. private static extern IntPtr xfeatures2d_BoostDesc_create_13();
  134. // C++: String cv::xfeatures2d::BoostDesc::getDefaultName()
  135. [DllImport(LIBNAME)]
  136. private static extern IntPtr xfeatures2d_BoostDesc_getDefaultName_10(IntPtr nativeObj);
  137. // C++: void cv::xfeatures2d::BoostDesc::setUseScaleOrientation(bool use_scale_orientation)
  138. [DllImport(LIBNAME)]
  139. private static extern void xfeatures2d_BoostDesc_setUseScaleOrientation_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation);
  140. // C++: bool cv::xfeatures2d::BoostDesc::getUseScaleOrientation()
  141. [DllImport(LIBNAME)]
  142. [return: MarshalAs(UnmanagedType.U1)]
  143. private static extern bool xfeatures2d_BoostDesc_getUseScaleOrientation_10(IntPtr nativeObj);
  144. // C++: void cv::xfeatures2d::BoostDesc::setScaleFactor(float scale_factor)
  145. [DllImport(LIBNAME)]
  146. private static extern void xfeatures2d_BoostDesc_setScaleFactor_10(IntPtr nativeObj, float scale_factor);
  147. // C++: float cv::xfeatures2d::BoostDesc::getScaleFactor()
  148. [DllImport(LIBNAME)]
  149. private static extern float xfeatures2d_BoostDesc_getScaleFactor_10(IntPtr nativeObj);
  150. // native support for java finalize()
  151. [DllImport(LIBNAME)]
  152. private static extern void xfeatures2d_BoostDesc_delete(IntPtr nativeObj);
  153. }
  154. }