TrackerGOTURN.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.VideoModule
  7. {
  8. // C++: class TrackerGOTURN
  9. /**
  10. * the GOTURN (Generic Object Tracking Using Regression Networks) tracker
  11. *
  12. * GOTURN (CITE: GOTURN) is kind of trackers based on Convolutional Neural Networks (CNN). While taking all advantages of CNN trackers,
  13. * GOTURN is much faster due to offline training without online fine-tuning nature.
  14. * GOTURN tracker addresses the problem of single target tracking: given a bounding box label of an object in the first frame of the video,
  15. * we track that object through the rest of the video. NOTE: Current method of GOTURN does not handle occlusions; however, it is fairly
  16. * robust to viewpoint changes, lighting changes, and deformations.
  17. * Inputs of GOTURN are two RGB patches representing Target and Search patches resized to 227x227.
  18. * Outputs of GOTURN are predicted bounding box coordinates, relative to Search patch coordinate system, in format X1,Y1,X2,Y2.
  19. * Original paper is here: <http://davheld.github.io/GOTURN/GOTURN.pdf>
  20. * As long as original authors implementation: <https://github.com/davheld/GOTURN#train-the-tracker>
  21. * Implementation of training algorithm is placed in separately here due to 3d-party dependencies:
  22. * <https://github.com/Auron-X/GOTURN_Training_Toolkit>
  23. * GOTURN architecture goturn.prototxt and trained model goturn.caffemodel are accessible on opencv_extra GitHub repository.
  24. */
  25. public class TrackerGOTURN : Tracker
  26. {
  27. protected override void Dispose(bool disposing)
  28. {
  29. try
  30. {
  31. if (disposing)
  32. {
  33. }
  34. if (IsEnabledDispose)
  35. {
  36. if (nativeObj != IntPtr.Zero)
  37. video_TrackerGOTURN_delete(nativeObj);
  38. nativeObj = IntPtr.Zero;
  39. }
  40. }
  41. finally
  42. {
  43. base.Dispose(disposing);
  44. }
  45. }
  46. protected internal TrackerGOTURN(IntPtr addr) : base(addr) { }
  47. // internal usage only
  48. public static new TrackerGOTURN __fromPtr__(IntPtr addr) { return new TrackerGOTURN(addr); }
  49. //
  50. // C++: static Ptr_TrackerGOTURN cv::TrackerGOTURN::create(TrackerGOTURN_Params parameters = TrackerGOTURN::Params())
  51. //
  52. /**
  53. * Constructor
  54. * param parameters GOTURN parameters TrackerGOTURN::Params
  55. * return automatically generated
  56. */
  57. public static TrackerGOTURN create(TrackerGOTURN_Params parameters)
  58. {
  59. if (parameters != null) parameters.ThrowIfDisposed();
  60. return TrackerGOTURN.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(video_TrackerGOTURN_create_10(parameters.nativeObj)));
  61. }
  62. /**
  63. * Constructor
  64. * return automatically generated
  65. */
  66. public static TrackerGOTURN create()
  67. {
  68. return TrackerGOTURN.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(video_TrackerGOTURN_create_11()));
  69. }
  70. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  71. const string LIBNAME = "__Internal";
  72. #else
  73. const string LIBNAME = "opencvforunity";
  74. #endif
  75. // C++: static Ptr_TrackerGOTURN cv::TrackerGOTURN::create(TrackerGOTURN_Params parameters = TrackerGOTURN::Params())
  76. [DllImport(LIBNAME)]
  77. private static extern IntPtr video_TrackerGOTURN_create_10(IntPtr parameters_nativeObj);
  78. [DllImport(LIBNAME)]
  79. private static extern IntPtr video_TrackerGOTURN_create_11();
  80. // native support for java finalize()
  81. [DllImport(LIBNAME)]
  82. private static extern void video_TrackerGOTURN_delete(IntPtr nativeObj);
  83. }
  84. }