BackgroundSubtractorCNT.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295
  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 BackgroundSubtractorCNT
  10. /**
  11. * Background subtraction based on counting.
  12. *
  13. * About as fast as MOG2 on a high end system.
  14. * More than twice faster than MOG2 on cheap hardware (benchmarked on Raspberry Pi3).
  15. *
  16. * %Algorithm by Sagi Zeevi ( https://github.com/sagi-z/BackgroundSubtractorCNT )
  17. */
  18. public class BackgroundSubtractorCNT : BackgroundSubtractor
  19. {
  20. protected override void Dispose(bool disposing)
  21. {
  22. try
  23. {
  24. if (disposing)
  25. {
  26. }
  27. if (IsEnabledDispose)
  28. {
  29. if (nativeObj != IntPtr.Zero)
  30. bgsegm_BackgroundSubtractorCNT_delete(nativeObj);
  31. nativeObj = IntPtr.Zero;
  32. }
  33. }
  34. finally
  35. {
  36. base.Dispose(disposing);
  37. }
  38. }
  39. protected internal BackgroundSubtractorCNT(IntPtr addr) : base(addr) { }
  40. // internal usage only
  41. public static new BackgroundSubtractorCNT __fromPtr__(IntPtr addr) { return new BackgroundSubtractorCNT(addr); }
  42. //
  43. // C++: void cv::bgsegm::BackgroundSubtractorCNT::apply(Mat image, Mat& fgmask, double learningRate = -1)
  44. //
  45. public override void apply(Mat image, Mat fgmask, double learningRate)
  46. {
  47. ThrowIfDisposed();
  48. if (image != null) image.ThrowIfDisposed();
  49. if (fgmask != null) fgmask.ThrowIfDisposed();
  50. bgsegm_BackgroundSubtractorCNT_apply_10(nativeObj, image.nativeObj, fgmask.nativeObj, learningRate);
  51. }
  52. public override void apply(Mat image, Mat fgmask)
  53. {
  54. ThrowIfDisposed();
  55. if (image != null) image.ThrowIfDisposed();
  56. if (fgmask != null) fgmask.ThrowIfDisposed();
  57. bgsegm_BackgroundSubtractorCNT_apply_11(nativeObj, image.nativeObj, fgmask.nativeObj);
  58. }
  59. //
  60. // C++: void cv::bgsegm::BackgroundSubtractorCNT::getBackgroundImage(Mat& backgroundImage)
  61. //
  62. public override void getBackgroundImage(Mat backgroundImage)
  63. {
  64. ThrowIfDisposed();
  65. if (backgroundImage != null) backgroundImage.ThrowIfDisposed();
  66. bgsegm_BackgroundSubtractorCNT_getBackgroundImage_10(nativeObj, backgroundImage.nativeObj);
  67. }
  68. //
  69. // C++: int cv::bgsegm::BackgroundSubtractorCNT::getMinPixelStability()
  70. //
  71. /**
  72. * Returns number of frames with same pixel color to consider stable.
  73. * return automatically generated
  74. */
  75. public int getMinPixelStability()
  76. {
  77. ThrowIfDisposed();
  78. return bgsegm_BackgroundSubtractorCNT_getMinPixelStability_10(nativeObj);
  79. }
  80. //
  81. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setMinPixelStability(int value)
  82. //
  83. /**
  84. * Sets the number of frames with same pixel color to consider stable.
  85. * param value automatically generated
  86. */
  87. public void setMinPixelStability(int value)
  88. {
  89. ThrowIfDisposed();
  90. bgsegm_BackgroundSubtractorCNT_setMinPixelStability_10(nativeObj, value);
  91. }
  92. //
  93. // C++: int cv::bgsegm::BackgroundSubtractorCNT::getMaxPixelStability()
  94. //
  95. /**
  96. * Returns maximum allowed credit for a pixel in history.
  97. * return automatically generated
  98. */
  99. public int getMaxPixelStability()
  100. {
  101. ThrowIfDisposed();
  102. return bgsegm_BackgroundSubtractorCNT_getMaxPixelStability_10(nativeObj);
  103. }
  104. //
  105. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setMaxPixelStability(int value)
  106. //
  107. /**
  108. * Sets the maximum allowed credit for a pixel in history.
  109. * param value automatically generated
  110. */
  111. public void setMaxPixelStability(int value)
  112. {
  113. ThrowIfDisposed();
  114. bgsegm_BackgroundSubtractorCNT_setMaxPixelStability_10(nativeObj, value);
  115. }
  116. //
  117. // C++: bool cv::bgsegm::BackgroundSubtractorCNT::getUseHistory()
  118. //
  119. /**
  120. * Returns if we're giving a pixel credit for being stable for a long time.
  121. * return automatically generated
  122. */
  123. public bool getUseHistory()
  124. {
  125. ThrowIfDisposed();
  126. return bgsegm_BackgroundSubtractorCNT_getUseHistory_10(nativeObj);
  127. }
  128. //
  129. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setUseHistory(bool value)
  130. //
  131. /**
  132. * Sets if we're giving a pixel credit for being stable for a long time.
  133. * param value automatically generated
  134. */
  135. public void setUseHistory(bool value)
  136. {
  137. ThrowIfDisposed();
  138. bgsegm_BackgroundSubtractorCNT_setUseHistory_10(nativeObj, value);
  139. }
  140. //
  141. // C++: bool cv::bgsegm::BackgroundSubtractorCNT::getIsParallel()
  142. //
  143. /**
  144. * Returns if we're parallelizing the algorithm.
  145. * return automatically generated
  146. */
  147. public bool getIsParallel()
  148. {
  149. ThrowIfDisposed();
  150. return bgsegm_BackgroundSubtractorCNT_getIsParallel_10(nativeObj);
  151. }
  152. //
  153. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setIsParallel(bool value)
  154. //
  155. /**
  156. * Sets if we're parallelizing the algorithm.
  157. * param value automatically generated
  158. */
  159. public void setIsParallel(bool value)
  160. {
  161. ThrowIfDisposed();
  162. bgsegm_BackgroundSubtractorCNT_setIsParallel_10(nativeObj, value);
  163. }
  164. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  165. const string LIBNAME = "__Internal";
  166. #else
  167. const string LIBNAME = "opencvforunity";
  168. #endif
  169. // C++: void cv::bgsegm::BackgroundSubtractorCNT::apply(Mat image, Mat& fgmask, double learningRate = -1)
  170. [DllImport(LIBNAME)]
  171. private static extern void bgsegm_BackgroundSubtractorCNT_apply_10(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr fgmask_nativeObj, double learningRate);
  172. [DllImport(LIBNAME)]
  173. private static extern void bgsegm_BackgroundSubtractorCNT_apply_11(IntPtr nativeObj, IntPtr image_nativeObj, IntPtr fgmask_nativeObj);
  174. // C++: void cv::bgsegm::BackgroundSubtractorCNT::getBackgroundImage(Mat& backgroundImage)
  175. [DllImport(LIBNAME)]
  176. private static extern void bgsegm_BackgroundSubtractorCNT_getBackgroundImage_10(IntPtr nativeObj, IntPtr backgroundImage_nativeObj);
  177. // C++: int cv::bgsegm::BackgroundSubtractorCNT::getMinPixelStability()
  178. [DllImport(LIBNAME)]
  179. private static extern int bgsegm_BackgroundSubtractorCNT_getMinPixelStability_10(IntPtr nativeObj);
  180. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setMinPixelStability(int value)
  181. [DllImport(LIBNAME)]
  182. private static extern void bgsegm_BackgroundSubtractorCNT_setMinPixelStability_10(IntPtr nativeObj, int value);
  183. // C++: int cv::bgsegm::BackgroundSubtractorCNT::getMaxPixelStability()
  184. [DllImport(LIBNAME)]
  185. private static extern int bgsegm_BackgroundSubtractorCNT_getMaxPixelStability_10(IntPtr nativeObj);
  186. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setMaxPixelStability(int value)
  187. [DllImport(LIBNAME)]
  188. private static extern void bgsegm_BackgroundSubtractorCNT_setMaxPixelStability_10(IntPtr nativeObj, int value);
  189. // C++: bool cv::bgsegm::BackgroundSubtractorCNT::getUseHistory()
  190. [DllImport(LIBNAME)]
  191. [return: MarshalAs(UnmanagedType.U1)]
  192. private static extern bool bgsegm_BackgroundSubtractorCNT_getUseHistory_10(IntPtr nativeObj);
  193. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setUseHistory(bool value)
  194. [DllImport(LIBNAME)]
  195. private static extern void bgsegm_BackgroundSubtractorCNT_setUseHistory_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool value);
  196. // C++: bool cv::bgsegm::BackgroundSubtractorCNT::getIsParallel()
  197. [DllImport(LIBNAME)]
  198. [return: MarshalAs(UnmanagedType.U1)]
  199. private static extern bool bgsegm_BackgroundSubtractorCNT_getIsParallel_10(IntPtr nativeObj);
  200. // C++: void cv::bgsegm::BackgroundSubtractorCNT::setIsParallel(bool value)
  201. [DllImport(LIBNAME)]
  202. private static extern void bgsegm_BackgroundSubtractorCNT_setIsParallel_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool value);
  203. // native support for java finalize()
  204. [DllImport(LIBNAME)]
  205. private static extern void bgsegm_BackgroundSubtractorCNT_delete(IntPtr nativeObj);
  206. }
  207. }