FastLineDetector.cs 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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 FastLineDetector
  9. /**
  10. * Class implementing the FLD (Fast Line Detector) algorithm described
  11. * in CITE: Lee14 .
  12. */
  13. public class FastLineDetector : Algorithm
  14. {
  15. protected override void Dispose(bool disposing)
  16. {
  17. try
  18. {
  19. if (disposing)
  20. {
  21. }
  22. if (IsEnabledDispose)
  23. {
  24. if (nativeObj != IntPtr.Zero)
  25. ximgproc_FastLineDetector_delete(nativeObj);
  26. nativeObj = IntPtr.Zero;
  27. }
  28. }
  29. finally
  30. {
  31. base.Dispose(disposing);
  32. }
  33. }
  34. protected internal FastLineDetector(IntPtr addr) : base(addr) { }
  35. // internal usage only
  36. public static new FastLineDetector __fromPtr__(IntPtr addr) { return new FastLineDetector(addr); }
  37. //
  38. // C++: void cv::ximgproc::FastLineDetector::detect(Mat image, Mat& lines)
  39. //
  40. /**
  41. * Finds lines in the input image.
  42. * This is the output of the default parameters of the algorithm on the above
  43. * shown image.
  44. *
  45. * ![image](pics/corridor_fld.jpg)
  46. *
  47. * param image A grayscale (CV_8UC1) input image. If only a roi needs to be
  48. * selected, use: `fld_ptr->detect(image(roi), lines, ...);
  49. * lines += Scalar(roi.x, roi.y, roi.x, roi.y);`
  50. * param lines A vector of Vec4f elements specifying the beginning
  51. * and ending point of a line. Where Vec4f is (x1, y1, x2, y2), point
  52. * 1 is the start, point 2 - end. Returned lines are directed so that the
  53. * brighter side is on their left.
  54. */
  55. public void detect(Mat image, Mat lines)
  56. {
  57. ThrowIfDisposed();
  58. if (image != null) image.ThrowIfDisposed();
  59. if (lines != null) lines.ThrowIfDisposed();
  60. ximgproc_FastLineDetector_detect_10(nativeObj, image.nativeObj, lines.nativeObj);
  61. }
  62. //
  63. // C++: void cv::ximgproc::FastLineDetector::drawSegments(Mat& image, Mat lines, bool draw_arrow = false, Scalar linecolor = Scalar(0, 0, 255), int linethickness = 1)
  64. //
  65. /**
  66. * Draws the line segments on a given image.
  67. * param image The image, where the lines will be drawn. Should be bigger
  68. * or equal to the image, where the lines were found.
  69. * param lines A vector of the lines that needed to be drawn.
  70. * param draw_arrow If true, arrow heads will be drawn.
  71. * param linecolor Line color.
  72. * param linethickness Line thickness.
  73. */
  74. public void drawSegments(Mat image, Mat lines, bool draw_arrow, Scalar linecolor, int linethickness)
  75. {
  76. ThrowIfDisposed();
  77. if (image != null) image.ThrowIfDisposed();
  78. if (lines != null) lines.ThrowIfDisposed();
  79. ximgproc_FastLineDetector_drawSegments_10(nativeObj, image.nativeObj, lines.nativeObj, draw_arrow, linecolor.val[0], linecolor.val[1], linecolor.val[2], linecolor.val[3], linethickness);
  80. }
  81. /**
  82. * Draws the line segments on a given image.
  83. * param image The image, where the lines will be drawn. Should be bigger
  84. * or equal to the image, where the lines were found.
  85. * param lines A vector of the lines that needed to be drawn.
  86. * param draw_arrow If true, arrow heads will be drawn.
  87. * param linecolor Line color.
  88. */
  89. public void drawSegments(Mat image, Mat lines, bool draw_arrow, Scalar linecolor)
  90. {
  91. ThrowIfDisposed();
  92. if (image != null) image.ThrowIfDisposed();
  93. if (lines != null) lines.ThrowIfDisposed();
  94. ximgproc_FastLineDetector_drawSegments_11(nativeObj, image.nativeObj, lines.nativeObj, draw_arrow, linecolor.val[0], linecolor.val[1], linecolor.val[2], linecolor.val[3]);
  95. }
  96. /**
  97. * Draws the line segments on a given image.
  98. * param image The image, where the lines will be drawn. Should be bigger
  99. * or equal to the image, where the lines were found.
  100. * param lines A vector of the lines that needed to be drawn.
  101. * param draw_arrow If true, arrow heads will be drawn.
  102. */
  103. public void drawSegments(Mat image, Mat lines, bool draw_arrow)
  104. {
  105. ThrowIfDisposed();
  106. if (image != null) image.ThrowIfDisposed();
  107. if (lines != null) lines.ThrowIfDisposed();
  108. ximgproc_FastLineDetector_drawSegments_12(nativeObj, image.nativeObj, lines.nativeObj, draw_arrow);
  109. }
  110. /**
  111. * Draws the line segments on a given image.
  112. * param image The image, where the lines will be drawn. Should be bigger
  113. * or equal to the image, where the lines were found.
  114. * param lines A vector of the lines that needed to be drawn.
  115. */
  116. public void drawSegments(Mat image, Mat lines)
  117. {
  118. ThrowIfDisposed();
  119. if (image != null) image.ThrowIfDisposed();
  120. if (lines != null) lines.ThrowIfDisposed();
  121. ximgproc_FastLineDetector_drawSegments_13(nativeObj, image.nativeObj, lines.nativeObj);
  122. }
  123. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  124. const string LIBNAME = "__Internal";
  125. #else
  126. const string LIBNAME = "opencvforunity";
  127. #endif
  128. // C++: void cv::ximgproc::FastLineDetector::detect(Mat image, Mat& lines)
  129. [DllImport(LIBNAME)]
  130. private static extern void ximgproc_FastLineDetector_detect_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr lines_nativeObj);
  131. // C++: void cv::ximgproc::FastLineDetector::drawSegments(Mat& image, Mat lines, bool draw_arrow = false, Scalar linecolor = Scalar(0, 0, 255), int linethickness = 1)
  132. [DllImport(LIBNAME)]
  133. private static extern void ximgproc_FastLineDetector_drawSegments_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr lines_nativeObj, [MarshalAs(UnmanagedType.U1)] bool draw_arrow, double linecolor_val0, double linecolor_val1, double linecolor_val2, double linecolor_val3, int linethickness);
  134. [DllImport(LIBNAME)]
  135. private static extern void ximgproc_FastLineDetector_drawSegments_11(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr lines_nativeObj, [MarshalAs(UnmanagedType.U1)] bool draw_arrow, double linecolor_val0, double linecolor_val1, double linecolor_val2, double linecolor_val3);
  136. [DllImport(LIBNAME)]
  137. private static extern void ximgproc_FastLineDetector_drawSegments_12(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr lines_nativeObj, [MarshalAs(UnmanagedType.U1)] bool draw_arrow);
  138. [DllImport(LIBNAME)]
  139. private static extern void ximgproc_FastLineDetector_drawSegments_13(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr lines_nativeObj);
  140. // native support for java finalize()
  141. [DllImport(LIBNAME)]
  142. private static extern void ximgproc_FastLineDetector_delete(IntPtr nativeObj);
  143. }
  144. }