Video.cs 32 KB

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