QRCodeDetector.cs 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.ObjdetectModule
  7. {
  8. // C++: class QRCodeDetector
  9. public class QRCodeDetector : GraphicalCodeDetector
  10. {
  11. protected override void Dispose(bool disposing)
  12. {
  13. try
  14. {
  15. if (disposing)
  16. {
  17. }
  18. if (IsEnabledDispose)
  19. {
  20. if (nativeObj != IntPtr.Zero)
  21. objdetect_QRCodeDetector_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. }
  25. finally
  26. {
  27. base.Dispose(disposing);
  28. }
  29. }
  30. protected internal QRCodeDetector(IntPtr addr) : base(addr) { }
  31. // internal usage only
  32. public static new QRCodeDetector __fromPtr__(IntPtr addr) { return new QRCodeDetector(addr); }
  33. //
  34. // C++: cv::QRCodeDetector::QRCodeDetector()
  35. //
  36. public QRCodeDetector() :
  37. base(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_QRCodeDetector_10()))
  38. {
  39. }
  40. //
  41. // C++: QRCodeDetector cv::QRCodeDetector::setEpsX(double epsX)
  42. //
  43. /**
  44. * sets the epsilon used during the horizontal scan of QR code stop marker detection.
  45. * param epsX Epsilon neighborhood, which allows you to determine the horizontal pattern
  46. * of the scheme 1:1:3:1:1 according to QR code standard.
  47. * return automatically generated
  48. */
  49. public QRCodeDetector setEpsX(double epsX)
  50. {
  51. ThrowIfDisposed();
  52. return new QRCodeDetector(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_setEpsX_10(nativeObj, epsX)));
  53. }
  54. //
  55. // C++: QRCodeDetector cv::QRCodeDetector::setEpsY(double epsY)
  56. //
  57. /**
  58. * sets the epsilon used during the vertical scan of QR code stop marker detection.
  59. * param epsY Epsilon neighborhood, which allows you to determine the vertical pattern
  60. * of the scheme 1:1:3:1:1 according to QR code standard.
  61. * return automatically generated
  62. */
  63. public QRCodeDetector setEpsY(double epsY)
  64. {
  65. ThrowIfDisposed();
  66. return new QRCodeDetector(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_setEpsY_10(nativeObj, epsY)));
  67. }
  68. //
  69. // C++: QRCodeDetector cv::QRCodeDetector::setUseAlignmentMarkers(bool useAlignmentMarkers)
  70. //
  71. /**
  72. * use markers to improve the position of the corners of the QR code
  73. *
  74. * alignmentMarkers using by default
  75. * param useAlignmentMarkers automatically generated
  76. * return automatically generated
  77. */
  78. public QRCodeDetector setUseAlignmentMarkers(bool useAlignmentMarkers)
  79. {
  80. ThrowIfDisposed();
  81. return new QRCodeDetector(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_setUseAlignmentMarkers_10(nativeObj, useAlignmentMarkers)));
  82. }
  83. //
  84. // C++: String cv::QRCodeDetector::decodeCurved(Mat img, Mat points, Mat& straight_qrcode = Mat())
  85. //
  86. /**
  87. * Decodes QR code on a curved surface in image once it's found by the detect() method.
  88. *
  89. * Returns UTF8-encoded output string or empty string if the code cannot be decoded.
  90. * param img grayscale or color (BGR) image containing QR code.
  91. * param points Quadrangle vertices found by detect() method (or some other algorithm).
  92. * param straight_qrcode The optional output image containing rectified and binarized QR code
  93. * return automatically generated
  94. */
  95. public string decodeCurved(Mat img, Mat points, Mat straight_qrcode)
  96. {
  97. ThrowIfDisposed();
  98. if (img != null) img.ThrowIfDisposed();
  99. if (points != null) points.ThrowIfDisposed();
  100. if (straight_qrcode != null) straight_qrcode.ThrowIfDisposed();
  101. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_decodeCurved_10(nativeObj, img.nativeObj, points.nativeObj, straight_qrcode.nativeObj)));
  102. return retVal;
  103. }
  104. /**
  105. * Decodes QR code on a curved surface in image once it's found by the detect() method.
  106. *
  107. * Returns UTF8-encoded output string or empty string if the code cannot be decoded.
  108. * param img grayscale or color (BGR) image containing QR code.
  109. * param points Quadrangle vertices found by detect() method (or some other algorithm).
  110. * return automatically generated
  111. */
  112. public string decodeCurved(Mat img, Mat points)
  113. {
  114. ThrowIfDisposed();
  115. if (img != null) img.ThrowIfDisposed();
  116. if (points != null) points.ThrowIfDisposed();
  117. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_decodeCurved_11(nativeObj, img.nativeObj, points.nativeObj)));
  118. return retVal;
  119. }
  120. //
  121. // C++: string cv::QRCodeDetector::detectAndDecodeCurved(Mat img, Mat& points = Mat(), Mat& straight_qrcode = Mat())
  122. //
  123. /**
  124. * Both detects and decodes QR code on a curved surface
  125. *
  126. * param img grayscale or color (BGR) image containing QR code.
  127. * param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found.
  128. * param straight_qrcode The optional output image containing rectified and binarized QR code
  129. * return automatically generated
  130. */
  131. public string detectAndDecodeCurved(Mat img, Mat points, Mat straight_qrcode)
  132. {
  133. ThrowIfDisposed();
  134. if (img != null) img.ThrowIfDisposed();
  135. if (points != null) points.ThrowIfDisposed();
  136. if (straight_qrcode != null) straight_qrcode.ThrowIfDisposed();
  137. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_detectAndDecodeCurved_10(nativeObj, img.nativeObj, points.nativeObj, straight_qrcode.nativeObj)));
  138. return retVal;
  139. }
  140. /**
  141. * Both detects and decodes QR code on a curved surface
  142. *
  143. * param img grayscale or color (BGR) image containing QR code.
  144. * param points optional output array of vertices of the found QR code quadrangle. Will be empty if not found.
  145. * return automatically generated
  146. */
  147. public string detectAndDecodeCurved(Mat img, Mat points)
  148. {
  149. ThrowIfDisposed();
  150. if (img != null) img.ThrowIfDisposed();
  151. if (points != null) points.ThrowIfDisposed();
  152. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_detectAndDecodeCurved_11(nativeObj, img.nativeObj, points.nativeObj)));
  153. return retVal;
  154. }
  155. /**
  156. * Both detects and decodes QR code on a curved surface
  157. *
  158. * param img grayscale or color (BGR) image containing QR code.
  159. * return automatically generated
  160. */
  161. public string detectAndDecodeCurved(Mat img)
  162. {
  163. ThrowIfDisposed();
  164. if (img != null) img.ThrowIfDisposed();
  165. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeDetector_detectAndDecodeCurved_12(nativeObj, img.nativeObj)));
  166. return retVal;
  167. }
  168. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  169. const string LIBNAME = "__Internal";
  170. #else
  171. const string LIBNAME = "opencvforunity";
  172. #endif
  173. // C++: cv::QRCodeDetector::QRCodeDetector()
  174. [DllImport(LIBNAME)]
  175. private static extern IntPtr objdetect_QRCodeDetector_QRCodeDetector_10();
  176. // C++: QRCodeDetector cv::QRCodeDetector::setEpsX(double epsX)
  177. [DllImport(LIBNAME)]
  178. private static extern IntPtr objdetect_QRCodeDetector_setEpsX_10(IntPtr nativeObj, double epsX);
  179. // C++: QRCodeDetector cv::QRCodeDetector::setEpsY(double epsY)
  180. [DllImport(LIBNAME)]
  181. private static extern IntPtr objdetect_QRCodeDetector_setEpsY_10(IntPtr nativeObj, double epsY);
  182. // C++: QRCodeDetector cv::QRCodeDetector::setUseAlignmentMarkers(bool useAlignmentMarkers)
  183. [DllImport(LIBNAME)]
  184. private static extern IntPtr objdetect_QRCodeDetector_setUseAlignmentMarkers_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool useAlignmentMarkers);
  185. // C++: String cv::QRCodeDetector::decodeCurved(Mat img, Mat points, Mat& straight_qrcode = Mat())
  186. [DllImport(LIBNAME)]
  187. private static extern IntPtr objdetect_QRCodeDetector_decodeCurved_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj, IntPtr straight_qrcode_nativeObj);
  188. [DllImport(LIBNAME)]
  189. private static extern IntPtr objdetect_QRCodeDetector_decodeCurved_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj);
  190. // C++: string cv::QRCodeDetector::detectAndDecodeCurved(Mat img, Mat& points = Mat(), Mat& straight_qrcode = Mat())
  191. [DllImport(LIBNAME)]
  192. private static extern IntPtr objdetect_QRCodeDetector_detectAndDecodeCurved_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj, IntPtr straight_qrcode_nativeObj);
  193. [DllImport(LIBNAME)]
  194. private static extern IntPtr objdetect_QRCodeDetector_detectAndDecodeCurved_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj);
  195. [DllImport(LIBNAME)]
  196. private static extern IntPtr objdetect_QRCodeDetector_detectAndDecodeCurved_12(IntPtr nativeObj, IntPtr img_nativeObj);
  197. // native support for java finalize()
  198. [DllImport(LIBNAME)]
  199. private static extern void objdetect_QRCodeDetector_delete(IntPtr nativeObj);
  200. }
  201. }