Tracker.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.TrackingModule
  8. {
  9. // C++: class Tracker
  10. //javadoc: Tracker
  11. public class Tracker : Algorithm
  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. tracking_Tracker_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal Tracker (IntPtr addr) : base (addr) { }
  32. // internal usage only
  33. public static new Tracker __fromPtr__ (IntPtr addr) { return new Tracker (addr); }
  34. //
  35. // C++: bool cv::Tracker::init(Mat image, Rect2d boundingBox)
  36. //
  37. //javadoc: Tracker::init(image, boundingBox)
  38. public bool init (Mat image, Rect2d boundingBox)
  39. {
  40. ThrowIfDisposed ();
  41. if (image != null) image.ThrowIfDisposed ();
  42. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  43. bool retVal = tracking_Tracker_init_10(nativeObj, image.nativeObj, boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
  44. return retVal;
  45. #else
  46. return false;
  47. #endif
  48. }
  49. //
  50. // C++: bool cv::Tracker::update(Mat image, Rect2d& boundingBox)
  51. //
  52. //javadoc: Tracker::update(image, boundingBox)
  53. public bool update (Mat image, Rect2d boundingBox)
  54. {
  55. ThrowIfDisposed ();
  56. if (image != null) image.ThrowIfDisposed ();
  57. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  58. double[] boundingBox_out = new double[4];
  59. bool retVal = tracking_Tracker_update_10(nativeObj, image.nativeObj, boundingBox_out);
  60. if(boundingBox!=null){ boundingBox.x = boundingBox_out[0]; boundingBox.y = boundingBox_out[1]; boundingBox.width = boundingBox_out[2]; boundingBox.height = boundingBox_out[3]; }
  61. return retVal;
  62. #else
  63. return false;
  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++: bool cv::Tracker::init(Mat image, Rect2d boundingBox)
  72. [DllImport (LIBNAME)]
  73. private static extern bool tracking_Tracker_init_10 (IntPtr nativeObj, IntPtr image_nativeObj, double boundingBox_x, double boundingBox_y, double boundingBox_width, double boundingBox_height);
  74. // C++: bool cv::Tracker::update(Mat image, Rect2d& boundingBox)
  75. [DllImport (LIBNAME)]
  76. private static extern bool tracking_Tracker_update_10 (IntPtr nativeObj, IntPtr image_nativeObj, double[] boundingBox_out);
  77. // native support for java finalize()
  78. [DllImport (LIBNAME)]
  79. private static extern void tracking_Tracker_delete (IntPtr nativeObj);
  80. }
  81. }