VideoCapture.cs 11 KB

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