Video.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578
  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.VideoModule {
  8. // C++: class Video
  9. //javadoc: Video
  10. public class Video {
  11. private const int CV_LKFLOW_INITIAL_GUESSES = 4;
  12. private const int CV_LKFLOW_GET_MIN_EIGENVALS = 8;
  13. // C++: enum <unnamed>
  14. public const int OPTFLOW_USE_INITIAL_FLOW = 4;
  15. public const int OPTFLOW_LK_GET_MIN_EIGENVALS = 8;
  16. public const int OPTFLOW_FARNEBACK_GAUSSIAN = 256;
  17. public const int MOTION_TRANSLATION = 0;
  18. public const int MOTION_EUCLIDEAN = 1;
  19. public const int MOTION_AFFINE = 2;
  20. public const int MOTION_HOMOGRAPHY = 3;
  21. //
  22. // C++: Mat cv::readOpticalFlow(String path)
  23. //
  24. //javadoc: readOpticalFlow(path)
  25. public static Mat readOpticalFlow(string path) {
  26. #if (UNITY_ANDROID && !UNITY_EDITOR)
  27. Mat retVal = new Mat(video_Video_readOpticalFlow_10(path));
  28. return retVal;
  29. #else
  30. return null;
  31. #endif
  32. }
  33. //
  34. // C++: Ptr_BackgroundSubtractorKNN cv::createBackgroundSubtractorKNN(int history = 500, double dist2Threshold = 400.0, bool detectShadows = true)
  35. //
  36. //javadoc: createBackgroundSubtractorKNN(history, dist2Threshold, detectShadows)
  37. public static BackgroundSubtractorKNN createBackgroundSubtractorKNN(int history, double dist2Threshold, bool detectShadows) {
  38. #if (UNITY_ANDROID && !UNITY_EDITOR)
  39. BackgroundSubtractorKNN retVal = BackgroundSubtractorKNN.__fromPtr__(video_Video_createBackgroundSubtractorKNN_10(history, dist2Threshold, detectShadows));
  40. return retVal;
  41. #else
  42. return null;
  43. #endif
  44. }
  45. //javadoc: createBackgroundSubtractorKNN(history, dist2Threshold)
  46. public static BackgroundSubtractorKNN createBackgroundSubtractorKNN(int history, double dist2Threshold) {
  47. #if (UNITY_ANDROID && !UNITY_EDITOR)
  48. BackgroundSubtractorKNN retVal = BackgroundSubtractorKNN.__fromPtr__(video_Video_createBackgroundSubtractorKNN_11(history, dist2Threshold));
  49. return retVal;
  50. #else
  51. return null;
  52. #endif
  53. }
  54. //javadoc: createBackgroundSubtractorKNN(history)
  55. public static BackgroundSubtractorKNN createBackgroundSubtractorKNN(int history) {
  56. #if (UNITY_ANDROID && !UNITY_EDITOR)
  57. BackgroundSubtractorKNN retVal = BackgroundSubtractorKNN.__fromPtr__(video_Video_createBackgroundSubtractorKNN_12(history));
  58. return retVal;
  59. #else
  60. return null;
  61. #endif
  62. }
  63. //javadoc: createBackgroundSubtractorKNN()
  64. public static BackgroundSubtractorKNN createBackgroundSubtractorKNN() {
  65. #if (UNITY_ANDROID && !UNITY_EDITOR)
  66. BackgroundSubtractorKNN retVal = BackgroundSubtractorKNN.__fromPtr__(video_Video_createBackgroundSubtractorKNN_13());
  67. return retVal;
  68. #else
  69. return null;
  70. #endif
  71. }
  72. //
  73. // C++: Ptr_BackgroundSubtractorMOG2 cv::createBackgroundSubtractorMOG2(int history = 500, double varThreshold = 16, bool detectShadows = true)
  74. //
  75. //javadoc: createBackgroundSubtractorMOG2(history, varThreshold, detectShadows)
  76. public static BackgroundSubtractorMOG2 createBackgroundSubtractorMOG2(int history, double varThreshold, bool detectShadows) {
  77. #if (UNITY_ANDROID && !UNITY_EDITOR)
  78. BackgroundSubtractorMOG2 retVal = BackgroundSubtractorMOG2.__fromPtr__(video_Video_createBackgroundSubtractorMOG2_10(history, varThreshold, detectShadows));
  79. return retVal;
  80. #else
  81. return null;
  82. #endif
  83. }
  84. //javadoc: createBackgroundSubtractorMOG2(history, varThreshold)
  85. public static BackgroundSubtractorMOG2 createBackgroundSubtractorMOG2(int history, double varThreshold) {
  86. #if (UNITY_ANDROID && !UNITY_EDITOR)
  87. BackgroundSubtractorMOG2 retVal = BackgroundSubtractorMOG2.__fromPtr__(video_Video_createBackgroundSubtractorMOG2_11(history, varThreshold));
  88. return retVal;
  89. #else
  90. return null;
  91. #endif
  92. }
  93. //javadoc: createBackgroundSubtractorMOG2(history)
  94. public static BackgroundSubtractorMOG2 createBackgroundSubtractorMOG2(int history) {
  95. #if (UNITY_ANDROID && !UNITY_EDITOR)
  96. BackgroundSubtractorMOG2 retVal = BackgroundSubtractorMOG2.__fromPtr__(video_Video_createBackgroundSubtractorMOG2_12(history));
  97. return retVal;
  98. #else
  99. return null;
  100. #endif
  101. }
  102. //javadoc: createBackgroundSubtractorMOG2()
  103. public static BackgroundSubtractorMOG2 createBackgroundSubtractorMOG2() {
  104. #if (UNITY_ANDROID && !UNITY_EDITOR)
  105. BackgroundSubtractorMOG2 retVal = BackgroundSubtractorMOG2.__fromPtr__(video_Video_createBackgroundSubtractorMOG2_13());
  106. return retVal;
  107. #else
  108. return null;
  109. #endif
  110. }
  111. //
  112. // C++: RotatedRect cv::CamShift(Mat probImage, Rect& window, TermCriteria criteria)
  113. //
  114. //javadoc: CamShift(probImage, window, criteria)
  115. public static RotatedRect CamShift(Mat probImage, Rect window, TermCriteria criteria) {
  116. if (probImage != null) probImage.ThrowIfDisposed();
  117. #if (UNITY_ANDROID && !UNITY_EDITOR)
  118. double[] window_out = new double[4];
  119. double[] tmpArray = new double[5];
  120. video_Video_CamShift_10(probImage.nativeObj, window.x, window.y, window.width, window.height, window_out, criteria.type, criteria.maxCount, criteria.epsilon, tmpArray);
  121. RotatedRect retVal = new RotatedRect(tmpArray);
  122. if (window != null) { window.x = (int)window_out[0]; window.y = (int)window_out[1]; window.width = (int)window_out[2]; window.height = (int)window_out[3]; }
  123. return retVal;
  124. #else
  125. return null;
  126. #endif
  127. }
  128. //
  129. // C++: bool cv::writeOpticalFlow(String path, Mat flow)
  130. //
  131. //javadoc: writeOpticalFlow(path, flow)
  132. public static bool writeOpticalFlow(string path, Mat flow) {
  133. if (flow != null) flow.ThrowIfDisposed();
  134. #if (UNITY_ANDROID && !UNITY_EDITOR)
  135. bool retVal = video_Video_writeOpticalFlow_10(path, flow.nativeObj);
  136. return retVal;
  137. #else
  138. return false;
  139. #endif
  140. }
  141. //
  142. // C++: double cv::findTransformECC(Mat templateImage, Mat inputImage, Mat& warpMatrix, int motionType = MOTION_AFFINE, TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), Mat inputMask = Mat())
  143. //
  144. //javadoc: findTransformECC(templateImage, inputImage, warpMatrix, motionType, criteria, inputMask)
  145. public static double findTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix, int motionType, TermCriteria criteria, Mat inputMask) {
  146. if (templateImage != null) templateImage.ThrowIfDisposed();
  147. if (inputImage != null) inputImage.ThrowIfDisposed();
  148. if (warpMatrix != null) warpMatrix.ThrowIfDisposed();
  149. if (inputMask != null) inputMask.ThrowIfDisposed();
  150. #if (UNITY_ANDROID && !UNITY_EDITOR)
  151. double retVal = video_Video_findTransformECC_10(templateImage.nativeObj, inputImage.nativeObj, warpMatrix.nativeObj, motionType, criteria.type, criteria.maxCount, criteria.epsilon, inputMask.nativeObj);
  152. return retVal;
  153. #else
  154. return -1;
  155. #endif
  156. }
  157. //javadoc: findTransformECC(templateImage, inputImage, warpMatrix, motionType, criteria)
  158. public static double findTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix, int motionType, TermCriteria criteria) {
  159. if (templateImage != null) templateImage.ThrowIfDisposed();
  160. if (inputImage != null) inputImage.ThrowIfDisposed();
  161. if (warpMatrix != null) warpMatrix.ThrowIfDisposed();
  162. #if (UNITY_ANDROID && !UNITY_EDITOR)
  163. double retVal = video_Video_findTransformECC_11(templateImage.nativeObj, inputImage.nativeObj, warpMatrix.nativeObj, motionType, criteria.type, criteria.maxCount, criteria.epsilon);
  164. return retVal;
  165. #else
  166. return -1;
  167. #endif
  168. }
  169. //javadoc: findTransformECC(templateImage, inputImage, warpMatrix, motionType)
  170. public static double findTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix, int motionType) {
  171. if (templateImage != null) templateImage.ThrowIfDisposed();
  172. if (inputImage != null) inputImage.ThrowIfDisposed();
  173. if (warpMatrix != null) warpMatrix.ThrowIfDisposed();
  174. #if (UNITY_ANDROID && !UNITY_EDITOR)
  175. double retVal = video_Video_findTransformECC_12(templateImage.nativeObj, inputImage.nativeObj, warpMatrix.nativeObj, motionType);
  176. return retVal;
  177. #else
  178. return -1;
  179. #endif
  180. }
  181. //javadoc: findTransformECC(templateImage, inputImage, warpMatrix)
  182. public static double findTransformECC(Mat templateImage, Mat inputImage, Mat warpMatrix) {
  183. if (templateImage != null) templateImage.ThrowIfDisposed();
  184. if (inputImage != null) inputImage.ThrowIfDisposed();
  185. if (warpMatrix != null) warpMatrix.ThrowIfDisposed();
  186. #if (UNITY_ANDROID && !UNITY_EDITOR)
  187. double retVal = video_Video_findTransformECC_13(templateImage.nativeObj, inputImage.nativeObj, warpMatrix.nativeObj);
  188. return retVal;
  189. #else
  190. return -1;
  191. #endif
  192. }
  193. //
  194. // C++: int cv::buildOpticalFlowPyramid(Mat img, vector_Mat& pyramid, Size winSize, int maxLevel, bool withDerivatives = true, int pyrBorder = BORDER_REFLECT_101, int derivBorder = BORDER_CONSTANT, bool tryReuseInputImage = true)
  195. //
  196. //javadoc: buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel, withDerivatives, pyrBorder, derivBorder, tryReuseInputImage)
  197. public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel, bool withDerivatives, int pyrBorder, int derivBorder, bool tryReuseInputImage) {
  198. if (img != null) img.ThrowIfDisposed();
  199. #if (UNITY_ANDROID && !UNITY_EDITOR)
  200. Mat pyramid_mat = new Mat();
  201. int retVal = video_Video_buildOpticalFlowPyramid_10(img.nativeObj, pyramid_mat.nativeObj, winSize.width, winSize.height, maxLevel, withDerivatives, pyrBorder, derivBorder, tryReuseInputImage);
  202. Converters.Mat_to_vector_Mat(pyramid_mat, pyramid);
  203. pyramid_mat.release();
  204. return retVal;
  205. #else
  206. return -1;
  207. #endif
  208. }
  209. //javadoc: buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel, withDerivatives, pyrBorder, derivBorder)
  210. public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel, bool withDerivatives, int pyrBorder, int derivBorder) {
  211. if (img != null) img.ThrowIfDisposed();
  212. #if (UNITY_ANDROID && !UNITY_EDITOR)
  213. Mat pyramid_mat = new Mat();
  214. int retVal = video_Video_buildOpticalFlowPyramid_11(img.nativeObj, pyramid_mat.nativeObj, winSize.width, winSize.height, maxLevel, withDerivatives, pyrBorder, derivBorder);
  215. Converters.Mat_to_vector_Mat(pyramid_mat, pyramid);
  216. pyramid_mat.release();
  217. return retVal;
  218. #else
  219. return -1;
  220. #endif
  221. }
  222. //javadoc: buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel, withDerivatives, pyrBorder)
  223. public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel, bool withDerivatives, int pyrBorder) {
  224. if (img != null) img.ThrowIfDisposed();
  225. #if (UNITY_ANDROID && !UNITY_EDITOR)
  226. Mat pyramid_mat = new Mat();
  227. int retVal = video_Video_buildOpticalFlowPyramid_12(img.nativeObj, pyramid_mat.nativeObj, winSize.width, winSize.height, maxLevel, withDerivatives, pyrBorder);
  228. Converters.Mat_to_vector_Mat(pyramid_mat, pyramid);
  229. pyramid_mat.release();
  230. return retVal;
  231. #else
  232. return -1;
  233. #endif
  234. }
  235. //javadoc: buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel, withDerivatives)
  236. public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel, bool withDerivatives) {
  237. if (img != null) img.ThrowIfDisposed();
  238. #if (UNITY_ANDROID && !UNITY_EDITOR)
  239. Mat pyramid_mat = new Mat();
  240. int retVal = video_Video_buildOpticalFlowPyramid_13(img.nativeObj, pyramid_mat.nativeObj, winSize.width, winSize.height, maxLevel, withDerivatives);
  241. Converters.Mat_to_vector_Mat(pyramid_mat, pyramid);
  242. pyramid_mat.release();
  243. return retVal;
  244. #else
  245. return -1;
  246. #endif
  247. }
  248. //javadoc: buildOpticalFlowPyramid(img, pyramid, winSize, maxLevel)
  249. public static int buildOpticalFlowPyramid(Mat img, List<Mat> pyramid, Size winSize, int maxLevel) {
  250. if (img != null) img.ThrowIfDisposed();
  251. #if (UNITY_ANDROID && !UNITY_EDITOR)
  252. Mat pyramid_mat = new Mat();
  253. int retVal = video_Video_buildOpticalFlowPyramid_14(img.nativeObj, pyramid_mat.nativeObj, winSize.width, winSize.height, maxLevel);
  254. Converters.Mat_to_vector_Mat(pyramid_mat, pyramid);
  255. pyramid_mat.release();
  256. return retVal;
  257. #else
  258. return -1;
  259. #endif
  260. }
  261. //
  262. // C++: int cv::meanShift(Mat probImage, Rect& window, TermCriteria criteria)
  263. //
  264. //javadoc: meanShift(probImage, window, criteria)
  265. public static int meanShift(Mat probImage, Rect window, TermCriteria criteria) {
  266. if (probImage != null) probImage.ThrowIfDisposed();
  267. #if (UNITY_ANDROID && !UNITY_EDITOR)
  268. double[] window_out = new double[4];
  269. int retVal = video_Video_meanShift_10(probImage.nativeObj, window.x, window.y, window.width, window.height, window_out, criteria.type, criteria.maxCount, criteria.epsilon);
  270. if (window != null) { window.x = (int)window_out[0]; window.y = (int)window_out[1]; window.width = (int)window_out[2]; window.height = (int)window_out[3]; }
  271. return retVal;
  272. #else
  273. return -1;
  274. #endif
  275. }
  276. //
  277. // C++: void cv::calcOpticalFlowFarneback(Mat prev, Mat next, Mat& flow, double pyr_scale, int levels, int winsize, int iterations, int poly_n, double poly_sigma, int flags)
  278. //
  279. //javadoc: calcOpticalFlowFarneback(prev, next, flow, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags)
  280. public static void calcOpticalFlowFarneback(Mat prev, Mat next, Mat flow, double pyr_scale, int levels, int winsize, int iterations, int poly_n, double poly_sigma, int flags) {
  281. if (prev != null) prev.ThrowIfDisposed();
  282. if (next != null) next.ThrowIfDisposed();
  283. if (flow != null) flow.ThrowIfDisposed();
  284. #if (UNITY_ANDROID && !UNITY_EDITOR)
  285. video_Video_calcOpticalFlowFarneback_10(prev.nativeObj, next.nativeObj, flow.nativeObj, pyr_scale, levels, winsize, iterations, poly_n, poly_sigma, flags);
  286. return;
  287. #else
  288. return;
  289. #endif
  290. }
  291. //
  292. // C++: void cv::calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, vector_Point2f prevPts, vector_Point2f& nextPts, vector_uchar& status, vector_float& err, Size winSize = Size(21,21), int maxLevel = 3, TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), int flags = 0, double minEigThreshold = 1e-4)
  293. //
  294. //javadoc: calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err, winSize, maxLevel, criteria, flags, minEigThreshold)
  295. public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel, TermCriteria criteria, int flags, double minEigThreshold) {
  296. if (prevImg != null) prevImg.ThrowIfDisposed();
  297. if (nextImg != null) nextImg.ThrowIfDisposed();
  298. if (prevPts != null) prevPts.ThrowIfDisposed();
  299. if (nextPts != null) nextPts.ThrowIfDisposed();
  300. if (status != null) status.ThrowIfDisposed();
  301. if (err != null) err.ThrowIfDisposed();
  302. #if (UNITY_ANDROID && !UNITY_EDITOR)
  303. Mat prevPts_mat = prevPts;
  304. Mat nextPts_mat = nextPts;
  305. Mat status_mat = status;
  306. Mat err_mat = err;
  307. video_Video_calcOpticalFlowPyrLK_10(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj, winSize.width, winSize.height, maxLevel, criteria.type, criteria.maxCount, criteria.epsilon, flags, minEigThreshold);
  308. return;
  309. #else
  310. return;
  311. #endif
  312. }
  313. //javadoc: calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err, winSize, maxLevel, criteria, flags)
  314. public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel, TermCriteria criteria, int flags) {
  315. if (prevImg != null) prevImg.ThrowIfDisposed();
  316. if (nextImg != null) nextImg.ThrowIfDisposed();
  317. if (prevPts != null) prevPts.ThrowIfDisposed();
  318. if (nextPts != null) nextPts.ThrowIfDisposed();
  319. if (status != null) status.ThrowIfDisposed();
  320. if (err != null) err.ThrowIfDisposed();
  321. #if (UNITY_ANDROID && !UNITY_EDITOR)
  322. Mat prevPts_mat = prevPts;
  323. Mat nextPts_mat = nextPts;
  324. Mat status_mat = status;
  325. Mat err_mat = err;
  326. video_Video_calcOpticalFlowPyrLK_11(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj, winSize.width, winSize.height, maxLevel, criteria.type, criteria.maxCount, criteria.epsilon, flags);
  327. return;
  328. #else
  329. return;
  330. #endif
  331. }
  332. //javadoc: calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err, winSize, maxLevel, criteria)
  333. public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel, TermCriteria criteria) {
  334. if (prevImg != null) prevImg.ThrowIfDisposed();
  335. if (nextImg != null) nextImg.ThrowIfDisposed();
  336. if (prevPts != null) prevPts.ThrowIfDisposed();
  337. if (nextPts != null) nextPts.ThrowIfDisposed();
  338. if (status != null) status.ThrowIfDisposed();
  339. if (err != null) err.ThrowIfDisposed();
  340. #if (UNITY_ANDROID && !UNITY_EDITOR)
  341. Mat prevPts_mat = prevPts;
  342. Mat nextPts_mat = nextPts;
  343. Mat status_mat = status;
  344. Mat err_mat = err;
  345. video_Video_calcOpticalFlowPyrLK_12(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj, winSize.width, winSize.height, maxLevel, criteria.type, criteria.maxCount, criteria.epsilon);
  346. return;
  347. #else
  348. return;
  349. #endif
  350. }
  351. //javadoc: calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err, winSize, maxLevel)
  352. public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize, int maxLevel) {
  353. if (prevImg != null) prevImg.ThrowIfDisposed();
  354. if (nextImg != null) nextImg.ThrowIfDisposed();
  355. if (prevPts != null) prevPts.ThrowIfDisposed();
  356. if (nextPts != null) nextPts.ThrowIfDisposed();
  357. if (status != null) status.ThrowIfDisposed();
  358. if (err != null) err.ThrowIfDisposed();
  359. #if (UNITY_ANDROID && !UNITY_EDITOR)
  360. Mat prevPts_mat = prevPts;
  361. Mat nextPts_mat = nextPts;
  362. Mat status_mat = status;
  363. Mat err_mat = err;
  364. video_Video_calcOpticalFlowPyrLK_13(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj, winSize.width, winSize.height, maxLevel);
  365. return;
  366. #else
  367. return;
  368. #endif
  369. }
  370. //javadoc: calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err, winSize)
  371. public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err, Size winSize) {
  372. if (prevImg != null) prevImg.ThrowIfDisposed();
  373. if (nextImg != null) nextImg.ThrowIfDisposed();
  374. if (prevPts != null) prevPts.ThrowIfDisposed();
  375. if (nextPts != null) nextPts.ThrowIfDisposed();
  376. if (status != null) status.ThrowIfDisposed();
  377. if (err != null) err.ThrowIfDisposed();
  378. #if (UNITY_ANDROID && !UNITY_EDITOR)
  379. Mat prevPts_mat = prevPts;
  380. Mat nextPts_mat = nextPts;
  381. Mat status_mat = status;
  382. Mat err_mat = err;
  383. video_Video_calcOpticalFlowPyrLK_14(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj, winSize.width, winSize.height);
  384. return;
  385. #else
  386. return;
  387. #endif
  388. }
  389. //javadoc: calcOpticalFlowPyrLK(prevImg, nextImg, prevPts, nextPts, status, err)
  390. public static void calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, MatOfPoint2f prevPts, MatOfPoint2f nextPts, MatOfByte status, MatOfFloat err) {
  391. if (prevImg != null) prevImg.ThrowIfDisposed();
  392. if (nextImg != null) nextImg.ThrowIfDisposed();
  393. if (prevPts != null) prevPts.ThrowIfDisposed();
  394. if (nextPts != null) nextPts.ThrowIfDisposed();
  395. if (status != null) status.ThrowIfDisposed();
  396. if (err != null) err.ThrowIfDisposed();
  397. #if (UNITY_ANDROID && !UNITY_EDITOR)
  398. Mat prevPts_mat = prevPts;
  399. Mat nextPts_mat = nextPts;
  400. Mat status_mat = status;
  401. Mat err_mat = err;
  402. video_Video_calcOpticalFlowPyrLK_15(prevImg.nativeObj, nextImg.nativeObj, prevPts_mat.nativeObj, nextPts_mat.nativeObj, status_mat.nativeObj, err_mat.nativeObj);
  403. return;
  404. #else
  405. return;
  406. #endif
  407. }
  408. #if (UNITY_ANDROID && !UNITY_EDITOR)
  409. const string LIBNAME = "opencvforunity";
  410. // C++: Mat cv::readOpticalFlow(String path)
  411. [DllImport(LIBNAME)]
  412. private static extern IntPtr video_Video_readOpticalFlow_10(string path);
  413. // C++: Ptr_BackgroundSubtractorKNN cv::createBackgroundSubtractorKNN(int history = 500, double dist2Threshold = 400.0, bool detectShadows = true)
  414. [DllImport(LIBNAME)]
  415. private static extern IntPtr video_Video_createBackgroundSubtractorKNN_10(int history, double dist2Threshold, bool detectShadows);
  416. [DllImport(LIBNAME)]
  417. private static extern IntPtr video_Video_createBackgroundSubtractorKNN_11(int history, double dist2Threshold);
  418. [DllImport(LIBNAME)]
  419. private static extern IntPtr video_Video_createBackgroundSubtractorKNN_12(int history);
  420. [DllImport(LIBNAME)]
  421. private static extern IntPtr video_Video_createBackgroundSubtractorKNN_13();
  422. // C++: Ptr_BackgroundSubtractorMOG2 cv::createBackgroundSubtractorMOG2(int history = 500, double varThreshold = 16, bool detectShadows = true)
  423. [DllImport(LIBNAME)]
  424. private static extern IntPtr video_Video_createBackgroundSubtractorMOG2_10(int history, double varThreshold, bool detectShadows);
  425. [DllImport(LIBNAME)]
  426. private static extern IntPtr video_Video_createBackgroundSubtractorMOG2_11(int history, double varThreshold);
  427. [DllImport(LIBNAME)]
  428. private static extern IntPtr video_Video_createBackgroundSubtractorMOG2_12(int history);
  429. [DllImport(LIBNAME)]
  430. private static extern IntPtr video_Video_createBackgroundSubtractorMOG2_13();
  431. // C++: RotatedRect cv::CamShift(Mat probImage, Rect& window, TermCriteria criteria)
  432. [DllImport(LIBNAME)]
  433. private static extern void video_Video_CamShift_10(IntPtr probImage_nativeObj, int window_x, int window_y, int window_width, int window_height, double[] window_out, int criteria_type, int criteria_maxCount, double criteria_epsilon, double[] retVal);
  434. // C++: bool cv::writeOpticalFlow(String path, Mat flow)
  435. [DllImport(LIBNAME)]
  436. private static extern bool video_Video_writeOpticalFlow_10(string path, IntPtr flow_nativeObj);
  437. // C++: double cv::findTransformECC(Mat templateImage, Mat inputImage, Mat& warpMatrix, int motionType = MOTION_AFFINE, TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 50, 0.001), Mat inputMask = Mat())
  438. [DllImport(LIBNAME)]
  439. private static extern double video_Video_findTransformECC_10(IntPtr templateImage_nativeObj, IntPtr inputImage_nativeObj, IntPtr warpMatrix_nativeObj, int motionType, int criteria_type, int criteria_maxCount, double criteria_epsilon, IntPtr inputMask_nativeObj);
  440. [DllImport(LIBNAME)]
  441. private static extern double video_Video_findTransformECC_11(IntPtr templateImage_nativeObj, IntPtr inputImage_nativeObj, IntPtr warpMatrix_nativeObj, int motionType, int criteria_type, int criteria_maxCount, double criteria_epsilon);
  442. [DllImport(LIBNAME)]
  443. private static extern double video_Video_findTransformECC_12(IntPtr templateImage_nativeObj, IntPtr inputImage_nativeObj, IntPtr warpMatrix_nativeObj, int motionType);
  444. [DllImport(LIBNAME)]
  445. private static extern double video_Video_findTransformECC_13(IntPtr templateImage_nativeObj, IntPtr inputImage_nativeObj, IntPtr warpMatrix_nativeObj);
  446. // C++: int cv::buildOpticalFlowPyramid(Mat img, vector_Mat& pyramid, Size winSize, int maxLevel, bool withDerivatives = true, int pyrBorder = BORDER_REFLECT_101, int derivBorder = BORDER_CONSTANT, bool tryReuseInputImage = true)
  447. [DllImport(LIBNAME)]
  448. private static extern int video_Video_buildOpticalFlowPyramid_10(IntPtr img_nativeObj, IntPtr pyramid_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, bool withDerivatives, int pyrBorder, int derivBorder, bool tryReuseInputImage);
  449. [DllImport(LIBNAME)]
  450. private static extern int video_Video_buildOpticalFlowPyramid_11(IntPtr img_nativeObj, IntPtr pyramid_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, bool withDerivatives, int pyrBorder, int derivBorder);
  451. [DllImport(LIBNAME)]
  452. private static extern int video_Video_buildOpticalFlowPyramid_12(IntPtr img_nativeObj, IntPtr pyramid_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, bool withDerivatives, int pyrBorder);
  453. [DllImport(LIBNAME)]
  454. private static extern int video_Video_buildOpticalFlowPyramid_13(IntPtr img_nativeObj, IntPtr pyramid_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, bool withDerivatives);
  455. [DllImport(LIBNAME)]
  456. private static extern int video_Video_buildOpticalFlowPyramid_14(IntPtr img_nativeObj, IntPtr pyramid_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel);
  457. // C++: int cv::meanShift(Mat probImage, Rect& window, TermCriteria criteria)
  458. [DllImport(LIBNAME)]
  459. private static extern int video_Video_meanShift_10(IntPtr probImage_nativeObj, int window_x, int window_y, int window_width, int window_height, double[] window_out, int criteria_type, int criteria_maxCount, double criteria_epsilon);
  460. // C++: void cv::calcOpticalFlowFarneback(Mat prev, Mat next, Mat& flow, double pyr_scale, int levels, int winsize, int iterations, int poly_n, double poly_sigma, int flags)
  461. [DllImport(LIBNAME)]
  462. private static extern void video_Video_calcOpticalFlowFarneback_10(IntPtr prev_nativeObj, IntPtr next_nativeObj, IntPtr flow_nativeObj, double pyr_scale, int levels, int winsize, int iterations, int poly_n, double poly_sigma, int flags);
  463. // C++: void cv::calcOpticalFlowPyrLK(Mat prevImg, Mat nextImg, vector_Point2f prevPts, vector_Point2f& nextPts, vector_uchar& status, vector_float& err, Size winSize = Size(21,21), int maxLevel = 3, TermCriteria criteria = TermCriteria(TermCriteria::COUNT+TermCriteria::EPS, 30, 0.01), int flags = 0, double minEigThreshold = 1e-4)
  464. [DllImport(LIBNAME)]
  465. private static extern void video_Video_calcOpticalFlowPyrLK_10(IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_mat_nativeObj, IntPtr nextPts_mat_nativeObj, IntPtr status_mat_nativeObj, IntPtr err_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, int criteria_type, int criteria_maxCount, double criteria_epsilon, int flags, double minEigThreshold);
  466. [DllImport(LIBNAME)]
  467. private static extern void video_Video_calcOpticalFlowPyrLK_11(IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_mat_nativeObj, IntPtr nextPts_mat_nativeObj, IntPtr status_mat_nativeObj, IntPtr err_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, int criteria_type, int criteria_maxCount, double criteria_epsilon, int flags);
  468. [DllImport(LIBNAME)]
  469. private static extern void video_Video_calcOpticalFlowPyrLK_12(IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_mat_nativeObj, IntPtr nextPts_mat_nativeObj, IntPtr status_mat_nativeObj, IntPtr err_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel, int criteria_type, int criteria_maxCount, double criteria_epsilon);
  470. [DllImport(LIBNAME)]
  471. private static extern void video_Video_calcOpticalFlowPyrLK_13(IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_mat_nativeObj, IntPtr nextPts_mat_nativeObj, IntPtr status_mat_nativeObj, IntPtr err_mat_nativeObj, double winSize_width, double winSize_height, int maxLevel);
  472. [DllImport(LIBNAME)]
  473. private static extern void video_Video_calcOpticalFlowPyrLK_14(IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_mat_nativeObj, IntPtr nextPts_mat_nativeObj, IntPtr status_mat_nativeObj, IntPtr err_mat_nativeObj, double winSize_width, double winSize_height);
  474. [DllImport(LIBNAME)]
  475. private static extern void video_Video_calcOpticalFlowPyrLK_15(IntPtr prevImg_nativeObj, IntPtr nextImg_nativeObj, IntPtr prevPts_mat_nativeObj, IntPtr nextPts_mat_nativeObj, IntPtr status_mat_nativeObj, IntPtr err_mat_nativeObj);
  476. #endif
  477. }
  478. }