VideoWriter.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. 
  2. using OpenCVForUnity.CoreModule;
  3. using OpenCVForUnity.UtilsModule;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Runtime.InteropServices;
  7. namespace OpenCVForUnity.VideoioModule
  8. {
  9. // C++: class VideoWriter
  10. //javadoc: VideoWriter
  11. public class VideoWriter : DisposableOpenCVObject
  12. {
  13. protected override void Dispose (bool disposing)
  14. {
  15. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  16. try {
  17. if (disposing) {
  18. }
  19. if (IsEnabledDispose) {
  20. if (nativeObj != IntPtr.Zero)
  21. videoio_VideoWriter_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal VideoWriter (IntPtr addr) : base (addr) { }
  32. public IntPtr getNativeObjAddr () { return nativeObj; }
  33. // internal usage only
  34. public static VideoWriter __fromPtr__ (IntPtr addr) { return new VideoWriter (addr); }
  35. //
  36. // C++: cv::VideoWriter::VideoWriter(String filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor = true)
  37. //
  38. //javadoc: VideoWriter::VideoWriter(filename, apiPreference, fourcc, fps, frameSize, isColor)
  39. public VideoWriter (string filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor)
  40. {
  41. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  42. nativeObj = videoio_VideoWriter_VideoWriter_10(filename, apiPreference, fourcc, fps, frameSize.width, frameSize.height, isColor);
  43. return;
  44. #else
  45. return null;
  46. #endif
  47. }
  48. //javadoc: VideoWriter::VideoWriter(filename, apiPreference, fourcc, fps, frameSize)
  49. public VideoWriter (string filename, int apiPreference, int fourcc, double fps, Size frameSize)
  50. {
  51. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  52. nativeObj = videoio_VideoWriter_VideoWriter_11(filename, apiPreference, fourcc, fps, frameSize.width, frameSize.height);
  53. return;
  54. #else
  55. return null;
  56. #endif
  57. }
  58. //
  59. // C++: cv::VideoWriter::VideoWriter(String filename, int fourcc, double fps, Size frameSize, bool isColor = true)
  60. //
  61. //javadoc: VideoWriter::VideoWriter(filename, fourcc, fps, frameSize, isColor)
  62. public VideoWriter (string filename, int fourcc, double fps, Size frameSize, bool isColor)
  63. {
  64. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  65. nativeObj = videoio_VideoWriter_VideoWriter_12(filename, fourcc, fps, frameSize.width, frameSize.height, isColor);
  66. return;
  67. #else
  68. return null;
  69. #endif
  70. }
  71. //javadoc: VideoWriter::VideoWriter(filename, fourcc, fps, frameSize)
  72. public VideoWriter (string filename, int fourcc, double fps, Size frameSize)
  73. {
  74. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  75. nativeObj = videoio_VideoWriter_VideoWriter_13(filename, fourcc, fps, frameSize.width, frameSize.height);
  76. return;
  77. #else
  78. return null;
  79. #endif
  80. }
  81. //
  82. // C++: cv::VideoWriter::VideoWriter()
  83. //
  84. //javadoc: VideoWriter::VideoWriter()
  85. public VideoWriter ()
  86. {
  87. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  88. nativeObj = videoio_VideoWriter_VideoWriter_14();
  89. return;
  90. #else
  91. return null;
  92. #endif
  93. }
  94. //
  95. // C++: String cv::VideoWriter::getBackendName()
  96. //
  97. //javadoc: VideoWriter::getBackendName()
  98. public string getBackendName ()
  99. {
  100. ThrowIfDisposed ();
  101. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  102. string retVal = Marshal.PtrToStringAnsi (videoio_VideoWriter_getBackendName_10(nativeObj));
  103. return retVal;
  104. #else
  105. return null;
  106. #endif
  107. }
  108. //
  109. // C++: bool cv::VideoWriter::isOpened()
  110. //
  111. //javadoc: VideoWriter::isOpened()
  112. public bool isOpened ()
  113. {
  114. ThrowIfDisposed ();
  115. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  116. bool retVal = videoio_VideoWriter_isOpened_10(nativeObj);
  117. return retVal;
  118. #else
  119. return false;
  120. #endif
  121. }
  122. //
  123. // C++: bool cv::VideoWriter::open(String filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor = true)
  124. //
  125. //javadoc: VideoWriter::open(filename, apiPreference, fourcc, fps, frameSize, isColor)
  126. public bool open (string filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor)
  127. {
  128. ThrowIfDisposed ();
  129. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  130. bool retVal = videoio_VideoWriter_open_10(nativeObj, filename, apiPreference, fourcc, fps, frameSize.width, frameSize.height, isColor);
  131. return retVal;
  132. #else
  133. return false;
  134. #endif
  135. }
  136. //javadoc: VideoWriter::open(filename, apiPreference, fourcc, fps, frameSize)
  137. public bool open (string filename, int apiPreference, int fourcc, double fps, Size frameSize)
  138. {
  139. ThrowIfDisposed ();
  140. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  141. bool retVal = videoio_VideoWriter_open_11(nativeObj, filename, apiPreference, fourcc, fps, frameSize.width, frameSize.height);
  142. return retVal;
  143. #else
  144. return false;
  145. #endif
  146. }
  147. //
  148. // C++: bool cv::VideoWriter::open(String filename, int fourcc, double fps, Size frameSize, bool isColor = true)
  149. //
  150. //javadoc: VideoWriter::open(filename, fourcc, fps, frameSize, isColor)
  151. public bool open (string filename, int fourcc, double fps, Size frameSize, bool isColor)
  152. {
  153. ThrowIfDisposed ();
  154. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  155. bool retVal = videoio_VideoWriter_open_12(nativeObj, filename, fourcc, fps, frameSize.width, frameSize.height, isColor);
  156. return retVal;
  157. #else
  158. return false;
  159. #endif
  160. }
  161. //javadoc: VideoWriter::open(filename, fourcc, fps, frameSize)
  162. public bool open (string filename, int fourcc, double fps, Size frameSize)
  163. {
  164. ThrowIfDisposed ();
  165. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  166. bool retVal = videoio_VideoWriter_open_13(nativeObj, filename, fourcc, fps, frameSize.width, frameSize.height);
  167. return retVal;
  168. #else
  169. return false;
  170. #endif
  171. }
  172. //
  173. // C++: bool cv::VideoWriter::set(int propId, double value)
  174. //
  175. //javadoc: VideoWriter::set(propId, value)
  176. public bool set (int propId, double value)
  177. {
  178. ThrowIfDisposed ();
  179. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  180. bool retVal = videoio_VideoWriter_set_10(nativeObj, propId, value);
  181. return retVal;
  182. #else
  183. return false;
  184. #endif
  185. }
  186. //
  187. // C++: double cv::VideoWriter::get(int propId)
  188. //
  189. //javadoc: VideoWriter::get(propId)
  190. public double get (int propId)
  191. {
  192. ThrowIfDisposed ();
  193. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  194. double retVal = videoio_VideoWriter_get_10(nativeObj, propId);
  195. return retVal;
  196. #else
  197. return -1;
  198. #endif
  199. }
  200. //
  201. // C++: static int cv::VideoWriter::fourcc(char c1, char c2, char c3, char c4)
  202. //
  203. //javadoc: VideoWriter::fourcc(c1, c2, c3, c4)
  204. public static int fourcc (char c1, char c2, char c3, char c4)
  205. {
  206. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  207. int retVal = videoio_VideoWriter_fourcc_10(c1, c2, c3, c4);
  208. return retVal;
  209. #else
  210. return -1;
  211. #endif
  212. }
  213. //
  214. // C++: void cv::VideoWriter::release()
  215. //
  216. //javadoc: VideoWriter::release()
  217. public void release ()
  218. {
  219. ThrowIfDisposed ();
  220. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  221. videoio_VideoWriter_release_10(nativeObj);
  222. return;
  223. #else
  224. return;
  225. #endif
  226. }
  227. //
  228. // C++: void cv::VideoWriter::write(Mat image)
  229. //
  230. //javadoc: VideoWriter::write(image)
  231. public void write (Mat image)
  232. {
  233. ThrowIfDisposed ();
  234. if (image != null) image.ThrowIfDisposed ();
  235. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  236. videoio_VideoWriter_write_10(nativeObj, image.nativeObj);
  237. return;
  238. #else
  239. return;
  240. #endif
  241. }
  242. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  243. const string LIBNAME = "__Internal";
  244. #else
  245. const string LIBNAME = "opencvforunity";
  246. #endif
  247. // C++: cv::VideoWriter::VideoWriter(String filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor = true)
  248. [DllImport (LIBNAME)]
  249. private static extern IntPtr videoio_VideoWriter_VideoWriter_10 (string filename, int apiPreference, int fourcc, double fps, double frameSize_width, double frameSize_height, bool isColor);
  250. [DllImport (LIBNAME)]
  251. private static extern IntPtr videoio_VideoWriter_VideoWriter_11 (string filename, int apiPreference, int fourcc, double fps, double frameSize_width, double frameSize_height);
  252. // C++: cv::VideoWriter::VideoWriter(String filename, int fourcc, double fps, Size frameSize, bool isColor = true)
  253. [DllImport (LIBNAME)]
  254. private static extern IntPtr videoio_VideoWriter_VideoWriter_12 (string filename, int fourcc, double fps, double frameSize_width, double frameSize_height, bool isColor);
  255. [DllImport (LIBNAME)]
  256. private static extern IntPtr videoio_VideoWriter_VideoWriter_13 (string filename, int fourcc, double fps, double frameSize_width, double frameSize_height);
  257. // C++: cv::VideoWriter::VideoWriter()
  258. [DllImport (LIBNAME)]
  259. private static extern IntPtr videoio_VideoWriter_VideoWriter_14 ();
  260. // C++: String cv::VideoWriter::getBackendName()
  261. [DllImport (LIBNAME)]
  262. private static extern IntPtr videoio_VideoWriter_getBackendName_10 (IntPtr nativeObj);
  263. // C++: bool cv::VideoWriter::isOpened()
  264. [DllImport (LIBNAME)]
  265. private static extern bool videoio_VideoWriter_isOpened_10 (IntPtr nativeObj);
  266. // C++: bool cv::VideoWriter::open(String filename, int apiPreference, int fourcc, double fps, Size frameSize, bool isColor = true)
  267. [DllImport (LIBNAME)]
  268. private static extern bool videoio_VideoWriter_open_10 (IntPtr nativeObj, string filename, int apiPreference, int fourcc, double fps, double frameSize_width, double frameSize_height, bool isColor);
  269. [DllImport (LIBNAME)]
  270. private static extern bool videoio_VideoWriter_open_11 (IntPtr nativeObj, string filename, int apiPreference, int fourcc, double fps, double frameSize_width, double frameSize_height);
  271. // C++: bool cv::VideoWriter::open(String filename, int fourcc, double fps, Size frameSize, bool isColor = true)
  272. [DllImport (LIBNAME)]
  273. private static extern bool videoio_VideoWriter_open_12 (IntPtr nativeObj, string filename, int fourcc, double fps, double frameSize_width, double frameSize_height, bool isColor);
  274. [DllImport (LIBNAME)]
  275. private static extern bool videoio_VideoWriter_open_13 (IntPtr nativeObj, string filename, int fourcc, double fps, double frameSize_width, double frameSize_height);
  276. // C++: bool cv::VideoWriter::set(int propId, double value)
  277. [DllImport (LIBNAME)]
  278. private static extern bool videoio_VideoWriter_set_10 (IntPtr nativeObj, int propId, double value);
  279. // C++: double cv::VideoWriter::get(int propId)
  280. [DllImport (LIBNAME)]
  281. private static extern double videoio_VideoWriter_get_10 (IntPtr nativeObj, int propId);
  282. // C++: static int cv::VideoWriter::fourcc(char c1, char c2, char c3, char c4)
  283. [DllImport (LIBNAME)]
  284. private static extern int videoio_VideoWriter_fourcc_10 (char c1, char c2, char c3, char c4);
  285. // C++: void cv::VideoWriter::release()
  286. [DllImport (LIBNAME)]
  287. private static extern void videoio_VideoWriter_release_10 (IntPtr nativeObj);
  288. // C++: void cv::VideoWriter::write(Mat image)
  289. [DllImport (LIBNAME)]
  290. private static extern void videoio_VideoWriter_write_10 (IntPtr nativeObj, IntPtr image_nativeObj);
  291. // native support for java finalize()
  292. [DllImport (LIBNAME)]
  293. private static extern void videoio_VideoWriter_delete (IntPtr nativeObj);
  294. }
  295. }