legacy_MultiTracker.cs 5.3 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.TrackingModule
  7. {
  8. // C++: class MultiTracker
  9. /**
  10. * This class is used to track multiple objects using the specified tracker algorithm.
  11. *
  12. * The %MultiTracker is naive implementation of multiple object tracking.
  13. * It process the tracked objects independently without any optimization accross the tracked objects.
  14. */
  15. public class legacy_MultiTracker : Algorithm
  16. {
  17. protected override void Dispose(bool disposing)
  18. {
  19. try
  20. {
  21. if (disposing)
  22. {
  23. }
  24. if (IsEnabledDispose)
  25. {
  26. if (nativeObj != IntPtr.Zero)
  27. tracking_legacy_1MultiTracker_delete(nativeObj);
  28. nativeObj = IntPtr.Zero;
  29. }
  30. }
  31. finally
  32. {
  33. base.Dispose(disposing);
  34. }
  35. }
  36. protected internal legacy_MultiTracker(IntPtr addr) : base(addr) { }
  37. // internal usage only
  38. public static new legacy_MultiTracker __fromPtr__(IntPtr addr) { return new legacy_MultiTracker(addr); }
  39. //
  40. // C++: cv::legacy::MultiTracker::MultiTracker()
  41. //
  42. /**
  43. * Constructor.
  44. */
  45. public legacy_MultiTracker() :
  46. base(DisposableObject.ThrowIfNullIntPtr(tracking_legacy_1MultiTracker_legacy_1MultiTracker_10()))
  47. {
  48. }
  49. //
  50. // C++: bool cv::legacy::MultiTracker::add(Ptr_legacy_Tracker newTracker, Mat image, Rect2d boundingBox)
  51. //
  52. /**
  53. * Add a new object to be tracked.
  54. *
  55. * param newTracker tracking algorithm to be used
  56. * param image input image
  57. * param boundingBox a rectangle represents ROI of the tracked object
  58. * return automatically generated
  59. */
  60. public bool add(legacy_Tracker newTracker, Mat image, Rect2d boundingBox)
  61. {
  62. ThrowIfDisposed();
  63. if (newTracker != null) newTracker.ThrowIfDisposed();
  64. if (image != null) image.ThrowIfDisposed();
  65. return tracking_legacy_1MultiTracker_add_10(nativeObj, newTracker.getNativeObjAddr(), image.nativeObj, boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
  66. }
  67. //
  68. // C++: bool cv::legacy::MultiTracker::update(Mat image, vector_Rect2d& boundingBox)
  69. //
  70. /**
  71. * Update the current tracking status.
  72. * param image input image
  73. * param boundingBox the tracking result, represent a list of ROIs of the tracked objects.
  74. * return automatically generated
  75. */
  76. public bool update(Mat image, MatOfRect2d boundingBox)
  77. {
  78. ThrowIfDisposed();
  79. if (image != null) image.ThrowIfDisposed();
  80. if (boundingBox != null) boundingBox.ThrowIfDisposed();
  81. Mat boundingBox_mat = boundingBox;
  82. return tracking_legacy_1MultiTracker_update_10(nativeObj, image.nativeObj, boundingBox_mat.nativeObj);
  83. }
  84. //
  85. // C++: vector_Rect2d cv::legacy::MultiTracker::getObjects()
  86. //
  87. /**
  88. * Returns a reference to a storage for the tracked objects, each object corresponds to one tracker algorithm
  89. * return automatically generated
  90. */
  91. public MatOfRect2d getObjects()
  92. {
  93. ThrowIfDisposed();
  94. return MatOfRect2d.fromNativeAddr(DisposableObject.ThrowIfNullIntPtr(tracking_legacy_1MultiTracker_getObjects_10(nativeObj)));
  95. }
  96. //
  97. // C++: static Ptr_MultiTracker cv::legacy::MultiTracker::create()
  98. //
  99. // Return type 'Ptr_MultiTracker' is not supported, skipping the function
  100. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  101. const string LIBNAME = "__Internal";
  102. #else
  103. const string LIBNAME = "opencvforunity";
  104. #endif
  105. // C++: cv::legacy::MultiTracker::MultiTracker()
  106. [DllImport(LIBNAME)]
  107. private static extern IntPtr tracking_legacy_1MultiTracker_legacy_1MultiTracker_10();
  108. // C++: bool cv::legacy::MultiTracker::add(Ptr_legacy_Tracker newTracker, Mat image, Rect2d boundingBox)
  109. [DllImport(LIBNAME)]
  110. [return: MarshalAs(UnmanagedType.U1)]
  111. private static extern bool tracking_legacy_1MultiTracker_add_10(IntPtr nativeObj, IntPtr newTracker_nativeObj, IntPtr image_nativeObj, double boundingBox_x, double boundingBox_y, double boundingBox_width, double boundingBox_height);
  112. // C++: bool cv::legacy::MultiTracker::update(Mat image, vector_Rect2d& boundingBox)
  113. [DllImport(LIBNAME)]
  114. [return: MarshalAs(UnmanagedType.U1)]
  115. private static extern bool tracking_legacy_1MultiTracker_update_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr boundingBox_mat_nativeObj);
  116. // C++: vector_Rect2d cv::legacy::MultiTracker::getObjects()
  117. [DllImport(LIBNAME)]
  118. private static extern IntPtr tracking_legacy_1MultiTracker_getObjects_10(IntPtr nativeObj);
  119. // native support for java finalize()
  120. [DllImport(LIBNAME)]
  121. private static extern void tracking_legacy_1MultiTracker_delete(IntPtr nativeObj);
  122. }
  123. }