QRCodeEncoder.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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 QRCodeEncoder
  9. /**
  10. * Groups the object candidate rectangles.
  11. * rectList Input/output vector of rectangles. Output vector includes retained and grouped rectangles. (The Python list is not modified in place.)
  12. * weights Input/output vector of weights of rectangles. Output vector includes weights of retained and grouped rectangles. (The Python list is not modified in place.)
  13. * groupThreshold Minimum possible number of rectangles minus 1. The threshold is used in a group of rectangles to retain it.
  14. * eps Relative difference between sides of the rectangles to merge them into a group.
  15. */
  16. public class QRCodeEncoder : DisposableOpenCVObject
  17. {
  18. protected override void Dispose(bool disposing)
  19. {
  20. try
  21. {
  22. if (disposing)
  23. {
  24. }
  25. if (IsEnabledDispose)
  26. {
  27. if (nativeObj != IntPtr.Zero)
  28. objdetect_QRCodeEncoder_delete(nativeObj);
  29. nativeObj = IntPtr.Zero;
  30. }
  31. }
  32. finally
  33. {
  34. base.Dispose(disposing);
  35. }
  36. }
  37. protected internal QRCodeEncoder(IntPtr addr) : base(addr) { }
  38. public IntPtr getNativeObjAddr() { return nativeObj; }
  39. // internal usage only
  40. public static QRCodeEncoder __fromPtr__(IntPtr addr) { return new QRCodeEncoder(addr); }
  41. // C++: enum cv.QRCodeEncoder.CorrectionLevel
  42. public const int CORRECT_LEVEL_L = 0;
  43. public const int CORRECT_LEVEL_M = 1;
  44. public const int CORRECT_LEVEL_Q = 2;
  45. public const int CORRECT_LEVEL_H = 3;
  46. // C++: enum cv.QRCodeEncoder.ECIEncodings
  47. public const int ECI_UTF8 = 26;
  48. // C++: enum cv.QRCodeEncoder.EncodeMode
  49. public const int MODE_AUTO = -1;
  50. public const int MODE_NUMERIC = 1;
  51. public const int MODE_ALPHANUMERIC = 2;
  52. public const int MODE_BYTE = 4;
  53. public const int MODE_ECI = 7;
  54. public const int MODE_KANJI = 8;
  55. public const int MODE_STRUCTURED_APPEND = 3;
  56. //
  57. // C++: static Ptr_QRCodeEncoder cv::QRCodeEncoder::create(QRCodeEncoder_Params parameters = QRCodeEncoder::Params())
  58. //
  59. /**
  60. * Constructor
  61. * param parameters QR code encoder parameters QRCodeEncoder::Params
  62. * return automatically generated
  63. */
  64. public static QRCodeEncoder create(QRCodeEncoder_Params parameters)
  65. {
  66. if (parameters != null) parameters.ThrowIfDisposed();
  67. return QRCodeEncoder.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeEncoder_create_10(parameters.nativeObj)));
  68. }
  69. /**
  70. * Constructor
  71. * return automatically generated
  72. */
  73. public static QRCodeEncoder create()
  74. {
  75. return QRCodeEncoder.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(objdetect_QRCodeEncoder_create_11()));
  76. }
  77. //
  78. // C++: void cv::QRCodeEncoder::encode(String encoded_info, Mat& qrcode)
  79. //
  80. /**
  81. * Generates QR code from input string.
  82. * param encoded_info Input string to encode.
  83. * param qrcode Generated QR code.
  84. */
  85. public void encode(string encoded_info, Mat qrcode)
  86. {
  87. ThrowIfDisposed();
  88. if (qrcode != null) qrcode.ThrowIfDisposed();
  89. objdetect_QRCodeEncoder_encode_10(nativeObj, encoded_info, qrcode.nativeObj);
  90. }
  91. //
  92. // C++: void cv::QRCodeEncoder::encodeStructuredAppend(String encoded_info, vector_Mat& qrcodes)
  93. //
  94. /**
  95. * Generates QR code from input string in Structured Append mode. The encoded message is splitting over a number of QR codes.
  96. * param encoded_info Input string to encode.
  97. * param qrcodes Vector of generated QR codes.
  98. */
  99. public void encodeStructuredAppend(string encoded_info, List<Mat> qrcodes)
  100. {
  101. ThrowIfDisposed();
  102. Mat qrcodes_mat = new Mat();
  103. objdetect_QRCodeEncoder_encodeStructuredAppend_10(nativeObj, encoded_info, qrcodes_mat.nativeObj);
  104. Converters.Mat_to_vector_Mat(qrcodes_mat, qrcodes);
  105. qrcodes_mat.release();
  106. }
  107. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  108. const string LIBNAME = "__Internal";
  109. #else
  110. const string LIBNAME = "opencvforunity";
  111. #endif
  112. // C++: static Ptr_QRCodeEncoder cv::QRCodeEncoder::create(QRCodeEncoder_Params parameters = QRCodeEncoder::Params())
  113. [DllImport(LIBNAME)]
  114. private static extern IntPtr objdetect_QRCodeEncoder_create_10(IntPtr parameters_nativeObj);
  115. [DllImport(LIBNAME)]
  116. private static extern IntPtr objdetect_QRCodeEncoder_create_11();
  117. // C++: void cv::QRCodeEncoder::encode(String encoded_info, Mat& qrcode)
  118. [DllImport(LIBNAME)]
  119. private static extern void objdetect_QRCodeEncoder_encode_10(IntPtr nativeObj, string encoded_info, IntPtr qrcode_nativeObj);
  120. // C++: void cv::QRCodeEncoder::encodeStructuredAppend(String encoded_info, vector_Mat& qrcodes)
  121. [DllImport(LIBNAME)]
  122. private static extern void objdetect_QRCodeEncoder_encodeStructuredAppend_10(IntPtr nativeObj, string encoded_info, IntPtr qrcodes_mat_nativeObj);
  123. // native support for java finalize()
  124. [DllImport(LIBNAME)]
  125. private static extern void objdetect_QRCodeEncoder_delete(IntPtr nativeObj);
  126. }
  127. }