VideoWriter.cs 12 KB

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