DISOpticalFlow.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  1. using OpenCVForUnity.CoreModule;
  2. using OpenCVForUnity.UtilsModule;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Runtime.InteropServices;
  6. namespace OpenCVForUnity.VideoModule
  7. {
  8. // C++: class DISOpticalFlow
  9. /**
  10. * DIS optical flow algorithm.
  11. *
  12. * This class implements the Dense Inverse Search (DIS) optical flow algorithm. More
  13. * details about the algorithm can be found at CITE: Kroeger2016 . Includes three presets with preselected
  14. * parameters to provide reasonable trade-off between speed and quality. However, even the slowest preset is
  15. * still relatively fast, use DeepFlow if you need better quality and don't care about speed.
  16. *
  17. * This implementation includes several additional features compared to the algorithm described in the paper,
  18. * including spatial propagation of flow vectors (REF: getUseSpatialPropagation), as well as an option to
  19. * utilize an initial flow approximation passed to REF: calc (which is, essentially, temporal propagation,
  20. * if the previous frame's flow field is passed).
  21. */
  22. public class DISOpticalFlow : DenseOpticalFlow
  23. {
  24. protected override void Dispose(bool disposing)
  25. {
  26. try
  27. {
  28. if (disposing)
  29. {
  30. }
  31. if (IsEnabledDispose)
  32. {
  33. if (nativeObj != IntPtr.Zero)
  34. video_DISOpticalFlow_delete(nativeObj);
  35. nativeObj = IntPtr.Zero;
  36. }
  37. }
  38. finally
  39. {
  40. base.Dispose(disposing);
  41. }
  42. }
  43. protected internal DISOpticalFlow(IntPtr addr) : base(addr) { }
  44. // internal usage only
  45. public static new DISOpticalFlow __fromPtr__(IntPtr addr) { return new DISOpticalFlow(addr); }
  46. // C++: enum <unnamed>
  47. public const int PRESET_ULTRAFAST = 0;
  48. public const int PRESET_FAST = 1;
  49. public const int PRESET_MEDIUM = 2;
  50. //
  51. // C++: int cv::DISOpticalFlow::getFinestScale()
  52. //
  53. /**
  54. * Finest level of the Gaussian pyramid on which the flow is computed (zero level
  55. * corresponds to the original image resolution). The final flow is obtained by bilinear upscaling.
  56. * SEE: setFinestScale
  57. * return automatically generated
  58. */
  59. public int getFinestScale()
  60. {
  61. ThrowIfDisposed();
  62. return video_DISOpticalFlow_getFinestScale_10(nativeObj);
  63. }
  64. //
  65. // C++: void cv::DISOpticalFlow::setFinestScale(int val)
  66. //
  67. /**
  68. * getFinestScale SEE: getFinestScale
  69. * param val automatically generated
  70. */
  71. public void setFinestScale(int val)
  72. {
  73. ThrowIfDisposed();
  74. video_DISOpticalFlow_setFinestScale_10(nativeObj, val);
  75. }
  76. //
  77. // C++: int cv::DISOpticalFlow::getPatchSize()
  78. //
  79. /**
  80. * Size of an image patch for matching (in pixels). Normally, default 8x8 patches work well
  81. * enough in most cases.
  82. * SEE: setPatchSize
  83. * return automatically generated
  84. */
  85. public int getPatchSize()
  86. {
  87. ThrowIfDisposed();
  88. return video_DISOpticalFlow_getPatchSize_10(nativeObj);
  89. }
  90. //
  91. // C++: void cv::DISOpticalFlow::setPatchSize(int val)
  92. //
  93. /**
  94. * getPatchSize SEE: getPatchSize
  95. * param val automatically generated
  96. */
  97. public void setPatchSize(int val)
  98. {
  99. ThrowIfDisposed();
  100. video_DISOpticalFlow_setPatchSize_10(nativeObj, val);
  101. }
  102. //
  103. // C++: int cv::DISOpticalFlow::getPatchStride()
  104. //
  105. /**
  106. * Stride between neighbor patches. Must be less than patch size. Lower values correspond
  107. * to higher flow quality.
  108. * SEE: setPatchStride
  109. * return automatically generated
  110. */
  111. public int getPatchStride()
  112. {
  113. ThrowIfDisposed();
  114. return video_DISOpticalFlow_getPatchStride_10(nativeObj);
  115. }
  116. //
  117. // C++: void cv::DISOpticalFlow::setPatchStride(int val)
  118. //
  119. /**
  120. * getPatchStride SEE: getPatchStride
  121. * param val automatically generated
  122. */
  123. public void setPatchStride(int val)
  124. {
  125. ThrowIfDisposed();
  126. video_DISOpticalFlow_setPatchStride_10(nativeObj, val);
  127. }
  128. //
  129. // C++: int cv::DISOpticalFlow::getGradientDescentIterations()
  130. //
  131. /**
  132. * Maximum number of gradient descent iterations in the patch inverse search stage. Higher values
  133. * may improve quality in some cases.
  134. * SEE: setGradientDescentIterations
  135. * return automatically generated
  136. */
  137. public int getGradientDescentIterations()
  138. {
  139. ThrowIfDisposed();
  140. return video_DISOpticalFlow_getGradientDescentIterations_10(nativeObj);
  141. }
  142. //
  143. // C++: void cv::DISOpticalFlow::setGradientDescentIterations(int val)
  144. //
  145. /**
  146. * getGradientDescentIterations SEE: getGradientDescentIterations
  147. * param val automatically generated
  148. */
  149. public void setGradientDescentIterations(int val)
  150. {
  151. ThrowIfDisposed();
  152. video_DISOpticalFlow_setGradientDescentIterations_10(nativeObj, val);
  153. }
  154. //
  155. // C++: int cv::DISOpticalFlow::getVariationalRefinementIterations()
  156. //
  157. /**
  158. * Number of fixed point iterations of variational refinement per scale. Set to zero to
  159. * disable variational refinement completely. Higher values will typically result in more smooth and
  160. * high-quality flow.
  161. * SEE: setGradientDescentIterations
  162. * return automatically generated
  163. */
  164. public int getVariationalRefinementIterations()
  165. {
  166. ThrowIfDisposed();
  167. return video_DISOpticalFlow_getVariationalRefinementIterations_10(nativeObj);
  168. }
  169. //
  170. // C++: void cv::DISOpticalFlow::setVariationalRefinementIterations(int val)
  171. //
  172. /**
  173. * getGradientDescentIterations SEE: getGradientDescentIterations
  174. * param val automatically generated
  175. */
  176. public void setVariationalRefinementIterations(int val)
  177. {
  178. ThrowIfDisposed();
  179. video_DISOpticalFlow_setVariationalRefinementIterations_10(nativeObj, val);
  180. }
  181. //
  182. // C++: float cv::DISOpticalFlow::getVariationalRefinementAlpha()
  183. //
  184. /**
  185. * Weight of the smoothness term
  186. * SEE: setVariationalRefinementAlpha
  187. * return automatically generated
  188. */
  189. public float getVariationalRefinementAlpha()
  190. {
  191. ThrowIfDisposed();
  192. return video_DISOpticalFlow_getVariationalRefinementAlpha_10(nativeObj);
  193. }
  194. //
  195. // C++: void cv::DISOpticalFlow::setVariationalRefinementAlpha(float val)
  196. //
  197. /**
  198. * getVariationalRefinementAlpha SEE: getVariationalRefinementAlpha
  199. * param val automatically generated
  200. */
  201. public void setVariationalRefinementAlpha(float val)
  202. {
  203. ThrowIfDisposed();
  204. video_DISOpticalFlow_setVariationalRefinementAlpha_10(nativeObj, val);
  205. }
  206. //
  207. // C++: float cv::DISOpticalFlow::getVariationalRefinementDelta()
  208. //
  209. /**
  210. * Weight of the color constancy term
  211. * SEE: setVariationalRefinementDelta
  212. * return automatically generated
  213. */
  214. public float getVariationalRefinementDelta()
  215. {
  216. ThrowIfDisposed();
  217. return video_DISOpticalFlow_getVariationalRefinementDelta_10(nativeObj);
  218. }
  219. //
  220. // C++: void cv::DISOpticalFlow::setVariationalRefinementDelta(float val)
  221. //
  222. /**
  223. * getVariationalRefinementDelta SEE: getVariationalRefinementDelta
  224. * param val automatically generated
  225. */
  226. public void setVariationalRefinementDelta(float val)
  227. {
  228. ThrowIfDisposed();
  229. video_DISOpticalFlow_setVariationalRefinementDelta_10(nativeObj, val);
  230. }
  231. //
  232. // C++: float cv::DISOpticalFlow::getVariationalRefinementGamma()
  233. //
  234. /**
  235. * Weight of the gradient constancy term
  236. * SEE: setVariationalRefinementGamma
  237. * return automatically generated
  238. */
  239. public float getVariationalRefinementGamma()
  240. {
  241. ThrowIfDisposed();
  242. return video_DISOpticalFlow_getVariationalRefinementGamma_10(nativeObj);
  243. }
  244. //
  245. // C++: void cv::DISOpticalFlow::setVariationalRefinementGamma(float val)
  246. //
  247. /**
  248. * getVariationalRefinementGamma SEE: getVariationalRefinementGamma
  249. * param val automatically generated
  250. */
  251. public void setVariationalRefinementGamma(float val)
  252. {
  253. ThrowIfDisposed();
  254. video_DISOpticalFlow_setVariationalRefinementGamma_10(nativeObj, val);
  255. }
  256. //
  257. // C++: bool cv::DISOpticalFlow::getUseMeanNormalization()
  258. //
  259. /**
  260. * Whether to use mean-normalization of patches when computing patch distance. It is turned on
  261. * by default as it typically provides a noticeable quality boost because of increased robustness to
  262. * illumination variations. Turn it off if you are certain that your sequence doesn't contain any changes
  263. * in illumination.
  264. * SEE: setUseMeanNormalization
  265. * return automatically generated
  266. */
  267. public bool getUseMeanNormalization()
  268. {
  269. ThrowIfDisposed();
  270. return video_DISOpticalFlow_getUseMeanNormalization_10(nativeObj);
  271. }
  272. //
  273. // C++: void cv::DISOpticalFlow::setUseMeanNormalization(bool val)
  274. //
  275. /**
  276. * getUseMeanNormalization SEE: getUseMeanNormalization
  277. * param val automatically generated
  278. */
  279. public void setUseMeanNormalization(bool val)
  280. {
  281. ThrowIfDisposed();
  282. video_DISOpticalFlow_setUseMeanNormalization_10(nativeObj, val);
  283. }
  284. //
  285. // C++: bool cv::DISOpticalFlow::getUseSpatialPropagation()
  286. //
  287. /**
  288. * Whether to use spatial propagation of good optical flow vectors. This option is turned on by
  289. * default, as it tends to work better on average and can sometimes help recover from major errors
  290. * introduced by the coarse-to-fine scheme employed by the DIS optical flow algorithm. Turning this
  291. * option off can make the output flow field a bit smoother, however.
  292. * SEE: setUseSpatialPropagation
  293. * return automatically generated
  294. */
  295. public bool getUseSpatialPropagation()
  296. {
  297. ThrowIfDisposed();
  298. return video_DISOpticalFlow_getUseSpatialPropagation_10(nativeObj);
  299. }
  300. //
  301. // C++: void cv::DISOpticalFlow::setUseSpatialPropagation(bool val)
  302. //
  303. /**
  304. * getUseSpatialPropagation SEE: getUseSpatialPropagation
  305. * param val automatically generated
  306. */
  307. public void setUseSpatialPropagation(bool val)
  308. {
  309. ThrowIfDisposed();
  310. video_DISOpticalFlow_setUseSpatialPropagation_10(nativeObj, val);
  311. }
  312. //
  313. // C++: static Ptr_DISOpticalFlow cv::DISOpticalFlow::create(int preset = DISOpticalFlow::PRESET_FAST)
  314. //
  315. /**
  316. * Creates an instance of DISOpticalFlow
  317. *
  318. * param preset one of PRESET_ULTRAFAST, PRESET_FAST and PRESET_MEDIUM
  319. * return automatically generated
  320. */
  321. public static DISOpticalFlow create(int preset)
  322. {
  323. return DISOpticalFlow.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(video_DISOpticalFlow_create_10(preset)));
  324. }
  325. /**
  326. * Creates an instance of DISOpticalFlow
  327. *
  328. * return automatically generated
  329. */
  330. public static DISOpticalFlow create()
  331. {
  332. return DISOpticalFlow.__fromPtr__(DisposableObject.ThrowIfNullIntPtr(video_DISOpticalFlow_create_11()));
  333. }
  334. #if (UNITY_IOS || UNITY_WEBGL) && !UNITY_EDITOR
  335. const string LIBNAME = "__Internal";
  336. #else
  337. const string LIBNAME = "opencvforunity";
  338. #endif
  339. // C++: int cv::DISOpticalFlow::getFinestScale()
  340. [DllImport(LIBNAME)]
  341. private static extern int video_DISOpticalFlow_getFinestScale_10(IntPtr nativeObj);
  342. // C++: void cv::DISOpticalFlow::setFinestScale(int val)
  343. [DllImport(LIBNAME)]
  344. private static extern void video_DISOpticalFlow_setFinestScale_10(IntPtr nativeObj, int val);
  345. // C++: int cv::DISOpticalFlow::getPatchSize()
  346. [DllImport(LIBNAME)]
  347. private static extern int video_DISOpticalFlow_getPatchSize_10(IntPtr nativeObj);
  348. // C++: void cv::DISOpticalFlow::setPatchSize(int val)
  349. [DllImport(LIBNAME)]
  350. private static extern void video_DISOpticalFlow_setPatchSize_10(IntPtr nativeObj, int val);
  351. // C++: int cv::DISOpticalFlow::getPatchStride()
  352. [DllImport(LIBNAME)]
  353. private static extern int video_DISOpticalFlow_getPatchStride_10(IntPtr nativeObj);
  354. // C++: void cv::DISOpticalFlow::setPatchStride(int val)
  355. [DllImport(LIBNAME)]
  356. private static extern void video_DISOpticalFlow_setPatchStride_10(IntPtr nativeObj, int val);
  357. // C++: int cv::DISOpticalFlow::getGradientDescentIterations()
  358. [DllImport(LIBNAME)]
  359. private static extern int video_DISOpticalFlow_getGradientDescentIterations_10(IntPtr nativeObj);
  360. // C++: void cv::DISOpticalFlow::setGradientDescentIterations(int val)
  361. [DllImport(LIBNAME)]
  362. private static extern void video_DISOpticalFlow_setGradientDescentIterations_10(IntPtr nativeObj, int val);
  363. // C++: int cv::DISOpticalFlow::getVariationalRefinementIterations()
  364. [DllImport(LIBNAME)]
  365. private static extern int video_DISOpticalFlow_getVariationalRefinementIterations_10(IntPtr nativeObj);
  366. // C++: void cv::DISOpticalFlow::setVariationalRefinementIterations(int val)
  367. [DllImport(LIBNAME)]
  368. private static extern void video_DISOpticalFlow_setVariationalRefinementIterations_10(IntPtr nativeObj, int val);
  369. // C++: float cv::DISOpticalFlow::getVariationalRefinementAlpha()
  370. [DllImport(LIBNAME)]
  371. private static extern float video_DISOpticalFlow_getVariationalRefinementAlpha_10(IntPtr nativeObj);
  372. // C++: void cv::DISOpticalFlow::setVariationalRefinementAlpha(float val)
  373. [DllImport(LIBNAME)]
  374. private static extern void video_DISOpticalFlow_setVariationalRefinementAlpha_10(IntPtr nativeObj, float val);
  375. // C++: float cv::DISOpticalFlow::getVariationalRefinementDelta()
  376. [DllImport(LIBNAME)]
  377. private static extern float video_DISOpticalFlow_getVariationalRefinementDelta_10(IntPtr nativeObj);
  378. // C++: void cv::DISOpticalFlow::setVariationalRefinementDelta(float val)
  379. [DllImport(LIBNAME)]
  380. private static extern void video_DISOpticalFlow_setVariationalRefinementDelta_10(IntPtr nativeObj, float val);
  381. // C++: float cv::DISOpticalFlow::getVariationalRefinementGamma()
  382. [DllImport(LIBNAME)]
  383. private static extern float video_DISOpticalFlow_getVariationalRefinementGamma_10(IntPtr nativeObj);
  384. // C++: void cv::DISOpticalFlow::setVariationalRefinementGamma(float val)
  385. [DllImport(LIBNAME)]
  386. private static extern void video_DISOpticalFlow_setVariationalRefinementGamma_10(IntPtr nativeObj, float val);
  387. // C++: bool cv::DISOpticalFlow::getUseMeanNormalization()
  388. [DllImport(LIBNAME)]
  389. [return: MarshalAs(UnmanagedType.U1)]
  390. private static extern bool video_DISOpticalFlow_getUseMeanNormalization_10(IntPtr nativeObj);
  391. // C++: void cv::DISOpticalFlow::setUseMeanNormalization(bool val)
  392. [DllImport(LIBNAME)]
  393. private static extern void video_DISOpticalFlow_setUseMeanNormalization_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool val);
  394. // C++: bool cv::DISOpticalFlow::getUseSpatialPropagation()
  395. [DllImport(LIBNAME)]
  396. [return: MarshalAs(UnmanagedType.U1)]
  397. private static extern bool video_DISOpticalFlow_getUseSpatialPropagation_10(IntPtr nativeObj);
  398. // C++: void cv::DISOpticalFlow::setUseSpatialPropagation(bool val)
  399. [DllImport(LIBNAME)]
  400. private static extern void video_DISOpticalFlow_setUseSpatialPropagation_10(IntPtr nativeObj, [MarshalAs(UnmanagedType.U1)] bool val);
  401. // C++: static Ptr_DISOpticalFlow cv::DISOpticalFlow::create(int preset = DISOpticalFlow::PRESET_FAST)
  402. [DllImport(LIBNAME)]
  403. private static extern IntPtr video_DISOpticalFlow_create_10(int preset);
  404. [DllImport(LIBNAME)]
  405. private static extern IntPtr video_DISOpticalFlow_create_11();
  406. // native support for java finalize()
  407. [DllImport(LIBNAME)]
  408. private static extern void video_DISOpticalFlow_delete(IntPtr nativeObj);
  409. }
  410. }