TransientAreasSegmentationModule.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.BioinspiredModule
  7. {
  8. // C++: class TransientAreasSegmentationModule
  9. /**
  10. * class which provides a transient/moving areas segmentation module
  11. *
  12. * perform a locally adapted segmentation by using the retina magno input data Based on Alexandre
  13. * BENOIT thesis: "Le système visuel humain au secours de la vision par ordinateur"
  14. *
  15. * 3 spatio temporal filters are used:
  16. * <ul>
  17. * <li>
  18. * a first one which filters the noise and local variations of the input motion energy
  19. * </li>
  20. * <li>
  21. * a second (more powerfull low pass spatial filter) which gives the neighborhood motion energy the
  22. * segmentation consists in the comparison of these both outputs, if the local motion energy is higher
  23. * to the neighborhood otion energy, then the area is considered as moving and is segmented
  24. * </li>
  25. * <li>
  26. * a stronger third low pass filter helps decision by providing a smooth information about the
  27. * "motion context" in a wider area
  28. * </li>
  29. * </ul>
  30. */
  31. public class TransientAreasSegmentationModule : Algorithm
  32. {
  33. protected override void Dispose(bool disposing)
  34. {
  35. try
  36. {
  37. if (disposing)
  38. {
  39. }
  40. if (IsEnabledDispose)
  41. {
  42. if (nativeObj != IntPtr.Zero)
  43. bioinspired_TransientAreasSegmentationModule_delete(nativeObj);
  44. nativeObj = IntPtr.Zero;
  45. }
  46. }
  47. finally
  48. {
  49. base.Dispose(disposing);
  50. }
  51. }
  52. protected internal TransientAreasSegmentationModule(IntPtr addr) : base(addr) { }
  53. // internal usage only
  54. public static new TransientAreasSegmentationModule __fromPtr__(IntPtr addr) { return new TransientAreasSegmentationModule(addr); }
  55. //
  56. // C++: Size cv::bioinspired::TransientAreasSegmentationModule::getSize()
  57. //
  58. /**
  59. * return the sze of the manage input and output images
  60. * return automatically generated
  61. */
  62. public Size getSize()
  63. {
  64. ThrowIfDisposed();
  65. double[] tmpArray = new double[2];
  66. bioinspired_TransientAreasSegmentationModule_getSize_10(nativeObj, tmpArray);
  67. Size retVal = new Size(tmpArray);
  68. return retVal;
  69. }
  70. //
  71. // C++: void cv::bioinspired::TransientAreasSegmentationModule::setup(String segmentationParameterFile = "", bool applyDefaultSetupOnFailure = true)
  72. //
  73. /**
  74. * try to open an XML segmentation parameters file to adjust current segmentation instance setup
  75. *
  76. * <ul>
  77. * <li>
  78. * if the xml file does not exist, then default setup is applied
  79. * </li>
  80. * <li>
  81. * warning, Exceptions are thrown if read XML file is not valid
  82. * </li>
  83. * </ul>
  84. * param segmentationParameterFile : the parameters filename
  85. * param applyDefaultSetupOnFailure : set to true if an error must be thrown on error
  86. */
  87. public void setup(string segmentationParameterFile, bool applyDefaultSetupOnFailure)
  88. {
  89. ThrowIfDisposed();
  90. bioinspired_TransientAreasSegmentationModule_setup_10(nativeObj, segmentationParameterFile, applyDefaultSetupOnFailure);
  91. }
  92. /**
  93. * try to open an XML segmentation parameters file to adjust current segmentation instance setup
  94. *
  95. * <ul>
  96. * <li>
  97. * if the xml file does not exist, then default setup is applied
  98. * </li>
  99. * <li>
  100. * warning, Exceptions are thrown if read XML file is not valid
  101. * </li>
  102. * </ul>
  103. * param segmentationParameterFile : the parameters filename
  104. */
  105. public void setup(string segmentationParameterFile)
  106. {
  107. ThrowIfDisposed();
  108. bioinspired_TransientAreasSegmentationModule_setup_11(nativeObj, segmentationParameterFile);
  109. }
  110. /**
  111. * try to open an XML segmentation parameters file to adjust current segmentation instance setup
  112. *
  113. * <ul>
  114. * <li>
  115. * if the xml file does not exist, then default setup is applied
  116. * </li>
  117. * <li>
  118. * warning, Exceptions are thrown if read XML file is not valid
  119. * </li>
  120. * </ul>
  121. */
  122. public void setup()
  123. {
  124. ThrowIfDisposed();
  125. bioinspired_TransientAreasSegmentationModule_setup_12(nativeObj);
  126. }
  127. //
  128. // C++: String cv::bioinspired::TransientAreasSegmentationModule::printSetup()
  129. //
  130. /**
  131. * parameters setup display method
  132. * return a string which contains formatted parameters information
  133. */
  134. public string printSetup()
  135. {
  136. ThrowIfDisposed();
  137. string retVal = Marshal.PtrToStringAnsi(DisposableObject.ThrowIfNullIntPtr(bioinspired_TransientAreasSegmentationModule_printSetup_10(nativeObj)));
  138. return retVal;
  139. }
  140. //
  141. // C++: void cv::bioinspired::TransientAreasSegmentationModule::write(String fs)
  142. //
  143. /**
  144. * write xml/yml formated parameters information
  145. * param fs : the filename of the xml file that will be open and writen with formatted parameters information
  146. */
  147. public void write(string fs)
  148. {
  149. ThrowIfDisposed();
  150. bioinspired_TransientAreasSegmentationModule_write_10(nativeObj, fs);
  151. }
  152. //
  153. // C++: void cv::bioinspired::TransientAreasSegmentationModule::run(Mat inputToSegment, int channelIndex = 0)
  154. //
  155. /**
  156. * main processing method, get result using methods getSegmentationPicture()
  157. * param inputToSegment : the image to process, it must match the instance buffer size !
  158. * param channelIndex : the channel to process in case of multichannel images
  159. */
  160. public void run(Mat inputToSegment, int channelIndex)
  161. {
  162. ThrowIfDisposed();
  163. if (inputToSegment != null) inputToSegment.ThrowIfDisposed();
  164. bioinspired_TransientAreasSegmentationModule_run_10(nativeObj, inputToSegment.nativeObj, channelIndex);
  165. }
  166. /**
  167. * main processing method, get result using methods getSegmentationPicture()
  168. * param inputToSegment : the image to process, it must match the instance buffer size !
  169. */
  170. public void run(Mat inputToSegment)
  171. {
  172. ThrowIfDisposed();
  173. if (inputToSegment != null) inputToSegment.ThrowIfDisposed();
  174. bioinspired_TransientAreasSegmentationModule_run_11(nativeObj, inputToSegment.nativeObj);
  175. }
  176. //
  177. // C++: void cv::bioinspired::TransientAreasSegmentationModule::getSegmentationPicture(Mat& transientAreas)
  178. //
  179. /**
  180. * access function
  181. * return the last segmentation result: a boolean picture which is resampled between 0 and 255 for a display purpose
  182. * param transientAreas automatically generated
  183. */
  184. public void getSegmentationPicture(Mat transientAreas)
  185. {
  186. ThrowIfDisposed();
  187. if (transientAreas != null) transientAreas.ThrowIfDisposed();
  188. bioinspired_TransientAreasSegmentationModule_getSegmentationPicture_10(nativeObj, transientAreas.nativeObj);
  189. }
  190. //
  191. // C++: void cv::bioinspired::TransientAreasSegmentationModule::clearAllBuffers()
  192. //
  193. /**
  194. * cleans all the buffers of the instance
  195. */
  196. public void clearAllBuffers()
  197. {
  198. ThrowIfDisposed();
  199. bioinspired_TransientAreasSegmentationModule_clearAllBuffers_10(nativeObj);
  200. }
  201. //
  202. // C++: static Ptr_TransientAreasSegmentationModule cv::bioinspired::TransientAreasSegmentationModule::create(Size inputSize)
  203. //
  204. /**
  205. * allocator
  206. * param inputSize : size of the images input to segment (output will be the same size)
  207. * return automatically generated
  208. */
  209. public static TransientAreasSegmentationModule create(Size inputSize)
  210. {
  211. return TransientAreasSegmentationModule.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(bioinspired_TransientAreasSegmentationModule_create_10(inputSize.width, inputSize.height)));
  212. }
  213. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  214. const string LIBNAME = "__Internal";
  215. #else
  216. const string LIBNAME = "opencvforunity";
  217. #endif
  218. // C++: Size cv::bioinspired::TransientAreasSegmentationModule::getSize()
  219. [DllImport(LIBNAME)]
  220. private static extern void bioinspired_TransientAreasSegmentationModule_getSize_10(IntPtr nativeObj, double[] retVal);
  221. // C++: void cv::bioinspired::TransientAreasSegmentationModule::setup(String segmentationParameterFile = "", bool applyDefaultSetupOnFailure = true)
  222. [DllImport(LIBNAME)]
  223. private static extern void bioinspired_TransientAreasSegmentationModule_setup_10(IntPtr nativeObj, string segmentationParameterFile, [MarshalAs(UnmanagedType.U1)] bool applyDefaultSetupOnFailure);
  224. [DllImport(LIBNAME)]
  225. private static extern void bioinspired_TransientAreasSegmentationModule_setup_11(IntPtr nativeObj, string segmentationParameterFile);
  226. [DllImport(LIBNAME)]
  227. private static extern void bioinspired_TransientAreasSegmentationModule_setup_12(IntPtr nativeObj);
  228. // C++: String cv::bioinspired::TransientAreasSegmentationModule::printSetup()
  229. [DllImport(LIBNAME)]
  230. private static extern IntPtr bioinspired_TransientAreasSegmentationModule_printSetup_10(IntPtr nativeObj);
  231. // C++: void cv::bioinspired::TransientAreasSegmentationModule::write(String fs)
  232. [DllImport(LIBNAME)]
  233. private static extern void bioinspired_TransientAreasSegmentationModule_write_10(IntPtr nativeObj, string fs);
  234. // C++: void cv::bioinspired::TransientAreasSegmentationModule::run(Mat inputToSegment, int channelIndex = 0)
  235. [DllImport(LIBNAME)]
  236. private static extern void bioinspired_TransientAreasSegmentationModule_run_10(IntPtr nativeObj, IntPtr inputToSegment_nativeObj, int channelIndex);
  237. [DllImport(LIBNAME)]
  238. private static extern void bioinspired_TransientAreasSegmentationModule_run_11(IntPtr nativeObj, IntPtr inputToSegment_nativeObj);
  239. // C++: void cv::bioinspired::TransientAreasSegmentationModule::getSegmentationPicture(Mat& transientAreas)
  240. [DllImport(LIBNAME)]
  241. private static extern void bioinspired_TransientAreasSegmentationModule_getSegmentationPicture_10(IntPtr nativeObj, IntPtr transientAreas_nativeObj);
  242. // C++: void cv::bioinspired::TransientAreasSegmentationModule::clearAllBuffers()
  243. [DllImport(LIBNAME)]
  244. private static extern void bioinspired_TransientAreasSegmentationModule_clearAllBuffers_10(IntPtr nativeObj);
  245. // C++: static Ptr_TransientAreasSegmentationModule cv::bioinspired::TransientAreasSegmentationModule::create(Size inputSize)
  246. [DllImport(LIBNAME)]
  247. private static extern IntPtr bioinspired_TransientAreasSegmentationModule_create_10(double inputSize_width, double inputSize_height);
  248. // native support for java finalize()
  249. [DllImport(LIBNAME)]
  250. private static extern void bioinspired_TransientAreasSegmentationModule_delete(IntPtr nativeObj);
  251. }
  252. }