GraphicalCodeDetector.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 GraphicalCodeDetector
  9. public class GraphicalCodeDetector : DisposableOpenCVObject
  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_GraphicalCodeDetector_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. }
  25. finally
  26. {
  27. base.Dispose(disposing);
  28. }
  29. }
  30. protected internal GraphicalCodeDetector(IntPtr addr) : base(addr) { }
  31. public IntPtr getNativeObjAddr() { return nativeObj; }
  32. // internal usage only
  33. public static GraphicalCodeDetector __fromPtr__(IntPtr addr) { return new GraphicalCodeDetector(addr); }
  34. //
  35. // C++: bool cv::GraphicalCodeDetector::detect(Mat img, Mat& points)
  36. //
  37. /**
  38. * Detects graphical code in image and returns the quadrangle containing the code.
  39. * param img grayscale or color (BGR) image containing (or not) graphical code.
  40. * param points Output vector of vertices of the minimum-area quadrangle containing the code.
  41. * return automatically generated
  42. */
  43. public bool detect(Mat img, Mat points)
  44. {
  45. ThrowIfDisposed();
  46. if (img != null) img.ThrowIfDisposed();
  47. if (points != null) points.ThrowIfDisposed();
  48. return objdetect_GraphicalCodeDetector_detect_10(nativeObj, img.nativeObj, points.nativeObj);
  49. }
  50. //
  51. // C++: string cv::GraphicalCodeDetector::decode(Mat img, Mat points, Mat& straight_code = Mat())
  52. //
  53. /**
  54. * Decodes graphical code in image once it's found by the detect() method.
  55. *
  56. * Returns UTF8-encoded output string or empty string if the code cannot be decoded.
  57. * param img grayscale or color (BGR) image containing graphical code.
  58. * param points Quadrangle vertices found by detect() method (or some other algorithm).
  59. * param straight_code The optional output image containing binarized code, will be empty if not found.
  60. * return automatically generated
  61. */
  62. public string decode(Mat img, Mat points, Mat straight_code)
  63. {
  64. ThrowIfDisposed();
  65. if (img != null) img.ThrowIfDisposed();
  66. if (points != null) points.ThrowIfDisposed();
  67. if (straight_code != null) straight_code.ThrowIfDisposed();
  68. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_GraphicalCodeDetector_decode_10(nativeObj, img.nativeObj, points.nativeObj, straight_code.nativeObj)));
  69. return retVal;
  70. }
  71. /**
  72. * Decodes graphical code in image once it's found by the detect() method.
  73. *
  74. * Returns UTF8-encoded output string or empty string if the code cannot be decoded.
  75. * param img grayscale or color (BGR) image containing graphical code.
  76. * param points Quadrangle vertices found by detect() method (or some other algorithm).
  77. * return automatically generated
  78. */
  79. public string decode(Mat img, Mat points)
  80. {
  81. ThrowIfDisposed();
  82. if (img != null) img.ThrowIfDisposed();
  83. if (points != null) points.ThrowIfDisposed();
  84. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_GraphicalCodeDetector_decode_11(nativeObj, img.nativeObj, points.nativeObj)));
  85. return retVal;
  86. }
  87. //
  88. // C++: string cv::GraphicalCodeDetector::detectAndDecode(Mat img, Mat& points = Mat(), Mat& straight_code = Mat())
  89. //
  90. /**
  91. * Both detects and decodes graphical code
  92. *
  93. * param img grayscale or color (BGR) image containing graphical code.
  94. * param points optional output array of vertices of the found graphical code quadrangle, will be empty if not found.
  95. * param straight_code The optional output image containing binarized code
  96. * return automatically generated
  97. */
  98. public string detectAndDecode(Mat img, Mat points, Mat straight_code)
  99. {
  100. ThrowIfDisposed();
  101. if (img != null) img.ThrowIfDisposed();
  102. if (points != null) points.ThrowIfDisposed();
  103. if (straight_code != null) straight_code.ThrowIfDisposed();
  104. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_GraphicalCodeDetector_detectAndDecode_10(nativeObj, img.nativeObj, points.nativeObj, straight_code.nativeObj)));
  105. return retVal;
  106. }
  107. /**
  108. * Both detects and decodes graphical code
  109. *
  110. * param img grayscale or color (BGR) image containing graphical code.
  111. * param points optional output array of vertices of the found graphical code quadrangle, will be empty if not found.
  112. * return automatically generated
  113. */
  114. public string detectAndDecode(Mat img, Mat points)
  115. {
  116. ThrowIfDisposed();
  117. if (img != null) img.ThrowIfDisposed();
  118. if (points != null) points.ThrowIfDisposed();
  119. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_GraphicalCodeDetector_detectAndDecode_11(nativeObj, img.nativeObj, points.nativeObj)));
  120. return retVal;
  121. }
  122. /**
  123. * Both detects and decodes graphical code
  124. *
  125. * param img grayscale or color (BGR) image containing graphical code.
  126. * return automatically generated
  127. */
  128. public string detectAndDecode(Mat img)
  129. {
  130. ThrowIfDisposed();
  131. if (img != null) img.ThrowIfDisposed();
  132. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(objdetect_GraphicalCodeDetector_detectAndDecode_12(nativeObj, img.nativeObj)));
  133. return retVal;
  134. }
  135. //
  136. // C++: bool cv::GraphicalCodeDetector::detectMulti(Mat img, Mat& points)
  137. //
  138. /**
  139. * Detects graphical codes in image and returns the vector of the quadrangles containing the codes.
  140. * param img grayscale or color (BGR) image containing (or not) graphical codes.
  141. * param points Output vector of vector of vertices of the minimum-area quadrangle containing the codes.
  142. * return automatically generated
  143. */
  144. public bool detectMulti(Mat img, Mat points)
  145. {
  146. ThrowIfDisposed();
  147. if (img != null) img.ThrowIfDisposed();
  148. if (points != null) points.ThrowIfDisposed();
  149. return objdetect_GraphicalCodeDetector_detectMulti_10(nativeObj, img.nativeObj, points.nativeObj);
  150. }
  151. //
  152. // C++: bool cv::GraphicalCodeDetector::decodeMulti(Mat img, Mat points, vector_string& decoded_info, vector_Mat& straight_code = vector_Mat())
  153. //
  154. /**
  155. * Decodes graphical codes in image once it's found by the detect() method.
  156. * param img grayscale or color (BGR) image containing graphical codes.
  157. * param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  158. * param points vector of Quadrangle vertices found by detect() method (or some other algorithm).
  159. * param straight_code The optional output vector of images containing binarized codes
  160. * return automatically generated
  161. */
  162. public bool decodeMulti(Mat img, Mat points, List<string> decoded_info, List<Mat> straight_code)
  163. {
  164. ThrowIfDisposed();
  165. if (img != null) img.ThrowIfDisposed();
  166. if (points != null) points.ThrowIfDisposed();
  167. Mat decoded_info_mat = new Mat();
  168. Mat straight_code_mat = new Mat();
  169. bool retVal = objdetect_GraphicalCodeDetector_decodeMulti_10(nativeObj, img.nativeObj, points.nativeObj, decoded_info_mat.nativeObj, straight_code_mat.nativeObj);
  170. Converters.Mat_to_vector_string(decoded_info_mat, decoded_info);
  171. decoded_info_mat.release();
  172. Converters.Mat_to_vector_Mat(straight_code_mat, straight_code);
  173. straight_code_mat.release();
  174. return retVal;
  175. }
  176. /**
  177. * Decodes graphical codes in image once it's found by the detect() method.
  178. * param img grayscale or color (BGR) image containing graphical codes.
  179. * param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  180. * param points vector of Quadrangle vertices found by detect() method (or some other algorithm).
  181. * return automatically generated
  182. */
  183. public bool decodeMulti(Mat img, Mat points, List<string> decoded_info)
  184. {
  185. ThrowIfDisposed();
  186. if (img != null) img.ThrowIfDisposed();
  187. if (points != null) points.ThrowIfDisposed();
  188. Mat decoded_info_mat = new Mat();
  189. bool retVal = objdetect_GraphicalCodeDetector_decodeMulti_11(nativeObj, img.nativeObj, points.nativeObj, decoded_info_mat.nativeObj);
  190. Converters.Mat_to_vector_string(decoded_info_mat, decoded_info);
  191. decoded_info_mat.release();
  192. return retVal;
  193. }
  194. //
  195. // C++: bool cv::GraphicalCodeDetector::detectAndDecodeMulti(Mat img, vector_string& decoded_info, Mat& points = Mat(), vector_Mat& straight_code = vector_Mat())
  196. //
  197. /**
  198. * Both detects and decodes graphical codes
  199. * param img grayscale or color (BGR) image containing graphical codes.
  200. * param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  201. * param points optional output vector of vertices of the found graphical code quadrangles. Will be empty if not found.
  202. * param straight_code The optional vector of images containing binarized codes
  203. * return automatically generated
  204. */
  205. public bool detectAndDecodeMulti(Mat img, List<string> decoded_info, Mat points, List<Mat> straight_code)
  206. {
  207. ThrowIfDisposed();
  208. if (img != null) img.ThrowIfDisposed();
  209. if (points != null) points.ThrowIfDisposed();
  210. Mat decoded_info_mat = new Mat();
  211. Mat straight_code_mat = new Mat();
  212. bool retVal = objdetect_GraphicalCodeDetector_detectAndDecodeMulti_10(nativeObj, img.nativeObj, decoded_info_mat.nativeObj, points.nativeObj, straight_code_mat.nativeObj);
  213. Converters.Mat_to_vector_string(decoded_info_mat, decoded_info);
  214. decoded_info_mat.release();
  215. Converters.Mat_to_vector_Mat(straight_code_mat, straight_code);
  216. straight_code_mat.release();
  217. return retVal;
  218. }
  219. /**
  220. * Both detects and decodes graphical codes
  221. * param img grayscale or color (BGR) image containing graphical codes.
  222. * param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  223. * param points optional output vector of vertices of the found graphical code quadrangles. Will be empty if not found.
  224. * return automatically generated
  225. */
  226. public bool detectAndDecodeMulti(Mat img, List<string> decoded_info, Mat points)
  227. {
  228. ThrowIfDisposed();
  229. if (img != null) img.ThrowIfDisposed();
  230. if (points != null) points.ThrowIfDisposed();
  231. Mat decoded_info_mat = new Mat();
  232. bool retVal = objdetect_GraphicalCodeDetector_detectAndDecodeMulti_11(nativeObj, img.nativeObj, decoded_info_mat.nativeObj, points.nativeObj);
  233. Converters.Mat_to_vector_string(decoded_info_mat, decoded_info);
  234. decoded_info_mat.release();
  235. return retVal;
  236. }
  237. /**
  238. * Both detects and decodes graphical codes
  239. * param img grayscale or color (BGR) image containing graphical codes.
  240. * param decoded_info UTF8-encoded output vector of string or empty vector of string if the codes cannot be decoded.
  241. * return automatically generated
  242. */
  243. public bool detectAndDecodeMulti(Mat img, List<string> decoded_info)
  244. {
  245. ThrowIfDisposed();
  246. if (img != null) img.ThrowIfDisposed();
  247. Mat decoded_info_mat = new Mat();
  248. bool retVal = objdetect_GraphicalCodeDetector_detectAndDecodeMulti_12(nativeObj, img.nativeObj, decoded_info_mat.nativeObj);
  249. Converters.Mat_to_vector_string(decoded_info_mat, decoded_info);
  250. decoded_info_mat.release();
  251. return retVal;
  252. }
  253. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  254. const string LIBNAME = "__Internal";
  255. #else
  256. const string LIBNAME = "opencvforunity";
  257. #endif
  258. // C++: bool cv::GraphicalCodeDetector::detect(Mat img, Mat& points)
  259. [DllImport(LIBNAME)]
  260. [return: MarshalAs(UnmanagedType.U1)]
  261. private static extern bool objdetect_GraphicalCodeDetector_detect_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj);
  262. // C++: string cv::GraphicalCodeDetector::decode(Mat img, Mat points, Mat& straight_code = Mat())
  263. [DllImport(LIBNAME)]
  264. private static extern IntPtr objdetect_GraphicalCodeDetector_decode_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj, IntPtr straight_code_nativeObj);
  265. [DllImport(LIBNAME)]
  266. private static extern IntPtr objdetect_GraphicalCodeDetector_decode_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj);
  267. // C++: string cv::GraphicalCodeDetector::detectAndDecode(Mat img, Mat& points = Mat(), Mat& straight_code = Mat())
  268. [DllImport(LIBNAME)]
  269. private static extern IntPtr objdetect_GraphicalCodeDetector_detectAndDecode_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj, IntPtr straight_code_nativeObj);
  270. [DllImport(LIBNAME)]
  271. private static extern IntPtr objdetect_GraphicalCodeDetector_detectAndDecode_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj);
  272. [DllImport(LIBNAME)]
  273. private static extern IntPtr objdetect_GraphicalCodeDetector_detectAndDecode_12(IntPtr nativeObj, IntPtr img_nativeObj);
  274. // C++: bool cv::GraphicalCodeDetector::detectMulti(Mat img, Mat& points)
  275. [DllImport(LIBNAME)]
  276. [return: MarshalAs(UnmanagedType.U1)]
  277. private static extern bool objdetect_GraphicalCodeDetector_detectMulti_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj);
  278. // C++: bool cv::GraphicalCodeDetector::decodeMulti(Mat img, Mat points, vector_string& decoded_info, vector_Mat& straight_code = vector_Mat())
  279. [DllImport(LIBNAME)]
  280. [return: MarshalAs(UnmanagedType.U1)]
  281. private static extern bool objdetect_GraphicalCodeDetector_decodeMulti_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj, IntPtr decoded_info_mat_nativeObj, IntPtr straight_code_mat_nativeObj);
  282. [DllImport(LIBNAME)]
  283. [return: MarshalAs(UnmanagedType.U1)]
  284. private static extern bool objdetect_GraphicalCodeDetector_decodeMulti_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr points_nativeObj, IntPtr decoded_info_mat_nativeObj);
  285. // C++: bool cv::GraphicalCodeDetector::detectAndDecodeMulti(Mat img, vector_string& decoded_info, Mat& points = Mat(), vector_Mat& straight_code = vector_Mat())
  286. [DllImport(LIBNAME)]
  287. [return: MarshalAs(UnmanagedType.U1)]
  288. private static extern bool objdetect_GraphicalCodeDetector_detectAndDecodeMulti_10(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr decoded_info_mat_nativeObj, IntPtr points_nativeObj, IntPtr straight_code_mat_nativeObj);
  289. [DllImport(LIBNAME)]
  290. [return: MarshalAs(UnmanagedType.U1)]
  291. private static extern bool objdetect_GraphicalCodeDetector_detectAndDecodeMulti_11(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr decoded_info_mat_nativeObj, IntPtr points_nativeObj);
  292. [DllImport(LIBNAME)]
  293. [return: MarshalAs(UnmanagedType.U1)]
  294. private static extern bool objdetect_GraphicalCodeDetector_detectAndDecodeMulti_12(IntPtr nativeObj, IntPtr img_nativeObj, IntPtr decoded_info_mat_nativeObj);
  295. // native support for java finalize()
  296. [DllImport(LIBNAME)]
  297. private static extern void objdetect_GraphicalCodeDetector_delete(IntPtr nativeObj);
  298. }
  299. }