VGG.cs 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359
  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 VGG
  10. /**
  11. * Class implementing VGG (Oxford Visual Geometry Group) descriptor trained end to end
  12. * using "Descriptor Learning Using Convex Optimisation" (DLCO) aparatus described in CITE: Simonyan14.
  13. *
  14. * desc type of descriptor to use, VGG::VGG_120 is default (120 dimensions float)
  15. * Available types are VGG::VGG_120, VGG::VGG_80, VGG::VGG_64, VGG::VGG_48
  16. * isigma gaussian kernel value for image blur (default is 1.4f)
  17. * img_normalize use image sample intensity normalization (enabled by default)
  18. * use_orientation sample patterns using keypoints orientation, enabled by default
  19. * scale_factor adjust the sampling window of detected keypoints to 64.0f (VGG sampling window)
  20. * 6.25f is default and fits for KAZE, SURF detected keypoints window ratio
  21. * 6.75f should be the scale for SIFT detected keypoints window ratio
  22. * 5.00f should be the scale for AKAZE, MSD, AGAST, FAST, BRISK keypoints window ratio
  23. * 0.75f should be the scale for ORB keypoints ratio
  24. *
  25. * dsc_normalize clamp descriptors to 255 and convert to uchar CV_8UC1 (disabled by default)
  26. */
  27. public class VGG : Feature2D
  28. {
  29. protected override void Dispose(bool disposing)
  30. {
  31. try
  32. {
  33. if (disposing)
  34. {
  35. }
  36. if (IsEnabledDispose)
  37. {
  38. if (nativeObj != IntPtr.Zero)
  39. xfeatures2d_VGG_delete(nativeObj);
  40. nativeObj = IntPtr.Zero;
  41. }
  42. }
  43. finally
  44. {
  45. base.Dispose(disposing);
  46. }
  47. }
  48. protected internal VGG(IntPtr addr) : base(addr) { }
  49. // internal usage only
  50. public static new VGG __fromPtr__(IntPtr addr) { return new VGG(addr); }
  51. //
  52. // C++: static Ptr_VGG cv::xfeatures2d::VGG::create(int desc = VGG::VGG_120, float isigma = 1.4f, bool img_normalize = true, bool use_scale_orientation = true, float scale_factor = 6.25f, bool dsc_normalize = false)
  53. //
  54. public static VGG create(int desc, float isigma, bool img_normalize, bool use_scale_orientation, float scale_factor, bool dsc_normalize)
  55. {
  56. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_10(desc, isigma, img_normalize, use_scale_orientation, scale_factor, dsc_normalize)));
  57. }
  58. public static VGG create(int desc, float isigma, bool img_normalize, bool use_scale_orientation, float scale_factor)
  59. {
  60. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_11(desc, isigma, img_normalize, use_scale_orientation, scale_factor)));
  61. }
  62. public static VGG create(int desc, float isigma, bool img_normalize, bool use_scale_orientation)
  63. {
  64. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_12(desc, isigma, img_normalize, use_scale_orientation)));
  65. }
  66. public static VGG create(int desc, float isigma, bool img_normalize)
  67. {
  68. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_13(desc, isigma, img_normalize)));
  69. }
  70. public static VGG create(int desc, float isigma)
  71. {
  72. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_14(desc, isigma)));
  73. }
  74. public static VGG create(int desc)
  75. {
  76. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_15(desc)));
  77. }
  78. public static VGG create()
  79. {
  80. return VGG.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_create_16()));
  81. }
  82. //
  83. // C++: String cv::xfeatures2d::VGG::getDefaultName()
  84. //
  85. public override string getDefaultName()
  86. {
  87. ThrowIfDisposed();
  88. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_VGG_getDefaultName_10(nativeObj)));
  89. return retVal;
  90. }
  91. //
  92. // C++: void cv::xfeatures2d::VGG::setSigma(float isigma)
  93. //
  94. public void setSigma(float isigma)
  95. {
  96. ThrowIfDisposed();
  97. xfeatures2d_VGG_setSigma_10(nativeObj, isigma);
  98. }
  99. //
  100. // C++: float cv::xfeatures2d::VGG::getSigma()
  101. //
  102. public float getSigma()
  103. {
  104. ThrowIfDisposed();
  105. return xfeatures2d_VGG_getSigma_10(nativeObj);
  106. }
  107. //
  108. // C++: void cv::xfeatures2d::VGG::setUseNormalizeImage(bool img_normalize)
  109. //
  110. public void setUseNormalizeImage(bool img_normalize)
  111. {
  112. ThrowIfDisposed();
  113. xfeatures2d_VGG_setUseNormalizeImage_10(nativeObj, img_normalize);
  114. }
  115. //
  116. // C++: bool cv::xfeatures2d::VGG::getUseNormalizeImage()
  117. //
  118. public bool getUseNormalizeImage()
  119. {
  120. ThrowIfDisposed();
  121. return xfeatures2d_VGG_getUseNormalizeImage_10(nativeObj);
  122. }
  123. //
  124. // C++: void cv::xfeatures2d::VGG::setUseScaleOrientation(bool use_scale_orientation)
  125. //
  126. public void setUseScaleOrientation(bool use_scale_orientation)
  127. {
  128. ThrowIfDisposed();
  129. xfeatures2d_VGG_setUseScaleOrientation_10(nativeObj, use_scale_orientation);
  130. }
  131. //
  132. // C++: bool cv::xfeatures2d::VGG::getUseScaleOrientation()
  133. //
  134. public bool getUseScaleOrientation()
  135. {
  136. ThrowIfDisposed();
  137. return xfeatures2d_VGG_getUseScaleOrientation_10(nativeObj);
  138. }
  139. //
  140. // C++: void cv::xfeatures2d::VGG::setScaleFactor(float scale_factor)
  141. //
  142. public void setScaleFactor(float scale_factor)
  143. {
  144. ThrowIfDisposed();
  145. xfeatures2d_VGG_setScaleFactor_10(nativeObj, scale_factor);
  146. }
  147. //
  148. // C++: float cv::xfeatures2d::VGG::getScaleFactor()
  149. //
  150. public float getScaleFactor()
  151. {
  152. ThrowIfDisposed();
  153. return xfeatures2d_VGG_getScaleFactor_10(nativeObj);
  154. }
  155. //
  156. // C++: void cv::xfeatures2d::VGG::setUseNormalizeDescriptor(bool dsc_normalize)
  157. //
  158. public void setUseNormalizeDescriptor(bool dsc_normalize)
  159. {
  160. ThrowIfDisposed();
  161. xfeatures2d_VGG_setUseNormalizeDescriptor_10(nativeObj, dsc_normalize);
  162. }
  163. //
  164. // C++: bool cv::xfeatures2d::VGG::getUseNormalizeDescriptor()
  165. //
  166. public bool getUseNormalizeDescriptor()
  167. {
  168. ThrowIfDisposed();
  169. return xfeatures2d_VGG_getUseNormalizeDescriptor_10(nativeObj);
  170. }
  171. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  172. const string LIBNAME = "__Internal";
  173. #else
  174. const string LIBNAME = "opencvforunity";
  175. #endif
  176. // C++: static Ptr_VGG cv::xfeatures2d::VGG::create(int desc = VGG::VGG_120, float isigma = 1.4f, bool img_normalize = true, bool use_scale_orientation = true, float scale_factor = 6.25f, bool dsc_normalize = false)
  177. [DllImport(LIBNAME)]
  178. private static extern IntPtr xfeatures2d_VGG_create_10(int desc, float isigma, [MarshalAs(UnmanagedType.U1)] bool img_normalize, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation, float scale_factor, [MarshalAs(UnmanagedType.U1)] bool dsc_normalize);
  179. [DllImport(LIBNAME)]
  180. private static extern IntPtr xfeatures2d_VGG_create_11(int desc, float isigma, [MarshalAs(UnmanagedType.U1)] bool img_normalize, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation, float scale_factor);
  181. [DllImport(LIBNAME)]
  182. private static extern IntPtr xfeatures2d_VGG_create_12(int desc, float isigma, [MarshalAs(UnmanagedType.U1)] bool img_normalize, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation);
  183. [DllImport(LIBNAME)]
  184. private static extern IntPtr xfeatures2d_VGG_create_13(int desc, float isigma, [MarshalAs(UnmanagedType.U1)] bool img_normalize);
  185. [DllImport(LIBNAME)]
  186. private static extern IntPtr xfeatures2d_VGG_create_14(int desc, float isigma);
  187. [DllImport(LIBNAME)]
  188. private static extern IntPtr xfeatures2d_VGG_create_15(int desc);
  189. [DllImport(LIBNAME)]
  190. private static extern IntPtr xfeatures2d_VGG_create_16();
  191. // C++: String cv::xfeatures2d::VGG::getDefaultName()
  192. [DllImport(LIBNAME)]
  193. private static extern IntPtr xfeatures2d_VGG_getDefaultName_10(IntPtr nativeObj);
  194. // C++: void cv::xfeatures2d::VGG::setSigma(float isigma)
  195. [DllImport(LIBNAME)]
  196. private static extern void xfeatures2d_VGG_setSigma_10(IntPtr nativeObj, float isigma);
  197. // C++: float cv::xfeatures2d::VGG::getSigma()
  198. [DllImport(LIBNAME)]
  199. private static extern float xfeatures2d_VGG_getSigma_10(IntPtr nativeObj);
  200. // C++: void cv::xfeatures2d::VGG::setUseNormalizeImage(bool img_normalize)
  201. [DllImport(LIBNAME)]
  202. private static extern void xfeatures2d_VGG_setUseNormalizeImage_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool img_normalize);
  203. // C++: bool cv::xfeatures2d::VGG::getUseNormalizeImage()
  204. [DllImport(LIBNAME)]
  205. [return: MarshalAs(UnmanagedType.U1)]
  206. private static extern bool xfeatures2d_VGG_getUseNormalizeImage_10(IntPtr nativeObj);
  207. // C++: void cv::xfeatures2d::VGG::setUseScaleOrientation(bool use_scale_orientation)
  208. [DllImport(LIBNAME)]
  209. private static extern void xfeatures2d_VGG_setUseScaleOrientation_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool use_scale_orientation);
  210. // C++: bool cv::xfeatures2d::VGG::getUseScaleOrientation()
  211. [DllImport(LIBNAME)]
  212. [return: MarshalAs(UnmanagedType.U1)]
  213. private static extern bool xfeatures2d_VGG_getUseScaleOrientation_10(IntPtr nativeObj);
  214. // C++: void cv::xfeatures2d::VGG::setScaleFactor(float scale_factor)
  215. [DllImport(LIBNAME)]
  216. private static extern void xfeatures2d_VGG_setScaleFactor_10(IntPtr nativeObj, float scale_factor);
  217. // C++: float cv::xfeatures2d::VGG::getScaleFactor()
  218. [DllImport(LIBNAME)]
  219. private static extern float xfeatures2d_VGG_getScaleFactor_10(IntPtr nativeObj);
  220. // C++: void cv::xfeatures2d::VGG::setUseNormalizeDescriptor(bool dsc_normalize)
  221. [DllImport(LIBNAME)]
  222. private static extern void xfeatures2d_VGG_setUseNormalizeDescriptor_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool dsc_normalize);
  223. // C++: bool cv::xfeatures2d::VGG::getUseNormalizeDescriptor()
  224. [DllImport(LIBNAME)]
  225. [return: MarshalAs(UnmanagedType.U1)]
  226. private static extern bool xfeatures2d_VGG_getUseNormalizeDescriptor_10(IntPtr nativeObj);
  227. // native support for java finalize()
  228. [DllImport(LIBNAME)]
  229. private static extern void xfeatures2d_VGG_delete(IntPtr nativeObj);
  230. }
  231. }