TextDetector.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. // C++: class TextDetector
  9. //javadoc: TextDetector
  10. public class TextDetector : DisposableOpenCVObject {
  11. protected override void Dispose(bool disposing) {
  12. #if (UNITY_ANDROID && !UNITY_EDITOR)
  13. try {
  14. if (disposing) {
  15. }
  16. if (IsEnabledDispose) {
  17. if (nativeObj != IntPtr.Zero)
  18. text_TextDetector_delete(nativeObj);
  19. nativeObj = IntPtr.Zero;
  20. }
  21. } finally {
  22. base.Dispose(disposing);
  23. }
  24. #else
  25. return;
  26. #endif
  27. }
  28. protected internal TextDetector(IntPtr addr)
  29. : base(addr) {
  30. }
  31. public IntPtr getNativeObjAddr() {
  32. return nativeObj;
  33. }
  34. // internal usage only
  35. public static TextDetector __fromPtr__(IntPtr addr) {
  36. return new TextDetector(addr);
  37. }
  38. //
  39. // C++: void cv::text::TextDetector::detect(Mat inputImage, vector_Rect& Bbox, vector_float& confidence)
  40. //
  41. //javadoc: TextDetector::detect(inputImage, Bbox, confidence)
  42. public virtual void detect(Mat inputImage, MatOfRect Bbox, MatOfFloat confidence) {
  43. ThrowIfDisposed();
  44. if (inputImage != null)
  45. inputImage.ThrowIfDisposed();
  46. if (Bbox != null)
  47. Bbox.ThrowIfDisposed();
  48. if (confidence != null)
  49. confidence.ThrowIfDisposed();
  50. #if (UNITY_ANDROID && !UNITY_EDITOR)
  51. Mat Bbox_mat = Bbox;
  52. Mat confidence_mat = confidence;
  53. text_TextDetector_detect_10(nativeObj, inputImage.nativeObj, Bbox_mat.nativeObj, confidence_mat.nativeObj);
  54. return;
  55. #else
  56. return;
  57. #endif
  58. }
  59. #if (UNITY_ANDROID && !UNITY_EDITOR)
  60. const string LIBNAME = "opencvforunity";
  61. // C++: void cv::text::TextDetector::detect(Mat inputImage, vector_Rect& Bbox, vector_float& confidence)
  62. [DllImport(LIBNAME)]
  63. private static extern void text_TextDetector_detect_10(IntPtr nativeObj, IntPtr inputImage_nativeObj, IntPtr Bbox_mat_nativeObj, IntPtr confidence_mat_nativeObj);
  64. // native support for java finalize()
  65. [DllImport(LIBNAME)]
  66. private static extern void text_TextDetector_delete(IntPtr nativeObj);
  67. #endif
  68. }
  69. }
  70. #endif