MultiTracker.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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 MultiTracker
  10. //javadoc: MultiTracker
  11. public class MultiTracker : 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_MultiTracker_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal MultiTracker (IntPtr addr) : base (addr) { }
  32. // internal usage only
  33. public static new MultiTracker __fromPtr__ (IntPtr addr) { return new MultiTracker (addr); }
  34. //
  35. // C++: cv::MultiTracker::MultiTracker()
  36. //
  37. //javadoc: MultiTracker::MultiTracker()
  38. public MultiTracker () :
  39. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  40. base( tracking_MultiTracker_MultiTracker_10() )
  41. #else
  42. base (IntPtr.Zero)
  43. #endif
  44. {
  45. return;
  46. }
  47. //
  48. // C++: static Ptr_MultiTracker cv::MultiTracker::create()
  49. //
  50. //javadoc: MultiTracker::create()
  51. public static MultiTracker create ()
  52. {
  53. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  54. MultiTracker retVal = MultiTracker.__fromPtr__(tracking_MultiTracker_create_10());
  55. return retVal;
  56. #else
  57. return null;
  58. #endif
  59. }
  60. //
  61. // C++: bool cv::MultiTracker::add(Ptr_Tracker newTracker, Mat image, Rect2d boundingBox)
  62. //
  63. //javadoc: MultiTracker::add(newTracker, image, boundingBox)
  64. public bool add (Tracker newTracker, Mat image, Rect2d boundingBox)
  65. {
  66. ThrowIfDisposed ();
  67. if (newTracker != null) newTracker.ThrowIfDisposed ();
  68. if (image != null) image.ThrowIfDisposed ();
  69. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  70. bool retVal = tracking_MultiTracker_add_10(nativeObj, newTracker.getNativeObjAddr(), image.nativeObj, boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height);
  71. return retVal;
  72. #else
  73. return false;
  74. #endif
  75. }
  76. //
  77. // C++: bool cv::MultiTracker::update(Mat image, vector_Rect2d& boundingBox)
  78. //
  79. //javadoc: MultiTracker::update(image, boundingBox)
  80. public bool update (Mat image, MatOfRect2d boundingBox)
  81. {
  82. ThrowIfDisposed ();
  83. if (image != null) image.ThrowIfDisposed ();
  84. if (boundingBox != null) boundingBox.ThrowIfDisposed ();
  85. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  86. Mat boundingBox_mat = boundingBox;
  87. bool retVal = tracking_MultiTracker_update_10(nativeObj, image.nativeObj, boundingBox_mat.nativeObj);
  88. return retVal;
  89. #else
  90. return false;
  91. #endif
  92. }
  93. //
  94. // C++: vector_Rect2d cv::MultiTracker::getObjects()
  95. //
  96. //javadoc: MultiTracker::getObjects()
  97. public MatOfRect2d getObjects ()
  98. {
  99. ThrowIfDisposed ();
  100. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  101. MatOfRect2d retVal = MatOfRect2d.fromNativeAddr(tracking_MultiTracker_getObjects_10(nativeObj));
  102. return retVal;
  103. #else
  104. return null;
  105. #endif
  106. }
  107. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  108. const string LIBNAME = "__Internal";
  109. #else
  110. const string LIBNAME = "opencvforunity";
  111. #endif
  112. // C++: cv::MultiTracker::MultiTracker()
  113. [DllImport (LIBNAME)]
  114. private static extern IntPtr tracking_MultiTracker_MultiTracker_10 ();
  115. // C++: static Ptr_MultiTracker cv::MultiTracker::create()
  116. [DllImport (LIBNAME)]
  117. private static extern IntPtr tracking_MultiTracker_create_10 ();
  118. // C++: bool cv::MultiTracker::add(Ptr_Tracker newTracker, Mat image, Rect2d boundingBox)
  119. [DllImport (LIBNAME)]
  120. private static extern bool tracking_MultiTracker_add_10 (IntPtr nativeObj, IntPtr newTracker_nativeObj, IntPtr image_nativeObj, double boundingBox_x, double boundingBox_y, double boundingBox_width, double boundingBox_height);
  121. // C++: bool cv::MultiTracker::update(Mat image, vector_Rect2d& boundingBox)
  122. [DllImport (LIBNAME)]
  123. private static extern bool tracking_MultiTracker_update_10 (IntPtr nativeObj, IntPtr image_nativeObj, IntPtr boundingBox_mat_nativeObj);
  124. // C++: vector_Rect2d cv::MultiTracker::getObjects()
  125. [DllImport (LIBNAME)]
  126. private static extern IntPtr tracking_MultiTracker_getObjects_10 (IntPtr nativeObj);
  127. // native support for java finalize()
  128. [DllImport (LIBNAME)]
  129. private static extern void tracking_MultiTracker_delete (IntPtr nativeObj);
  130. }
  131. }