StructuredEdgeDetection.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.XimgprocModule
  7. {
  8. // C++: class StructuredEdgeDetection
  9. /**
  10. * Class implementing edge detection algorithm from CITE: Dollar2013 :
  11. */
  12. public class StructuredEdgeDetection : Algorithm
  13. {
  14. protected override void Dispose(bool disposing)
  15. {
  16. try
  17. {
  18. if (disposing)
  19. {
  20. }
  21. if (IsEnabledDispose)
  22. {
  23. if (nativeObj != IntPtr.Zero)
  24. ximgproc_StructuredEdgeDetection_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal StructuredEdgeDetection(IntPtr addr) : base(addr) { }
  34. // internal usage only
  35. public static new StructuredEdgeDetection __fromPtr__(IntPtr addr) { return new StructuredEdgeDetection(addr); }
  36. //
  37. // C++: void cv::ximgproc::StructuredEdgeDetection::detectEdges(Mat src, Mat& dst)
  38. //
  39. /**
  40. * The function detects edges in src and draw them to dst.
  41. *
  42. * The algorithm underlies this function is much more robust to texture presence, than common
  43. * approaches, e.g. Sobel
  44. * param src source image (RGB, float, in [0;1]) to detect edges
  45. * param dst destination image (grayscale, float, in [0;1]) where edges are drawn
  46. * SEE: Sobel, Canny
  47. */
  48. public void detectEdges(Mat src, Mat dst)
  49. {
  50. ThrowIfDisposed();
  51. if (src != null) src.ThrowIfDisposed();
  52. if (dst != null) dst.ThrowIfDisposed();
  53. ximgproc_StructuredEdgeDetection_detectEdges_10(nativeObj, src.nativeObj, dst.nativeObj);
  54. }
  55. //
  56. // C++: void cv::ximgproc::StructuredEdgeDetection::computeOrientation(Mat src, Mat& dst)
  57. //
  58. /**
  59. * The function computes orientation from edge image.
  60. *
  61. * param src edge image.
  62. * param dst orientation image.
  63. */
  64. public void computeOrientation(Mat src, Mat dst)
  65. {
  66. ThrowIfDisposed();
  67. if (src != null) src.ThrowIfDisposed();
  68. if (dst != null) dst.ThrowIfDisposed();
  69. ximgproc_StructuredEdgeDetection_computeOrientation_10(nativeObj, src.nativeObj, dst.nativeObj);
  70. }
  71. //
  72. // C++: void cv::ximgproc::StructuredEdgeDetection::edgesNms(Mat edge_image, Mat orientation_image, Mat& dst, int r = 2, int s = 0, float m = 1, bool isParallel = true)
  73. //
  74. /**
  75. * The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
  76. *
  77. * param edge_image edge image from detectEdges function.
  78. * param orientation_image orientation image from computeOrientation function.
  79. * param dst suppressed image (grayscale, float, in [0;1])
  80. * param r radius for NMS suppression.
  81. * param s radius for boundary suppression.
  82. * param m multiplier for conservative suppression.
  83. * param isParallel enables/disables parallel computing.
  84. */
  85. public void edgesNms(Mat edge_image, Mat orientation_image, Mat dst, int r, int s, float m, bool isParallel)
  86. {
  87. ThrowIfDisposed();
  88. if (edge_image != null) edge_image.ThrowIfDisposed();
  89. if (orientation_image != null) orientation_image.ThrowIfDisposed();
  90. if (dst != null) dst.ThrowIfDisposed();
  91. ximgproc_StructuredEdgeDetection_edgesNms_10(nativeObj, edge_image.nativeObj, orientation_image.nativeObj, dst.nativeObj, r, s, m, isParallel);
  92. }
  93. /**
  94. * The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
  95. *
  96. * param edge_image edge image from detectEdges function.
  97. * param orientation_image orientation image from computeOrientation function.
  98. * param dst suppressed image (grayscale, float, in [0;1])
  99. * param r radius for NMS suppression.
  100. * param s radius for boundary suppression.
  101. * param m multiplier for conservative suppression.
  102. */
  103. public void edgesNms(Mat edge_image, Mat orientation_image, Mat dst, int r, int s, float m)
  104. {
  105. ThrowIfDisposed();
  106. if (edge_image != null) edge_image.ThrowIfDisposed();
  107. if (orientation_image != null) orientation_image.ThrowIfDisposed();
  108. if (dst != null) dst.ThrowIfDisposed();
  109. ximgproc_StructuredEdgeDetection_edgesNms_11(nativeObj, edge_image.nativeObj, orientation_image.nativeObj, dst.nativeObj, r, s, m);
  110. }
  111. /**
  112. * The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
  113. *
  114. * param edge_image edge image from detectEdges function.
  115. * param orientation_image orientation image from computeOrientation function.
  116. * param dst suppressed image (grayscale, float, in [0;1])
  117. * param r radius for NMS suppression.
  118. * param s radius for boundary suppression.
  119. */
  120. public void edgesNms(Mat edge_image, Mat orientation_image, Mat dst, int r, int s)
  121. {
  122. ThrowIfDisposed();
  123. if (edge_image != null) edge_image.ThrowIfDisposed();
  124. if (orientation_image != null) orientation_image.ThrowIfDisposed();
  125. if (dst != null) dst.ThrowIfDisposed();
  126. ximgproc_StructuredEdgeDetection_edgesNms_12(nativeObj, edge_image.nativeObj, orientation_image.nativeObj, dst.nativeObj, r, s);
  127. }
  128. /**
  129. * The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
  130. *
  131. * param edge_image edge image from detectEdges function.
  132. * param orientation_image orientation image from computeOrientation function.
  133. * param dst suppressed image (grayscale, float, in [0;1])
  134. * param r radius for NMS suppression.
  135. */
  136. public void edgesNms(Mat edge_image, Mat orientation_image, Mat dst, int r)
  137. {
  138. ThrowIfDisposed();
  139. if (edge_image != null) edge_image.ThrowIfDisposed();
  140. if (orientation_image != null) orientation_image.ThrowIfDisposed();
  141. if (dst != null) dst.ThrowIfDisposed();
  142. ximgproc_StructuredEdgeDetection_edgesNms_13(nativeObj, edge_image.nativeObj, orientation_image.nativeObj, dst.nativeObj, r);
  143. }
  144. /**
  145. * The function edgenms in edge image and suppress edges where edge is stronger in orthogonal direction.
  146. *
  147. * param edge_image edge image from detectEdges function.
  148. * param orientation_image orientation image from computeOrientation function.
  149. * param dst suppressed image (grayscale, float, in [0;1])
  150. */
  151. public void edgesNms(Mat edge_image, Mat orientation_image, Mat dst)
  152. {
  153. ThrowIfDisposed();
  154. if (edge_image != null) edge_image.ThrowIfDisposed();
  155. if (orientation_image != null) orientation_image.ThrowIfDisposed();
  156. if (dst != null) dst.ThrowIfDisposed();
  157. ximgproc_StructuredEdgeDetection_edgesNms_14(nativeObj, edge_image.nativeObj, orientation_image.nativeObj, dst.nativeObj);
  158. }
  159. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  160. const string LIBNAME = "__Internal";
  161. #else
  162. const string LIBNAME = "opencvforunity";
  163. #endif
  164. // C++: void cv::ximgproc::StructuredEdgeDetection::detectEdges(Mat src, Mat& dst)
  165. [DllImport(LIBNAME)]
  166. private static extern void ximgproc_StructuredEdgeDetection_detectEdges_10(IntPtr nativeObj, IntPtr src_nativeObj, IntPtr dst_nativeObj);
  167. // C++: void cv::ximgproc::StructuredEdgeDetection::computeOrientation(Mat src, Mat& dst)
  168. [DllImport(LIBNAME)]
  169. private static extern void ximgproc_StructuredEdgeDetection_computeOrientation_10(IntPtr nativeObj, IntPtr src_nativeObj, IntPtr dst_nativeObj);
  170. // C++: void cv::ximgproc::StructuredEdgeDetection::edgesNms(Mat edge_image, Mat orientation_image, Mat& dst, int r = 2, int s = 0, float m = 1, bool isParallel = true)
  171. [DllImport(LIBNAME)]
  172. private static extern void ximgproc_StructuredEdgeDetection_edgesNms_10(IntPtr nativeObj, IntPtr edge_image_nativeObj, IntPtr orientation_image_nativeObj, IntPtr dst_nativeObj, int r, int s, float m, [MarshalAs(UnmanagedType.U1)] bool isParallel);
  173. [DllImport(LIBNAME)]
  174. private static extern void ximgproc_StructuredEdgeDetection_edgesNms_11(IntPtr nativeObj, IntPtr edge_image_nativeObj, IntPtr orientation_image_nativeObj, IntPtr dst_nativeObj, int r, int s, float m);
  175. [DllImport(LIBNAME)]
  176. private static extern void ximgproc_StructuredEdgeDetection_edgesNms_12(IntPtr nativeObj, IntPtr edge_image_nativeObj, IntPtr orientation_image_nativeObj, IntPtr dst_nativeObj, int r, int s);
  177. [DllImport(LIBNAME)]
  178. private static extern void ximgproc_StructuredEdgeDetection_edgesNms_13(IntPtr nativeObj, IntPtr edge_image_nativeObj, IntPtr orientation_image_nativeObj, IntPtr dst_nativeObj, int r);
  179. [DllImport(LIBNAME)]
  180. private static extern void ximgproc_StructuredEdgeDetection_edgesNms_14(IntPtr nativeObj, IntPtr edge_image_nativeObj, IntPtr orientation_image_nativeObj, IntPtr dst_nativeObj);
  181. // native support for java finalize()
  182. [DllImport(LIBNAME)]
  183. private static extern void ximgproc_StructuredEdgeDetection_delete(IntPtr nativeObj);
  184. }
  185. }