TextDetector.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. #if !UNITY_WSA_10_0
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.TextModule
  8. {
  9. // C++: class TextDetector
  10. //javadoc: TextDetector
  11. public class TextDetector : DisposableOpenCVObject
  12. {
  13. protected override void Dispose (bool disposing)
  14. {
  15. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  16. try {
  17. if (disposing) {
  18. }
  19. if (IsEnabledDispose) {
  20. if (nativeObj != IntPtr.Zero)
  21. text_TextDetector_delete (nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal TextDetector (IntPtr addr)
  32. : base (addr)
  33. {
  34. }
  35. public IntPtr getNativeObjAddr ()
  36. {
  37. return nativeObj;
  38. }
  39. // internal usage only
  40. public static TextDetector __fromPtr__ (IntPtr addr)
  41. {
  42. return new TextDetector (addr);
  43. }
  44. //
  45. // C++: void cv::text::TextDetector::detect(Mat inputImage, vector_Rect& Bbox, vector_float& confidence)
  46. //
  47. //javadoc: TextDetector::detect(inputImage, Bbox, confidence)
  48. public virtual void detect (Mat inputImage, MatOfRect Bbox, MatOfFloat confidence)
  49. {
  50. ThrowIfDisposed ();
  51. if (inputImage != null)
  52. inputImage.ThrowIfDisposed ();
  53. if (Bbox != null)
  54. Bbox.ThrowIfDisposed ();
  55. if (confidence != null)
  56. confidence.ThrowIfDisposed ();
  57. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  58. Mat Bbox_mat = Bbox;
  59. Mat confidence_mat = confidence;
  60. text_TextDetector_detect_10 (nativeObj, inputImage.nativeObj, Bbox_mat.nativeObj, confidence_mat.nativeObj);
  61. return;
  62. #else
  63. return;
  64. #endif
  65. }
  66. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  67. const string LIBNAME = "__Internal";
  68. #else
  69. const string LIBNAME = "opencvforunity";
  70. #endif
  71. // C++: void cv::text::TextDetector::detect(Mat inputImage, vector_Rect& Bbox, vector_float& confidence)
  72. [DllImport (LIBNAME)]
  73. private static extern void text_TextDetector_detect_10 (IntPtr nativeObj, IntPtr inputImage_nativeObj, IntPtr Bbox_mat_nativeObj, IntPtr confidence_mat_nativeObj);
  74. // native support for java finalize()
  75. [DllImport (LIBNAME)]
  76. private static extern void text_TextDetector_delete (IntPtr nativeObj);
  77. }
  78. }
  79. #endif