VideoCapture.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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 VideoCapture
  10. //javadoc: VideoCapture
  11. public class VideoCapture : 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_VideoCapture_delete(nativeObj);
  22. nativeObj = IntPtr.Zero;
  23. }
  24. } finally {
  25. base.Dispose (disposing);
  26. }
  27. #else
  28. return;
  29. #endif
  30. }
  31. protected internal VideoCapture (IntPtr addr) : base (addr) { }
  32. public IntPtr getNativeObjAddr () { return nativeObj; }
  33. // internal usage only
  34. public static VideoCapture __fromPtr__ (IntPtr addr) { return new VideoCapture (addr); }
  35. //
  36. // C++: cv::VideoCapture::VideoCapture(String filename, int apiPreference = CAP_ANY)
  37. //
  38. //javadoc: VideoCapture::VideoCapture(filename, apiPreference)
  39. public VideoCapture (string filename, int apiPreference)
  40. {
  41. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  42. nativeObj = videoio_VideoCapture_VideoCapture_10(filename, apiPreference);
  43. return;
  44. #else
  45. return null;
  46. #endif
  47. }
  48. //javadoc: VideoCapture::VideoCapture(filename)
  49. public VideoCapture (string filename)
  50. {
  51. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  52. nativeObj = videoio_VideoCapture_VideoCapture_11(filename);
  53. return;
  54. #else
  55. return null;
  56. #endif
  57. }
  58. //
  59. // C++: cv::VideoCapture::VideoCapture(int index, int apiPreference = CAP_ANY)
  60. //
  61. //javadoc: VideoCapture::VideoCapture(index, apiPreference)
  62. public VideoCapture (int index, int apiPreference)
  63. {
  64. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  65. nativeObj = videoio_VideoCapture_VideoCapture_12(index, apiPreference);
  66. return;
  67. #else
  68. return null;
  69. #endif
  70. }
  71. //javadoc: VideoCapture::VideoCapture(index)
  72. public VideoCapture (int index)
  73. {
  74. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  75. nativeObj = videoio_VideoCapture_VideoCapture_13(index);
  76. return;
  77. #else
  78. return null;
  79. #endif
  80. }
  81. //
  82. // C++: cv::VideoCapture::VideoCapture()
  83. //
  84. //javadoc: VideoCapture::VideoCapture()
  85. public VideoCapture ()
  86. {
  87. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  88. nativeObj = videoio_VideoCapture_VideoCapture_14();
  89. return;
  90. #else
  91. return null;
  92. #endif
  93. }
  94. //
  95. // C++: String cv::VideoCapture::getBackendName()
  96. //
  97. //javadoc: VideoCapture::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_VideoCapture_getBackendName_10(nativeObj));
  103. return retVal;
  104. #else
  105. return null;
  106. #endif
  107. }
  108. //
  109. // C++: bool cv::VideoCapture::grab()
  110. //
  111. //javadoc: VideoCapture::grab()
  112. public bool grab ()
  113. {
  114. ThrowIfDisposed ();
  115. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  116. bool retVal = videoio_VideoCapture_grab_10(nativeObj);
  117. return retVal;
  118. #else
  119. return false;
  120. #endif
  121. }
  122. //
  123. // C++: bool cv::VideoCapture::isOpened()
  124. //
  125. //javadoc: VideoCapture::isOpened()
  126. public bool isOpened ()
  127. {
  128. ThrowIfDisposed ();
  129. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  130. bool retVal = videoio_VideoCapture_isOpened_10(nativeObj);
  131. return retVal;
  132. #else
  133. return false;
  134. #endif
  135. }
  136. //
  137. // C++: bool cv::VideoCapture::open(String filename, int apiPreference = CAP_ANY)
  138. //
  139. //javadoc: VideoCapture::open(filename, apiPreference)
  140. public bool open (string filename, int apiPreference)
  141. {
  142. ThrowIfDisposed ();
  143. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  144. bool retVal = videoio_VideoCapture_open_10(nativeObj, filename, apiPreference);
  145. return retVal;
  146. #else
  147. return false;
  148. #endif
  149. }
  150. //javadoc: VideoCapture::open(filename)
  151. public bool open (string filename)
  152. {
  153. ThrowIfDisposed ();
  154. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  155. bool retVal = videoio_VideoCapture_open_11(nativeObj, filename);
  156. return retVal;
  157. #else
  158. return false;
  159. #endif
  160. }
  161. //
  162. // C++: bool cv::VideoCapture::open(int index, int apiPreference = CAP_ANY)
  163. //
  164. //javadoc: VideoCapture::open(index, apiPreference)
  165. public bool open (int index, int apiPreference)
  166. {
  167. ThrowIfDisposed ();
  168. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  169. bool retVal = videoio_VideoCapture_open_12(nativeObj, index, apiPreference);
  170. return retVal;
  171. #else
  172. return false;
  173. #endif
  174. }
  175. //javadoc: VideoCapture::open(index)
  176. public bool open (int index)
  177. {
  178. ThrowIfDisposed ();
  179. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  180. bool retVal = videoio_VideoCapture_open_13(nativeObj, index);
  181. return retVal;
  182. #else
  183. return false;
  184. #endif
  185. }
  186. //
  187. // C++: bool cv::VideoCapture::read(Mat& image)
  188. //
  189. //javadoc: VideoCapture::read(image)
  190. public bool read (Mat image)
  191. {
  192. ThrowIfDisposed ();
  193. if (image != null) image.ThrowIfDisposed ();
  194. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  195. bool retVal = videoio_VideoCapture_read_10(nativeObj, image.nativeObj);
  196. return retVal;
  197. #else
  198. return false;
  199. #endif
  200. }
  201. //
  202. // C++: bool cv::VideoCapture::retrieve(Mat& image, int flag = 0)
  203. //
  204. //javadoc: VideoCapture::retrieve(image, flag)
  205. public bool retrieve (Mat image, int flag)
  206. {
  207. ThrowIfDisposed ();
  208. if (image != null) image.ThrowIfDisposed ();
  209. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  210. bool retVal = videoio_VideoCapture_retrieve_10(nativeObj, image.nativeObj, flag);
  211. return retVal;
  212. #else
  213. return false;
  214. #endif
  215. }
  216. //javadoc: VideoCapture::retrieve(image)
  217. public bool retrieve (Mat image)
  218. {
  219. ThrowIfDisposed ();
  220. if (image != null) image.ThrowIfDisposed ();
  221. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  222. bool retVal = videoio_VideoCapture_retrieve_11(nativeObj, image.nativeObj);
  223. return retVal;
  224. #else
  225. return false;
  226. #endif
  227. }
  228. //
  229. // C++: bool cv::VideoCapture::set(int propId, double value)
  230. //
  231. //javadoc: VideoCapture::set(propId, value)
  232. public bool set (int propId, double value)
  233. {
  234. ThrowIfDisposed ();
  235. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  236. bool retVal = videoio_VideoCapture_set_10(nativeObj, propId, value);
  237. return retVal;
  238. #else
  239. return false;
  240. #endif
  241. }
  242. //
  243. // C++: double cv::VideoCapture::get(int propId)
  244. //
  245. //javadoc: VideoCapture::get(propId)
  246. public double get (int propId)
  247. {
  248. ThrowIfDisposed ();
  249. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  250. double retVal = videoio_VideoCapture_get_10(nativeObj, propId);
  251. return retVal;
  252. #else
  253. return -1;
  254. #endif
  255. }
  256. //
  257. // C++: void cv::VideoCapture::release()
  258. //
  259. //javadoc: VideoCapture::release()
  260. public void release ()
  261. {
  262. ThrowIfDisposed ();
  263. #if ((UNITY_ANDROID || UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR) || UNITY_5 || UNITY_5_3_OR_NEWER
  264. videoio_VideoCapture_release_10(nativeObj);
  265. return;
  266. #else
  267. return;
  268. #endif
  269. }
  270. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  271. const string LIBNAME = "__Internal";
  272. #else
  273. const string LIBNAME = "opencvforunity";
  274. #endif
  275. // C++: cv::VideoCapture::VideoCapture(String filename, int apiPreference = CAP_ANY)
  276. [DllImport (LIBNAME)]
  277. private static extern IntPtr videoio_VideoCapture_VideoCapture_10 (string filename, int apiPreference);
  278. [DllImport (LIBNAME)]
  279. private static extern IntPtr videoio_VideoCapture_VideoCapture_11 (string filename);
  280. // C++: cv::VideoCapture::VideoCapture(int index, int apiPreference = CAP_ANY)
  281. [DllImport (LIBNAME)]
  282. private static extern IntPtr videoio_VideoCapture_VideoCapture_12 (int index, int apiPreference);
  283. [DllImport (LIBNAME)]
  284. private static extern IntPtr videoio_VideoCapture_VideoCapture_13 (int index);
  285. // C++: cv::VideoCapture::VideoCapture()
  286. [DllImport (LIBNAME)]
  287. private static extern IntPtr videoio_VideoCapture_VideoCapture_14 ();
  288. // C++: String cv::VideoCapture::getBackendName()
  289. [DllImport (LIBNAME)]
  290. private static extern IntPtr videoio_VideoCapture_getBackendName_10 (IntPtr nativeObj);
  291. // C++: bool cv::VideoCapture::grab()
  292. [DllImport (LIBNAME)]
  293. private static extern bool videoio_VideoCapture_grab_10 (IntPtr nativeObj);
  294. // C++: bool cv::VideoCapture::isOpened()
  295. [DllImport (LIBNAME)]
  296. private static extern bool videoio_VideoCapture_isOpened_10 (IntPtr nativeObj);
  297. // C++: bool cv::VideoCapture::open(String filename, int apiPreference = CAP_ANY)
  298. [DllImport (LIBNAME)]
  299. private static extern bool videoio_VideoCapture_open_10 (IntPtr nativeObj, string filename, int apiPreference);
  300. [DllImport (LIBNAME)]
  301. private static extern bool videoio_VideoCapture_open_11 (IntPtr nativeObj, string filename);
  302. // C++: bool cv::VideoCapture::open(int index, int apiPreference = CAP_ANY)
  303. [DllImport (LIBNAME)]
  304. private static extern bool videoio_VideoCapture_open_12 (IntPtr nativeObj, int index, int apiPreference);
  305. [DllImport (LIBNAME)]
  306. private static extern bool videoio_VideoCapture_open_13 (IntPtr nativeObj, int index);
  307. // C++: bool cv::VideoCapture::read(Mat& image)
  308. [DllImport (LIBNAME)]
  309. private static extern bool videoio_VideoCapture_read_10 (IntPtr nativeObj, IntPtr image_nativeObj);
  310. // C++: bool cv::VideoCapture::retrieve(Mat& image, int flag = 0)
  311. [DllImport (LIBNAME)]
  312. private static extern bool videoio_VideoCapture_retrieve_10 (IntPtr nativeObj, IntPtr image_nativeObj, int flag);
  313. [DllImport (LIBNAME)]
  314. private static extern bool videoio_VideoCapture_retrieve_11 (IntPtr nativeObj, IntPtr image_nativeObj);
  315. // C++: bool cv::VideoCapture::set(int propId, double value)
  316. [DllImport (LIBNAME)]
  317. private static extern bool videoio_VideoCapture_set_10 (IntPtr nativeObj, int propId, double value);
  318. // C++: double cv::VideoCapture::get(int propId)
  319. [DllImport (LIBNAME)]
  320. private static extern double videoio_VideoCapture_get_10 (IntPtr nativeObj, int propId);
  321. // C++: void cv::VideoCapture::release()
  322. [DllImport (LIBNAME)]
  323. private static extern void videoio_VideoCapture_release_10 (IntPtr nativeObj);
  324. // native support for java finalize()
  325. [DllImport (LIBNAME)]
  326. private static extern void videoio_VideoCapture_delete (IntPtr nativeObj);
  327. }
  328. }