TBMR.cs 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.Xfeatures2dModule
  7. {
  8. // C++: class TBMR
  9. /**
  10. * Class implementing the Tree Based Morse Regions (TBMR) as described in
  11. * CITE: Najman2014 extended with scaled extraction ability.
  12. *
  13. * min_area prune areas smaller than minArea
  14. * max_area_relative prune areas bigger than maxArea = max_area_relative *
  15. * input_image_size
  16. * scale_factor scale factor for scaled extraction.
  17. * n_scales number of applications of the scale factor (octaves).
  18. *
  19. * <b>Note:</b> This algorithm is based on Component Tree (Min/Max) as well as MSER but
  20. * uses a Morse-theory approach to extract features.
  21. *
  22. * Features are ellipses (similar to MSER, however a MSER feature can never be a
  23. * TBMR feature and vice versa).
  24. */
  25. public class TBMR : AffineFeature2D
  26. {
  27. protected override void Dispose(bool disposing)
  28. {
  29. try
  30. {
  31. if (disposing)
  32. {
  33. }
  34. if (IsEnabledDispose)
  35. {
  36. if (nativeObj != IntPtr.Zero)
  37. xfeatures2d_TBMR_delete(nativeObj);
  38. nativeObj = IntPtr.Zero;
  39. }
  40. }
  41. finally
  42. {
  43. base.Dispose(disposing);
  44. }
  45. }
  46. protected internal TBMR(IntPtr addr) : base(addr) { }
  47. // internal usage only
  48. public static new TBMR __fromPtr__(IntPtr addr) { return new TBMR(addr); }
  49. //
  50. // C++: static Ptr_TBMR cv::xfeatures2d::TBMR::create(int min_area = 60, float max_area_relative = 0.01f, float scale_factor = 1.25f, int n_scales = -1)
  51. //
  52. public static TBMR create(int min_area, float max_area_relative, float scale_factor, int n_scales)
  53. {
  54. return TBMR.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_TBMR_create_10(min_area, max_area_relative, scale_factor, n_scales)));
  55. }
  56. public static TBMR create(int min_area, float max_area_relative, float scale_factor)
  57. {
  58. return TBMR.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_TBMR_create_11(min_area, max_area_relative, scale_factor)));
  59. }
  60. public static TBMR create(int min_area, float max_area_relative)
  61. {
  62. return TBMR.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_TBMR_create_12(min_area, max_area_relative)));
  63. }
  64. public static TBMR create(int min_area)
  65. {
  66. return TBMR.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_TBMR_create_13(min_area)));
  67. }
  68. public static TBMR create()
  69. {
  70. return TBMR.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_TBMR_create_14()));
  71. }
  72. //
  73. // C++: void cv::xfeatures2d::TBMR::setMinArea(int minArea)
  74. //
  75. public void setMinArea(int minArea)
  76. {
  77. ThrowIfDisposed();
  78. xfeatures2d_TBMR_setMinArea_10(nativeObj, minArea);
  79. }
  80. //
  81. // C++: int cv::xfeatures2d::TBMR::getMinArea()
  82. //
  83. public int getMinArea()
  84. {
  85. ThrowIfDisposed();
  86. return xfeatures2d_TBMR_getMinArea_10(nativeObj);
  87. }
  88. //
  89. // C++: void cv::xfeatures2d::TBMR::setMaxAreaRelative(float maxArea)
  90. //
  91. public void setMaxAreaRelative(float maxArea)
  92. {
  93. ThrowIfDisposed();
  94. xfeatures2d_TBMR_setMaxAreaRelative_10(nativeObj, maxArea);
  95. }
  96. //
  97. // C++: float cv::xfeatures2d::TBMR::getMaxAreaRelative()
  98. //
  99. public float getMaxAreaRelative()
  100. {
  101. ThrowIfDisposed();
  102. return xfeatures2d_TBMR_getMaxAreaRelative_10(nativeObj);
  103. }
  104. //
  105. // C++: void cv::xfeatures2d::TBMR::setScaleFactor(float scale_factor)
  106. //
  107. public void setScaleFactor(float scale_factor)
  108. {
  109. ThrowIfDisposed();
  110. xfeatures2d_TBMR_setScaleFactor_10(nativeObj, scale_factor);
  111. }
  112. //
  113. // C++: float cv::xfeatures2d::TBMR::getScaleFactor()
  114. //
  115. public float getScaleFactor()
  116. {
  117. ThrowIfDisposed();
  118. return xfeatures2d_TBMR_getScaleFactor_10(nativeObj);
  119. }
  120. //
  121. // C++: void cv::xfeatures2d::TBMR::setNScales(int n_scales)
  122. //
  123. public void setNScales(int n_scales)
  124. {
  125. ThrowIfDisposed();
  126. xfeatures2d_TBMR_setNScales_10(nativeObj, n_scales);
  127. }
  128. //
  129. // C++: int cv::xfeatures2d::TBMR::getNScales()
  130. //
  131. public int getNScales()
  132. {
  133. ThrowIfDisposed();
  134. return xfeatures2d_TBMR_getNScales_10(nativeObj);
  135. }
  136. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  137. const string LIBNAME = "__Internal";
  138. #else
  139. const string LIBNAME = "opencvforunity";
  140. #endif
  141. // C++: static Ptr_TBMR cv::xfeatures2d::TBMR::create(int min_area = 60, float max_area_relative = 0.01f, float scale_factor = 1.25f, int n_scales = -1)
  142. [DllImport(LIBNAME)]
  143. private static extern IntPtr xfeatures2d_TBMR_create_10(int min_area, float max_area_relative, float scale_factor, int n_scales);
  144. [DllImport(LIBNAME)]
  145. private static extern IntPtr xfeatures2d_TBMR_create_11(int min_area, float max_area_relative, float scale_factor);
  146. [DllImport(LIBNAME)]
  147. private static extern IntPtr xfeatures2d_TBMR_create_12(int min_area, float max_area_relative);
  148. [DllImport(LIBNAME)]
  149. private static extern IntPtr xfeatures2d_TBMR_create_13(int min_area);
  150. [DllImport(LIBNAME)]
  151. private static extern IntPtr xfeatures2d_TBMR_create_14();
  152. // C++: void cv::xfeatures2d::TBMR::setMinArea(int minArea)
  153. [DllImport(LIBNAME)]
  154. private static extern void xfeatures2d_TBMR_setMinArea_10(IntPtr nativeObj, int minArea);
  155. // C++: int cv::xfeatures2d::TBMR::getMinArea()
  156. [DllImport(LIBNAME)]
  157. private static extern int xfeatures2d_TBMR_getMinArea_10(IntPtr nativeObj);
  158. // C++: void cv::xfeatures2d::TBMR::setMaxAreaRelative(float maxArea)
  159. [DllImport(LIBNAME)]
  160. private static extern void xfeatures2d_TBMR_setMaxAreaRelative_10(IntPtr nativeObj, float maxArea);
  161. // C++: float cv::xfeatures2d::TBMR::getMaxAreaRelative()
  162. [DllImport(LIBNAME)]
  163. private static extern float xfeatures2d_TBMR_getMaxAreaRelative_10(IntPtr nativeObj);
  164. // C++: void cv::xfeatures2d::TBMR::setScaleFactor(float scale_factor)
  165. [DllImport(LIBNAME)]
  166. private static extern void xfeatures2d_TBMR_setScaleFactor_10(IntPtr nativeObj, float scale_factor);
  167. // C++: float cv::xfeatures2d::TBMR::getScaleFactor()
  168. [DllImport(LIBNAME)]
  169. private static extern float xfeatures2d_TBMR_getScaleFactor_10(IntPtr nativeObj);
  170. // C++: void cv::xfeatures2d::TBMR::setNScales(int n_scales)
  171. [DllImport(LIBNAME)]
  172. private static extern void xfeatures2d_TBMR_setNScales_10(IntPtr nativeObj, int n_scales);
  173. // C++: int cv::xfeatures2d::TBMR::getNScales()
  174. [DllImport(LIBNAME)]
  175. private static extern int xfeatures2d_TBMR_getNScales_10(IntPtr nativeObj);
  176. // native support for java finalize()
  177. [DllImport(LIBNAME)]
  178. private static extern void xfeatures2d_TBMR_delete(IntPtr nativeObj);
  179. }
  180. }