SparseOpticalFlow.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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 SparseOpticalFlow
  9. /**
  10. * Base interface for sparse optical flow algorithms.
  11. */
  12. public class SparseOpticalFlow : Algorithm
  13. {
  14. protected override void Dispose(bool disposing)
  15. {
  16. try
  17. {
  18. if (disposing)
  19. {
  20. }
  21. if (IsEnabledDispose)
  22. {
  23. if (nativeObj != IntPtr.Zero)
  24. video_SparseOpticalFlow_delete(nativeObj);
  25. nativeObj = IntPtr.Zero;
  26. }
  27. }
  28. finally
  29. {
  30. base.Dispose(disposing);
  31. }
  32. }
  33. protected internal SparseOpticalFlow(IntPtr addr) : base(addr) { }
  34. // internal usage only
  35. public static new SparseOpticalFlow __fromPtr__(IntPtr addr) { return new SparseOpticalFlow(addr); }
  36. //
  37. // C++: void cv::SparseOpticalFlow::calc(Mat prevImg, Mat nextImg, Mat prevPts, Mat& nextPts, Mat& status, Mat& err = cv::Mat())
  38. //
  39. /**
  40. * Calculates a sparse optical flow.
  41. *
  42. * param prevImg First input image.
  43. * param nextImg Second input image of the same size and the same type as prevImg.
  44. * param prevPts Vector of 2D points for which the flow needs to be found.
  45. * param nextPts Output vector of 2D points containing the calculated new positions of input features in the second image.
  46. * param status Output status vector. Each element of the vector is set to 1 if the
  47. * flow for the corresponding features has been found. Otherwise, it is set to 0.
  48. * param err Optional output vector that contains error response for each point (inverse confidence).
  49. */
  50. public void calc(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status, Mat err)
  51. {
  52. ThrowIfDisposed();
  53. if (prevImg != null) prevImg.ThrowIfDisposed();
  54. if (nextImg != null) nextImg.ThrowIfDisposed();
  55. if (prevPts != null) prevPts.ThrowIfDisposed();
  56. if (nextPts != null) nextPts.ThrowIfDisposed();
  57. if (status != null) status.ThrowIfDisposed();
  58. if (err != null) err.ThrowIfDisposed();
  59. video_SparseOpticalFlow_calc_10(nativeObj, prevImg.nativeObj, nextImg.nativeObj, prevPts.nativeObj, nextPts.nativeObj, status.nativeObj, err.nativeObj);
  60. }
  61. /**
  62. * Calculates a sparse optical flow.
  63. *
  64. * param prevImg First input image.
  65. * param nextImg Second input image of the same size and the same type as prevImg.
  66. * param prevPts Vector of 2D points for which the flow needs to be found.
  67. * param nextPts Output vector of 2D points containing the calculated new positions of input features in the second image.
  68. * param status Output status vector. Each element of the vector is set to 1 if the
  69. * flow for the corresponding features has been found. Otherwise, it is set to 0.
  70. */
  71. public void calc(Mat prevImg, Mat nextImg, Mat prevPts, Mat nextPts, Mat status)
  72. {
  73. ThrowIfDisposed();
  74. if (prevImg != null) prevImg.ThrowIfDisposed();
  75. if (nextImg != null) nextImg.ThrowIfDisposed();
  76. if (prevPts != null) prevPts.ThrowIfDisposed();
  77. if (nextPts != null) nextPts.ThrowIfDisposed();
  78. if (status != null) status.ThrowIfDisposed();
  79. video_SparseOpticalFlow_calc_11(nativeObj, prevImg.nativeObj, nextImg.nativeObj, prevPts.nativeObj, nextPts.nativeObj, status.nativeObj);
  80. }
  81. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  82. const string LIBNAME = "__Internal";
  83. #else
  84. const string LIBNAME = "opencvforunity";
  85. #endif
  86. // C++: void cv::SparseOpticalFlow::calc(Mat prevImg, Mat nextImg, Mat prevPts, Mat& nextPts, Mat& status, Mat& err = cv::Mat())
  87. [DllImport(LIBNAME)]
  88. private static extern void video_SparseOpticalFlow_calc_10(IntPtr nativeObj, IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_nativeObj, IntPtr nextPts_nativeObj, IntPtr status_nativeObj, IntPtr err_nativeObj);
  89. [DllImport(LIBNAME)]
  90. private static extern void video_SparseOpticalFlow_calc_11(IntPtr nativeObj, IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_nativeObj, IntPtr nextPts_nativeObj, IntPtr status_nativeObj);
  91. // native support for java finalize()
  92. [DllImport(LIBNAME)]
  93. private static extern void video_SparseOpticalFlow_delete(IntPtr nativeObj);
  94. }
  95. }