EdgeDrawing.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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 EdgeDrawing
  9. /**
  10. * Class implementing the ED (EdgeDrawing) CITE: topal2012edge, EDLines CITE: akinlar2011edlines, EDPF CITE: akinlar2012edpf and EDCircles CITE: akinlar2013edcircles algorithms
  11. */
  12. public class EdgeDrawing : 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_EdgeDrawing_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal EdgeDrawing(IntPtr addr) : base(addr) { }
  34. // internal usage only
  35. public static new EdgeDrawing __fromPtr__(IntPtr addr) { return new EdgeDrawing(addr); }
  36. // C++: enum cv.ximgproc.EdgeDrawing.GradientOperator
  37. public const int PREWITT = 0;
  38. public const int SOBEL = 1;
  39. public const int SCHARR = 2;
  40. public const int LSD = 3;
  41. //
  42. // C++: void cv::ximgproc::EdgeDrawing::detectEdges(Mat src)
  43. //
  44. /**
  45. * Detects edges in a grayscale image and prepares them to detect lines and ellipses.
  46. *
  47. * param src 8-bit, single-channel, grayscale input image.
  48. */
  49. public void detectEdges(Mat src)
  50. {
  51. ThrowIfDisposed();
  52. if (src != null) src.ThrowIfDisposed();
  53. ximgproc_EdgeDrawing_detectEdges_10(nativeObj, src.nativeObj);
  54. }
  55. //
  56. // C++: void cv::ximgproc::EdgeDrawing::getEdgeImage(Mat& dst)
  57. //
  58. /**
  59. * returns Edge Image prepared by detectEdges() function.
  60. *
  61. * param dst returns 8-bit, single-channel output image.
  62. */
  63. public void getEdgeImage(Mat dst)
  64. {
  65. ThrowIfDisposed();
  66. if (dst != null) dst.ThrowIfDisposed();
  67. ximgproc_EdgeDrawing_getEdgeImage_10(nativeObj, dst.nativeObj);
  68. }
  69. //
  70. // C++: void cv::ximgproc::EdgeDrawing::getGradientImage(Mat& dst)
  71. //
  72. /**
  73. * returns Gradient Image prepared by detectEdges() function.
  74. *
  75. * param dst returns 16-bit, single-channel output image.
  76. */
  77. public void getGradientImage(Mat dst)
  78. {
  79. ThrowIfDisposed();
  80. if (dst != null) dst.ThrowIfDisposed();
  81. ximgproc_EdgeDrawing_getGradientImage_10(nativeObj, dst.nativeObj);
  82. }
  83. //
  84. // C++: vector_vector_Point cv::ximgproc::EdgeDrawing::getSegments()
  85. //
  86. /**
  87. * Returns std::vector<std::vector<Point>> of detected edge segments, see detectEdges()
  88. * return automatically generated
  89. */
  90. public List<MatOfPoint> getSegments()
  91. {
  92. ThrowIfDisposed();
  93. List<MatOfPoint> retVal = new List<MatOfPoint>();
  94. Mat retValMat = new Mat(DisposableObject.ThrowIfNullIntPtr(ximgproc_EdgeDrawing_getSegments_10(nativeObj)));
  95. Converters.Mat_to_vector_vector_Point(retValMat, retVal);
  96. return retVal;
  97. }
  98. //
  99. // C++: vector_int cv::ximgproc::EdgeDrawing::getSegmentIndicesOfLines()
  100. //
  101. /**
  102. * Returns for each line found in detectLines() its edge segment index in getSegments()
  103. * return automatically generated
  104. */
  105. public MatOfInt getSegmentIndicesOfLines()
  106. {
  107. ThrowIfDisposed();
  108. return MatOfInt.fromNativeAddr(DisposableObject.ThrowIfNullIntPtr(ximgproc_EdgeDrawing_getSegmentIndicesOfLines_10(nativeObj)));
  109. }
  110. //
  111. // C++: void cv::ximgproc::EdgeDrawing::detectLines(Mat& lines)
  112. //
  113. /**
  114. * Detects lines.
  115. *
  116. * param lines output Vec&lt;4f&gt; contains the start point and the end point of detected lines.
  117. * <b>Note:</b> you should call detectEdges() before calling this function.
  118. */
  119. public void detectLines(Mat lines)
  120. {
  121. ThrowIfDisposed();
  122. if (lines != null) lines.ThrowIfDisposed();
  123. ximgproc_EdgeDrawing_detectLines_10(nativeObj, lines.nativeObj);
  124. }
  125. //
  126. // C++: void cv::ximgproc::EdgeDrawing::detectEllipses(Mat& ellipses)
  127. //
  128. /**
  129. * Detects circles and ellipses.
  130. *
  131. * param ellipses output Vec&lt;6d&gt; contains center point and perimeter for circles, center point, axes and angle for ellipses.
  132. * <b>Note:</b> you should call detectEdges() before calling this function.
  133. */
  134. public void detectEllipses(Mat ellipses)
  135. {
  136. ThrowIfDisposed();
  137. if (ellipses != null) ellipses.ThrowIfDisposed();
  138. ximgproc_EdgeDrawing_detectEllipses_10(nativeObj, ellipses.nativeObj);
  139. }
  140. //
  141. // C++: void cv::ximgproc::EdgeDrawing::setParams(EdgeDrawing_Params parameters)
  142. //
  143. /**
  144. * sets parameters.
  145. *
  146. * this function is meant to be used for parameter setting in other languages than c++ like python.
  147. * param parameters Parameters of the algorithm
  148. */
  149. public void setParams(EdgeDrawing_Params parameters)
  150. {
  151. ThrowIfDisposed();
  152. if (parameters != null) parameters.ThrowIfDisposed();
  153. ximgproc_EdgeDrawing_setParams_10(nativeObj, parameters.nativeObj);
  154. }
  155. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  156. const string LIBNAME = "__Internal";
  157. #else
  158. const string LIBNAME = "opencvforunity";
  159. #endif
  160. // C++: void cv::ximgproc::EdgeDrawing::detectEdges(Mat src)
  161. [DllImport(LIBNAME)]
  162. private static extern void ximgproc_EdgeDrawing_detectEdges_10(IntPtr nativeObj, IntPtr src_nativeObj);
  163. // C++: void cv::ximgproc::EdgeDrawing::getEdgeImage(Mat& dst)
  164. [DllImport(LIBNAME)]
  165. private static extern void ximgproc_EdgeDrawing_getEdgeImage_10(IntPtr nativeObj, IntPtr dst_nativeObj);
  166. // C++: void cv::ximgproc::EdgeDrawing::getGradientImage(Mat& dst)
  167. [DllImport(LIBNAME)]
  168. private static extern void ximgproc_EdgeDrawing_getGradientImage_10(IntPtr nativeObj, IntPtr dst_nativeObj);
  169. // C++: vector_vector_Point cv::ximgproc::EdgeDrawing::getSegments()
  170. [DllImport(LIBNAME)]
  171. private static extern IntPtr ximgproc_EdgeDrawing_getSegments_10(IntPtr nativeObj);
  172. // C++: vector_int cv::ximgproc::EdgeDrawing::getSegmentIndicesOfLines()
  173. [DllImport(LIBNAME)]
  174. private static extern IntPtr ximgproc_EdgeDrawing_getSegmentIndicesOfLines_10(IntPtr nativeObj);
  175. // C++: void cv::ximgproc::EdgeDrawing::detectLines(Mat& lines)
  176. [DllImport(LIBNAME)]
  177. private static extern void ximgproc_EdgeDrawing_detectLines_10(IntPtr nativeObj, IntPtr lines_nativeObj);
  178. // C++: void cv::ximgproc::EdgeDrawing::detectEllipses(Mat& ellipses)
  179. [DllImport(LIBNAME)]
  180. private static extern void ximgproc_EdgeDrawing_detectEllipses_10(IntPtr nativeObj, IntPtr ellipses_nativeObj);
  181. // C++: void cv::ximgproc::EdgeDrawing::setParams(EdgeDrawing_Params parameters)
  182. [DllImport(LIBNAME)]
  183. private static extern void ximgproc_EdgeDrawing_setParams_10(IntPtr nativeObj, IntPtr parameters_nativeObj);
  184. // native support for java finalize()
  185. [DllImport(LIBNAME)]
  186. private static extern void ximgproc_EdgeDrawing_delete(IntPtr nativeObj);
  187. }
  188. }