LATCH.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300
  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 LATCH
  10. /**
  11. * latch Class for computing the LATCH descriptor.
  12. * If you find this code useful, please add a reference to the following paper in your work:
  13. * Gil Levi and Tal Hassner, "LATCH: Learned Arrangements of Three Patch Codes", arXiv preprint arXiv:1501.03719, 15 Jan. 2015
  14. *
  15. * LATCH is a binary descriptor based on learned comparisons of triplets of image patches.
  16. *
  17. * bytes is the size of the descriptor - can be 64, 32, 16, 8, 4, 2 or 1
  18. * rotationInvariance - whether or not the descriptor should compansate for orientation changes.
  19. * 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
  20. * then the half_ssd_size should be (7-1)/2 = 3.
  21. * sigma - sigma value for GaussianBlur smoothing of the source image. Source image will be used without smoothing in case sigma value is 0.
  22. *
  23. * Note: the descriptor can be coupled with any keypoint extractor. The only demand is that if you use set rotationInvariance = True then
  24. * you will have to use an extractor which estimates the patch orientation (in degrees). Examples for such extractors are ORB and SIFT.
  25. *
  26. * Note: a complete example can be found under /samples/cpp/tutorial_code/xfeatures2D/latch_match.cpp
  27. */
  28. public class LATCH : Feature2D
  29. {
  30. protected override void Dispose(bool disposing)
  31. {
  32. try
  33. {
  34. if (disposing)
  35. {
  36. }
  37. if (IsEnabledDispose)
  38. {
  39. if (nativeObj != IntPtr.Zero)
  40. xfeatures2d_LATCH_delete(nativeObj);
  41. nativeObj = IntPtr.Zero;
  42. }
  43. }
  44. finally
  45. {
  46. base.Dispose(disposing);
  47. }
  48. }
  49. protected internal LATCH(IntPtr addr) : base(addr) { }
  50. // internal usage only
  51. public static new LATCH __fromPtr__(IntPtr addr) { return new LATCH(addr); }
  52. //
  53. // C++: static Ptr_LATCH cv::xfeatures2d::LATCH::create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3, double sigma = 2.0)
  54. //
  55. public static LATCH create(int bytes, bool rotationInvariance, int half_ssd_size, double sigma)
  56. {
  57. return LATCH.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_LATCH_create_10(bytes, rotationInvariance, half_ssd_size, sigma)));
  58. }
  59. public static LATCH create(int bytes, bool rotationInvariance, int half_ssd_size)
  60. {
  61. return LATCH.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_LATCH_create_11(bytes, rotationInvariance, half_ssd_size)));
  62. }
  63. public static LATCH create(int bytes, bool rotationInvariance)
  64. {
  65. return LATCH.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_LATCH_create_12(bytes, rotationInvariance)));
  66. }
  67. public static LATCH create(int bytes)
  68. {
  69. return LATCH.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_LATCH_create_13(bytes)));
  70. }
  71. public static LATCH create()
  72. {
  73. return LATCH.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_LATCH_create_14()));
  74. }
  75. //
  76. // C++: void cv::xfeatures2d::LATCH::setBytes(int bytes)
  77. //
  78. public void setBytes(int bytes)
  79. {
  80. ThrowIfDisposed();
  81. xfeatures2d_LATCH_setBytes_10(nativeObj, bytes);
  82. }
  83. //
  84. // C++: int cv::xfeatures2d::LATCH::getBytes()
  85. //
  86. public int getBytes()
  87. {
  88. ThrowIfDisposed();
  89. return xfeatures2d_LATCH_getBytes_10(nativeObj);
  90. }
  91. //
  92. // C++: void cv::xfeatures2d::LATCH::setRotationInvariance(bool rotationInvariance)
  93. //
  94. public void setRotationInvariance(bool rotationInvariance)
  95. {
  96. ThrowIfDisposed();
  97. xfeatures2d_LATCH_setRotationInvariance_10(nativeObj, rotationInvariance);
  98. }
  99. //
  100. // C++: bool cv::xfeatures2d::LATCH::getRotationInvariance()
  101. //
  102. public bool getRotationInvariance()
  103. {
  104. ThrowIfDisposed();
  105. return xfeatures2d_LATCH_getRotationInvariance_10(nativeObj);
  106. }
  107. //
  108. // C++: void cv::xfeatures2d::LATCH::setHalfSSDsize(int half_ssd_size)
  109. //
  110. public void setHalfSSDsize(int half_ssd_size)
  111. {
  112. ThrowIfDisposed();
  113. xfeatures2d_LATCH_setHalfSSDsize_10(nativeObj, half_ssd_size);
  114. }
  115. //
  116. // C++: int cv::xfeatures2d::LATCH::getHalfSSDsize()
  117. //
  118. public int getHalfSSDsize()
  119. {
  120. ThrowIfDisposed();
  121. return xfeatures2d_LATCH_getHalfSSDsize_10(nativeObj);
  122. }
  123. //
  124. // C++: void cv::xfeatures2d::LATCH::setSigma(double sigma)
  125. //
  126. public void setSigma(double sigma)
  127. {
  128. ThrowIfDisposed();
  129. xfeatures2d_LATCH_setSigma_10(nativeObj, sigma);
  130. }
  131. //
  132. // C++: double cv::xfeatures2d::LATCH::getSigma()
  133. //
  134. public double getSigma()
  135. {
  136. ThrowIfDisposed();
  137. return xfeatures2d_LATCH_getSigma_10(nativeObj);
  138. }
  139. //
  140. // C++: String cv::xfeatures2d::LATCH::getDefaultName()
  141. //
  142. public override string getDefaultName()
  143. {
  144. ThrowIfDisposed();
  145. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(xfeatures2d_LATCH_getDefaultName_10(nativeObj)));
  146. return retVal;
  147. }
  148. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  149. const string LIBNAME = "__Internal";
  150. #else
  151. const string LIBNAME = "opencvforunity";
  152. #endif
  153. // C++: static Ptr_LATCH cv::xfeatures2d::LATCH::create(int bytes = 32, bool rotationInvariance = true, int half_ssd_size = 3, double sigma = 2.0)
  154. [DllImport(LIBNAME)]
  155. private static extern IntPtr xfeatures2d_LATCH_create_10(int bytes, [MarshalAs(UnmanagedType.U1)] bool rotationInvariance, int half_ssd_size, double sigma);
  156. [DllImport(LIBNAME)]
  157. private static extern IntPtr xfeatures2d_LATCH_create_11(int bytes, [MarshalAs(UnmanagedType.U1)] bool rotationInvariance, int half_ssd_size);
  158. [DllImport(LIBNAME)]
  159. private static extern IntPtr xfeatures2d_LATCH_create_12(int bytes, [MarshalAs(UnmanagedType.U1)] bool rotationInvariance);
  160. [DllImport(LIBNAME)]
  161. private static extern IntPtr xfeatures2d_LATCH_create_13(int bytes);
  162. [DllImport(LIBNAME)]
  163. private static extern IntPtr xfeatures2d_LATCH_create_14();
  164. // C++: void cv::xfeatures2d::LATCH::setBytes(int bytes)
  165. [DllImport(LIBNAME)]
  166. private static extern void xfeatures2d_LATCH_setBytes_10(IntPtr nativeObj, int bytes);
  167. // C++: int cv::xfeatures2d::LATCH::getBytes()
  168. [DllImport(LIBNAME)]
  169. private static extern int xfeatures2d_LATCH_getBytes_10(IntPtr nativeObj);
  170. // C++: void cv::xfeatures2d::LATCH::setRotationInvariance(bool rotationInvariance)
  171. [DllImport(LIBNAME)]
  172. private static extern void xfeatures2d_LATCH_setRotationInvariance_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool rotationInvariance);
  173. // C++: bool cv::xfeatures2d::LATCH::getRotationInvariance()
  174. [DllImport(LIBNAME)]
  175. [return: MarshalAs(UnmanagedType.U1)]
  176. private static extern bool xfeatures2d_LATCH_getRotationInvariance_10(IntPtr nativeObj);
  177. // C++: void cv::xfeatures2d::LATCH::setHalfSSDsize(int half_ssd_size)
  178. [DllImport(LIBNAME)]
  179. private static extern void xfeatures2d_LATCH_setHalfSSDsize_10(IntPtr nativeObj, int half_ssd_size);
  180. // C++: int cv::xfeatures2d::LATCH::getHalfSSDsize()
  181. [DllImport(LIBNAME)]
  182. private static extern int xfeatures2d_LATCH_getHalfSSDsize_10(IntPtr nativeObj);
  183. // C++: void cv::xfeatures2d::LATCH::setSigma(double sigma)
  184. [DllImport(LIBNAME)]
  185. private static extern void xfeatures2d_LATCH_setSigma_10(IntPtr nativeObj, double sigma);
  186. // C++: double cv::xfeatures2d::LATCH::getSigma()
  187. [DllImport(LIBNAME)]
  188. private static extern double xfeatures2d_LATCH_getSigma_10(IntPtr nativeObj);
  189. // C++: String cv::xfeatures2d::LATCH::getDefaultName()
  190. [DllImport(LIBNAME)]
  191. private static extern IntPtr xfeatures2d_LATCH_getDefaultName_10(IntPtr nativeObj);
  192. // native support for java finalize()
  193. [DllImport(LIBNAME)]
  194. private static extern void xfeatures2d_LATCH_delete(IntPtr nativeObj);
  195. }
  196. }