BackgroundSubtractorGSOC.cs 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using OpenCVForUnity.VideoModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.BgsegmModule
  8. {
  9. // C++: class BackgroundSubtractorGSOC
  10. /**
  11. * Implementation of the different yet better algorithm which is called GSOC, as it was implemented during GSOC and was not originated from any paper.
  12. *
  13. * This algorithm demonstrates better performance on CDNET 2014 dataset compared to other algorithms in OpenCV.
  14. */
  15. public class BackgroundSubtractorGSOC : BackgroundSubtractor
  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. bgsegm_BackgroundSubtractorGSOC_delete(nativeObj);
  28. nativeObj = IntPtr.Zero;
  29. }
  30. }
  31. finally
  32. {
  33. base.Dispose(disposing);
  34. }
  35. }
  36. protected internal BackgroundSubtractorGSOC(IntPtr addr) : base(addr) { }
  37. // internal usage only
  38. public static new BackgroundSubtractorGSOC __fromPtr__(IntPtr addr) { return new BackgroundSubtractorGSOC(addr); }
  39. //
  40. // C++: void cv::bgsegm::BackgroundSubtractorGSOC::apply(Mat image, Mat& fgmask, double learningRate = -1)
  41. //
  42. public override void apply(Mat image, Mat fgmask, double learningRate)
  43. {
  44. ThrowIfDisposed();
  45. if (image != null) image.ThrowIfDisposed();
  46. if (fgmask != null) fgmask.ThrowIfDisposed();
  47. bgsegm_BackgroundSubtractorGSOC_apply_10(nativeObj, image.nativeObj, fgmask.nativeObj, learningRate);
  48. }
  49. public override void apply(Mat image, Mat fgmask)
  50. {
  51. ThrowIfDisposed();
  52. if (image != null) image.ThrowIfDisposed();
  53. if (fgmask != null) fgmask.ThrowIfDisposed();
  54. bgsegm_BackgroundSubtractorGSOC_apply_11(nativeObj, image.nativeObj, fgmask.nativeObj);
  55. }
  56. //
  57. // C++: void cv::bgsegm::BackgroundSubtractorGSOC::getBackgroundImage(Mat& backgroundImage)
  58. //
  59. public override void getBackgroundImage(Mat backgroundImage)
  60. {
  61. ThrowIfDisposed();
  62. if (backgroundImage != null) backgroundImage.ThrowIfDisposed();
  63. bgsegm_BackgroundSubtractorGSOC_getBackgroundImage_10(nativeObj, backgroundImage.nativeObj);
  64. }
  65. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  66. const string LIBNAME = "__Internal";
  67. #else
  68. const string LIBNAME = "opencvforunity";
  69. #endif
  70. // C++: void cv::bgsegm::BackgroundSubtractorGSOC::apply(Mat image, Mat& fgmask, double learningRate = -1)
  71. [DllImport(LIBNAME)]
  72. private static extern void bgsegm_BackgroundSubtractorGSOC_apply_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr fgmask_nativeObj, double learningRate);
  73. [DllImport(LIBNAME)]
  74. private static extern void bgsegm_BackgroundSubtractorGSOC_apply_11(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr fgmask_nativeObj);
  75. // C++: void cv::bgsegm::BackgroundSubtractorGSOC::getBackgroundImage(Mat& backgroundImage)
  76. [DllImport(LIBNAME)]
  77. private static extern void bgsegm_BackgroundSubtractorGSOC_getBackgroundImage_10(IntPtr nativeObj, IntPtr backgroundImage_nativeObj);
  78. // native support for java finalize()
  79. [DllImport(LIBNAME)]
  80. private static extern void bgsegm_BackgroundSubtractorGSOC_delete(IntPtr nativeObj);
  81. }
  82. }