TextDetector.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. /**
  11. * An abstract class providing interface for text detection algorithms
  12. */
  13. public class TextDetector : DisposableOpenCVObject
  14. {
  15. protected override void Dispose(bool disposing)
  16. {
  17. try
  18. {
  19. if (disposing)
  20. {
  21. }
  22. if (IsEnabledDispose)
  23. {
  24. if (nativeObj != IntPtr.Zero)
  25. text_TextDetector_delete(nativeObj);
  26. nativeObj = IntPtr.Zero;
  27. }
  28. }
  29. finally
  30. {
  31. base.Dispose(disposing);
  32. }
  33. }
  34. protected internal TextDetector(IntPtr addr) : base(addr) { }
  35. public IntPtr getNativeObjAddr() { return nativeObj; }
  36. // internal usage only
  37. public static TextDetector __fromPtr__(IntPtr addr) { return new TextDetector(addr); }
  38. //
  39. // C++: void cv::text::TextDetector::detect(Mat inputImage, vector_Rect& Bbox, vector_float& confidence)
  40. //
  41. /**
  42. * Method that provides a quick and simple interface to detect text inside an image
  43. *
  44. * param inputImage an image to process
  45. * param Bbox a vector of Rect that will store the detected word bounding box
  46. * param confidence a vector of float that will be updated with the confidence the classifier has for the selected bounding box
  47. */
  48. public virtual void detect(Mat inputImage, MatOfRect Bbox, MatOfFloat confidence)
  49. {
  50. ThrowIfDisposed();
  51. if (inputImage != null) inputImage.ThrowIfDisposed();
  52. if (Bbox != null) Bbox.ThrowIfDisposed();
  53. if (confidence != null) confidence.ThrowIfDisposed();
  54. Mat Bbox_mat = Bbox;
  55. Mat confidence_mat = confidence;
  56. text_TextDetector_detect_10(nativeObj, inputImage.nativeObj, Bbox_mat.nativeObj, confidence_mat.nativeObj);
  57. }
  58. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  59. const string LIBNAME = "__Internal";
  60. #else
  61. const string LIBNAME = "opencvforunity";
  62. #endif
  63. // C++: void cv::text::TextDetector::detect(Mat inputImage, vector_Rect& Bbox, vector_float& confidence)
  64. [DllImport(LIBNAME)]
  65. private static extern void text_TextDetector_detect_10(IntPtr nativeObj, IntPtr inputImage_nativeObj, IntPtr Bbox_mat_nativeObj, IntPtr confidence_mat_nativeObj);
  66. // native support for java finalize()
  67. [DllImport(LIBNAME)]
  68. private static extern void text_TextDetector_delete(IntPtr nativeObj);
  69. }
  70. }
  71. #endif