rlofflow.hpp 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. // This file is part of OpenCV project.
  2. // It is subject to the license terms in the LICENSE file found in the top-level directory
  3. // of this distribution and at http://opencv.org/license.html.
  4. #ifndef __OPENCV_OPTFLOW_RLOFFLOW_HPP__
  5. #define __OPENCV_OPTFLOW_RLOFFLOW_HPP__
  6. #include "opencv2/core.hpp"
  7. #include "opencv2/video.hpp"
  8. namespace cv
  9. {
  10. namespace optflow
  11. {
  12. //! @addtogroup optflow
  13. //! @{
  14. enum SupportRegionType {
  15. SR_FIXED = 0, /**< Apply a constant support region */
  16. SR_CROSS = 1 /**< Apply a adaptive support region obtained by cross-based segmentation
  17. * as described in @cite Senst2014
  18. */
  19. };
  20. enum SolverType {
  21. ST_STANDART = 0, /**< Apply standard iterative refinement */
  22. ST_BILINEAR = 1 /**< Apply optimized iterative refinement based bilinear equation solutions
  23. * as described in @cite Senst2013
  24. */
  25. };
  26. enum InterpolationType
  27. {
  28. INTERP_GEO = 0, /**< Fast geodesic interpolation, see @cite Geistert2016 */
  29. INTERP_EPIC = 1, /**< Edge-preserving interpolation using ximgproc::EdgeAwareInterpolator, see @cite Revaud2015,Geistert2016. */
  30. INTERP_RIC = 2, /**< SLIC based robust interpolation using ximgproc::RICInterpolator, see @cite Hu2017. */
  31. };
  32. /** @brief This is used store and set up the parameters of the robust local optical flow (RLOF) algoritm.
  33. *
  34. * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014
  35. * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as
  36. * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019.
  37. * The implementation is derived from optflow::calcOpticalFlowPyrLK().
  38. * This RLOF implementation can be seen as an improved pyramidal iterative Lucas-Kanade and includes
  39. * a set of improving modules. The main improvements in respect to the pyramidal iterative Lucas-Kanade
  40. * are:
  41. * - A more robust redecending M-estimator framework (see @cite Senst2012) to improve the accuracy at
  42. * motion boundaries and appearing and disappearing pixels.
  43. * - an adaptive support region strategies to improve the accuracy at motion boundaries to reduce the
  44. * corona effect, i.e oversmoothing of the PLK at motion/object boundaries. The cross-based segementation
  45. * strategy (SR_CROSS) proposed in @cite Senst2014 uses a simple segmenation approach to obtain the optimal
  46. * shape of the support region.
  47. * - To deal with illumination changes (outdoor sequences and shadow) the intensity constancy assumption
  48. * based optical flow equation has been adopt with the Gennert and Negahdaripour illumination model
  49. * (see @cite Senst2016). This model can be switched on/off with the useIlluminationModel variable.
  50. * - By using a global motion prior initialization (see @cite Senst2016) of the iterative refinement
  51. * the accuracy could be significantly improved for large displacements. This initialization can be
  52. * switched on and of with useGlobalMotionPrior variable.
  53. *
  54. * The RLOF can be computed with the SparseOpticalFlow class or function interface to track a set of features
  55. * or with the DenseOpticalFlow class or function interface to compute dense optical flow.
  56. *
  57. * @see optflow::DenseRLOFOpticalFlow, optflow::calcOpticalFlowDenseRLOF(), optflow::SparseRLOFOpticalFlow, optflow::calcOpticalFlowSparseRLOF()
  58. */
  59. class CV_EXPORTS_W RLOFOpticalFlowParameter{
  60. public:
  61. RLOFOpticalFlowParameter()
  62. :solverType(ST_BILINEAR)
  63. ,supportRegionType(SR_CROSS)
  64. ,normSigma0(std::numeric_limits<float>::max())
  65. ,normSigma1(std::numeric_limits<float>::max())
  66. ,smallWinSize(9)
  67. ,largeWinSize(21)
  68. ,crossSegmentationThreshold(25)
  69. ,maxLevel(4)
  70. ,useInitialFlow(false)
  71. ,useIlluminationModel(true)
  72. ,useGlobalMotionPrior(true)
  73. ,maxIteration(30)
  74. ,minEigenValue(0.0001f)
  75. ,globalMotionRansacThreshold(10)
  76. {}
  77. SolverType solverType;
  78. /**< Variable specifies the iterative refinement strategy. Please consider citing @cite Senst2013 when
  79. * using ST_BILINEAR.
  80. */
  81. SupportRegionType supportRegionType;
  82. /**< Variable specifies the support region shape extraction or shrinking strategy.
  83. */
  84. float normSigma0;
  85. /**< &sigma parameter of the shrinked Hampel norm introduced in @cite Senst2012. If
  86. * &sigma = std::numeric_limist<float>::max() the least-square estimator will be used
  87. * instead of the M-estimator. Althoug M-estimator is more robust against outlier in the support
  88. * region the least-square can be fast in computation.
  89. */
  90. float normSigma1;
  91. /**< &sigma parameter of the shrinked Hampel norm introduced in @cite Senst2012. If
  92. * &sigma = std::numeric_limist<float>::max() the least-square estimator will be used
  93. * instead of the M-estimator. Althoug M-estimator is more robust against outlier in the support
  94. * region the least-square can be fast in computation.
  95. */
  96. int smallWinSize;
  97. /**< Minimal window size of the support region. This parameter is only used if supportRegionType is SR_CROSS.
  98. */
  99. int largeWinSize;
  100. /**< Maximal window size of the support region. If supportRegionType is SR_FIXED this gives the exact support
  101. * region size. The speed of the RLOF is related to the applied win sizes. The smaller the window size the lower is the runtime,
  102. * but the more sensitive to noise is the method.
  103. */
  104. int crossSegmentationThreshold;
  105. /**< Color similarity threshold used by cross-based segmentation following @cite Senst2014 .
  106. * (Only used if supportRegionType is SR_CROSS). With the cross-bassed segmentation
  107. * motion boundaries can be computed more accurately.
  108. */
  109. int maxLevel;
  110. /**< Maximal number of pyramid level used. The large this value is the more likely it is
  111. * to obtain accurate solutions for long-range motions. The runtime is linear related to
  112. * this parameter.
  113. */
  114. bool useInitialFlow;
  115. /**< Use next point list as initial values. A good intialization can imporve the algortihm
  116. * accuracy and reduce the runtime by a faster convergence of the iteration refinement.
  117. */
  118. bool useIlluminationModel;
  119. /**< Use the Gennert and Negahdaripour illumination model instead of the intensity brigthness
  120. * constraint. (proposed in @cite Senst2016 ) This model is defined as follow:
  121. * \f[ I(\mathbf{x},t) + m \cdot I(\mathbf{x},t) + c = I(\mathbf{x},t+1) \f]
  122. * and contains with m and c a multiplicative and additive term which makes the estimate
  123. * more robust against illumination changes. The computational complexity is increased by
  124. * enabling the illumination model.
  125. */
  126. bool useGlobalMotionPrior;
  127. /**< Use global motion prior initialisation has been introduced in @cite Senst2016 . It
  128. * allows to be more accurate for long-range motion. The computational complexity is
  129. * slightly increased by enabling the global motion prior initialisation.
  130. */
  131. int maxIteration;
  132. /**< Number of maximal iterations used for the iterative refinement. Lower values can
  133. * reduce the runtime but also the accuracy.
  134. */
  135. float minEigenValue;
  136. /**< Threshold for the minimal eigenvalue of the gradient matrix defines when to abort the
  137. * iterative refinement.
  138. */
  139. float globalMotionRansacThreshold;
  140. /**< To apply the global motion prior motion vectors will be computed on a regulary sampled which
  141. * are the basis for Homography estimation using RANSAC. The reprojection threshold is based on
  142. * n-th percentil (given by this value [0 ... 100]) of the motion vectors magnitude.
  143. * See @cite Senst2016 for more details.
  144. */
  145. //! @brief Enable M-estimator or disable and use least-square estimator.
  146. /** Enables M-estimator by setting sigma parameters to (3.2, 7.0). Disabling M-estimator can reduce
  147. * runtime, while enabling can improve the accuracy.
  148. * @param val If true M-estimator is used. If false least-square estimator is used.
  149. * @see setNormSigma0, setNormSigma1
  150. */
  151. CV_WRAP void setUseMEstimator(bool val);
  152. CV_WRAP void setSolverType(SolverType val);
  153. CV_WRAP SolverType getSolverType() const;
  154. CV_WRAP void setSupportRegionType(SupportRegionType val);
  155. CV_WRAP SupportRegionType getSupportRegionType() const;
  156. CV_WRAP void setNormSigma0(float val);
  157. CV_WRAP float getNormSigma0() const;
  158. CV_WRAP void setNormSigma1(float val);
  159. CV_WRAP float getNormSigma1() const;
  160. CV_WRAP void setSmallWinSize(int val);
  161. CV_WRAP int getSmallWinSize() const;
  162. CV_WRAP void setLargeWinSize(int val);
  163. CV_WRAP int getLargeWinSize() const;
  164. CV_WRAP void setCrossSegmentationThreshold(int val);
  165. CV_WRAP int getCrossSegmentationThreshold() const;
  166. CV_WRAP void setMaxLevel(int val);
  167. CV_WRAP int getMaxLevel() const;
  168. CV_WRAP void setUseInitialFlow(bool val);
  169. CV_WRAP bool getUseInitialFlow() const;
  170. CV_WRAP void setUseIlluminationModel(bool val);
  171. CV_WRAP bool getUseIlluminationModel() const;
  172. CV_WRAP void setUseGlobalMotionPrior(bool val);
  173. CV_WRAP bool getUseGlobalMotionPrior() const;
  174. CV_WRAP void setMaxIteration(int val);
  175. CV_WRAP int getMaxIteration() const;
  176. CV_WRAP void setMinEigenValue(float val);
  177. CV_WRAP float getMinEigenValue() const;
  178. CV_WRAP void setGlobalMotionRansacThreshold(float val);
  179. CV_WRAP float getGlobalMotionRansacThreshold() const;
  180. //! @brief Creates instance of optflow::RLOFOpticalFlowParameter
  181. CV_WRAP static Ptr<RLOFOpticalFlowParameter> create();
  182. };
  183. /** @brief Fast dense optical flow computation based on robust local optical flow (RLOF) algorithms and sparse-to-dense interpolation
  184. * scheme.
  185. *
  186. * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014
  187. * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as
  188. * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019.
  189. * The implementation is derived from optflow::calcOpticalFlowPyrLK().
  190. *
  191. * The sparse-to-dense interpolation scheme allows for fast computation of dense optical flow using RLOF (see @cite Geistert2016).
  192. * For this scheme the following steps are applied:
  193. * -# motion vector seeded at a regular sampled grid are computed. The sparsity of this grid can be configured with setGridStep
  194. * -# (optinally) errornous motion vectors are filter based on the forward backward confidence. The threshold can be configured
  195. * with setForwardBackward. The filter is only applied if the threshold >0 but than the runtime is doubled due to the estimation
  196. * of the backward flow.
  197. * -# Vector field interpolation is applied to the motion vector set to obtain a dense vector field.
  198. *
  199. * For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details.
  200. * Parameters have been described in @cite Senst2012 @cite Senst2013 @cite Senst2014 and @cite Senst2016.
  201. *
  202. * @note If the grid size is set to (1,1) and the forward backward threshold <= 0 than pixelwise dense optical flow field is
  203. * computed by RLOF without using interpolation.
  204. *
  205. * @note Note that in output, if no correspondences are found between \a I0 and \a I1, the \a flow is set to 0.
  206. * @see optflow::calcOpticalFlowDenseRLOF(), optflow::RLOFOpticalFlowParameter
  207. */
  208. class CV_EXPORTS_W DenseRLOFOpticalFlow : public DenseOpticalFlow
  209. {
  210. public:
  211. //! @brief Configuration of the RLOF alogrithm.
  212. /**
  213. @see optflow::RLOFOpticalFlowParameter, getRLOFOpticalFlowParameter
  214. */
  215. CV_WRAP virtual void setRLOFOpticalFlowParameter(Ptr<RLOFOpticalFlowParameter> val) = 0;
  216. /** @copybrief setRLOFOpticalFlowParameter
  217. @see optflow::RLOFOpticalFlowParameter, setRLOFOpticalFlowParameter
  218. */
  219. CV_WRAP virtual Ptr<RLOFOpticalFlowParameter> getRLOFOpticalFlowParameter() const = 0;
  220. //! @brief Threshold for the forward backward confidence check
  221. /**For each grid point \f$ \mathbf{x} \f$ a motion vector \f$ d_{I0,I1}(\mathbf{x}) \f$ is computed.
  222. * If the forward backward error \f[ EP_{FB} = || d_{I0,I1} + d_{I1,I0} || \f]
  223. * is larger than threshold given by this function then the motion vector will not be used by the following
  224. * vector field interpolation. \f$ d_{I1,I0} \f$ denotes the backward flow. Note, the forward backward test
  225. * will only be applied if the threshold > 0. This may results into a doubled runtime for the motion estimation.
  226. * @see getForwardBackward, setGridStep
  227. */
  228. CV_WRAP virtual void setForwardBackward(float val) = 0;
  229. /** @copybrief setForwardBackward
  230. @see setForwardBackward
  231. */
  232. CV_WRAP virtual float getForwardBackward() const = 0;
  233. //! @brief Size of the grid to spawn the motion vectors.
  234. /** For each grid point a motion vector is computed. Some motion vectors will be removed due to the forwatd backward
  235. * threshold (if set >0). The rest will be the base of the vector field interpolation.
  236. * @see getForwardBackward, setGridStep
  237. */
  238. CV_WRAP virtual Size getGridStep() const = 0;
  239. /** @copybrief getGridStep
  240. * @see getGridStep
  241. */
  242. CV_WRAP virtual void setGridStep(Size val) = 0;
  243. //! @brief Interpolation used to compute the dense optical flow.
  244. /** Two interpolation algorithms are supported
  245. * - **INTERP_GEO** applies the fast geodesic interpolation, see @cite Geistert2016.
  246. * - **INTERP_EPIC_RESIDUAL** applies the edge-preserving interpolation, see @cite Revaud2015,Geistert2016.
  247. * @see ximgproc::EdgeAwareInterpolator, getInterpolation
  248. */
  249. CV_WRAP virtual void setInterpolation(InterpolationType val) = 0;
  250. /** @copybrief setInterpolation
  251. * @see ximgproc::EdgeAwareInterpolator, setInterpolation
  252. */
  253. CV_WRAP virtual InterpolationType getInterpolation() const = 0;
  254. //! @brief see ximgproc::EdgeAwareInterpolator() K value.
  255. /** K is a number of nearest-neighbor matches considered, when fitting a locally affine
  256. * model. Usually it should be around 128. However, lower values would make the interpolation noticeably faster.
  257. * @see ximgproc::EdgeAwareInterpolator, setEPICK
  258. */
  259. CV_WRAP virtual int getEPICK() const = 0;
  260. /** @copybrief getEPICK
  261. * @see ximgproc::EdgeAwareInterpolator, getEPICK
  262. */
  263. CV_WRAP virtual void setEPICK(int val) = 0;
  264. //! @brief see ximgproc::EdgeAwareInterpolator() sigma value.
  265. /** Sigma is a parameter defining how fast the weights decrease in the locally-weighted affine
  266. * fitting. Higher values can help preserve fine details, lower values can help to get rid of noise in the
  267. * output flow.
  268. * @see ximgproc::EdgeAwareInterpolator, setEPICSigma
  269. */
  270. CV_WRAP virtual float getEPICSigma() const = 0;
  271. /** @copybrief getEPICSigma
  272. * @see ximgproc::EdgeAwareInterpolator, getEPICSigma
  273. */
  274. CV_WRAP virtual void setEPICSigma(float val) = 0;
  275. //! @brief see ximgproc::EdgeAwareInterpolator() lambda value.
  276. /** Lambda is a parameter defining the weight of the edge-aware term in geodesic distance,
  277. * should be in the range of 0 to 1000.
  278. * @see ximgproc::EdgeAwareInterpolator, setEPICSigma
  279. */
  280. CV_WRAP virtual float getEPICLambda() const = 0;
  281. /** @copybrief getEPICLambda
  282. * @see ximgproc::EdgeAwareInterpolator, getEPICLambda
  283. */
  284. CV_WRAP virtual void setEPICLambda(float val) = 0;
  285. //! @brief see ximgproc::EdgeAwareInterpolator().
  286. /** Sets the respective fastGlobalSmootherFilter() parameter.
  287. * @see ximgproc::EdgeAwareInterpolator, setFgsLambda
  288. */
  289. CV_WRAP virtual float getFgsLambda() const = 0;
  290. /** @copybrief getFgsLambda
  291. * @see ximgproc::EdgeAwareInterpolator, ximgproc::fastGlobalSmootherFilter, getFgsLambda
  292. */
  293. CV_WRAP virtual void setFgsLambda(float val) = 0;
  294. //! @brief see ximgproc::EdgeAwareInterpolator().
  295. /** Sets the respective fastGlobalSmootherFilter() parameter.
  296. * @see ximgproc::EdgeAwareInterpolator, ximgproc::fastGlobalSmootherFilter, setFgsSigma
  297. */
  298. CV_WRAP virtual float getFgsSigma() const = 0;
  299. /** @copybrief getFgsSigma
  300. * @see ximgproc::EdgeAwareInterpolator, ximgproc::fastGlobalSmootherFilter, getFgsSigma
  301. */
  302. CV_WRAP virtual void setFgsSigma(float val) = 0;
  303. //! @brief enables ximgproc::fastGlobalSmootherFilter
  304. /**
  305. * @see getUsePostProc
  306. */
  307. CV_WRAP virtual void setUsePostProc(bool val) = 0;
  308. /** @copybrief setUsePostProc
  309. * @see ximgproc::fastGlobalSmootherFilter, setUsePostProc
  310. */
  311. CV_WRAP virtual bool getUsePostProc() const = 0;
  312. //! @brief enables VariationalRefinement
  313. /**
  314. * @see getUseVariationalRefinement
  315. */
  316. CV_WRAP virtual void setUseVariationalRefinement(bool val) = 0;
  317. /** @copybrief setUseVariationalRefinement
  318. * @see ximgproc::fastGlobalSmootherFilter, setUsePostProc
  319. */
  320. CV_WRAP virtual bool getUseVariationalRefinement() const = 0;
  321. //! @brief Parameter to tune the approximate size of the superpixel used for oversegmentation.
  322. /**
  323. * @see cv::ximgproc::createSuperpixelSLIC, cv::ximgproc::RICInterpolator
  324. */
  325. CV_WRAP virtual void setRICSPSize(int val) = 0;
  326. /** @copybrief setRICSPSize
  327. * @see setRICSPSize
  328. */
  329. CV_WRAP virtual int getRICSPSize() const = 0;
  330. /** @brief Parameter to choose superpixel algorithm variant to use:
  331. * - cv::ximgproc::SLICType SLIC segments image using a desired region_size (value: 100)
  332. * - cv::ximgproc::SLICType SLICO will optimize using adaptive compactness factor (value: 101)
  333. * - cv::ximgproc::SLICType MSLIC will optimize using manifold methods resulting in more content-sensitive superpixels (value: 102).
  334. * @see cv::ximgproc::createSuperpixelSLIC, cv::ximgproc::RICInterpolator
  335. */
  336. CV_WRAP virtual void setRICSLICType(int val) = 0;
  337. /** @copybrief setRICSLICType
  338. * @see setRICSLICType
  339. */
  340. CV_WRAP virtual int getRICSLICType() const = 0;
  341. //! @brief Creates instance of optflow::DenseRLOFOpticalFlow
  342. /**
  343. * @param rlofParam see optflow::RLOFOpticalFlowParameter
  344. * @param forwardBackwardThreshold see setForwardBackward
  345. * @param gridStep see setGridStep
  346. * @param interp_type see setInterpolation
  347. * @param epicK see setEPICK
  348. * @param epicSigma see setEPICSigma
  349. * @param epicLambda see setEPICLambda
  350. * @param ricSPSize see setRICSPSize
  351. * @param ricSLICType see setRICSLICType
  352. * @param use_post_proc see setUsePostProc
  353. * @param fgsLambda see setFgsLambda
  354. * @param fgsSigma see setFgsSigma
  355. * @param use_variational_refinement see setUseVariationalRefinement
  356. */
  357. CV_WRAP static Ptr<DenseRLOFOpticalFlow> create(
  358. Ptr<RLOFOpticalFlowParameter> rlofParam = Ptr<RLOFOpticalFlowParameter>(),
  359. float forwardBackwardThreshold = 1.f,
  360. Size gridStep = Size(6, 6),
  361. InterpolationType interp_type = InterpolationType::INTERP_EPIC,
  362. int epicK = 128,
  363. float epicSigma = 0.05f,
  364. float epicLambda = 999.0f,
  365. int ricSPSize = 15,
  366. int ricSLICType = 100,
  367. bool use_post_proc = true,
  368. float fgsLambda = 500.0f,
  369. float fgsSigma = 1.5f,
  370. bool use_variational_refinement = false);
  371. };
  372. /** @brief Class used for calculation sparse optical flow and feature tracking with robust local optical flow (RLOF) algorithms.
  373. *
  374. * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014
  375. * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as
  376. * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019.
  377. * The implementation is derived from optflow::calcOpticalFlowPyrLK().
  378. *
  379. * For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details.
  380. * Parameters have been described in @cite Senst2012, @cite Senst2013, @cite Senst2014 and @cite Senst2016.
  381. *
  382. * @note SIMD parallelization is only available when compiling with SSE4.1.
  383. * @see optflow::calcOpticalFlowSparseRLOF(), optflow::RLOFOpticalFlowParameter
  384. */
  385. class CV_EXPORTS_W SparseRLOFOpticalFlow : public SparseOpticalFlow
  386. {
  387. public:
  388. /** @copydoc DenseRLOFOpticalFlow::setRLOFOpticalFlowParameter
  389. */
  390. CV_WRAP virtual void setRLOFOpticalFlowParameter(Ptr<RLOFOpticalFlowParameter> val) = 0;
  391. /** @copybrief setRLOFOpticalFlowParameter
  392. * @see setRLOFOpticalFlowParameter
  393. */
  394. CV_WRAP virtual Ptr<RLOFOpticalFlowParameter> getRLOFOpticalFlowParameter() const = 0;
  395. //! @brief Threshold for the forward backward confidence check
  396. /** For each feature point a motion vector \f$ d_{I0,I1}(\mathbf{x}) \f$ is computed.
  397. * If the forward backward error \f[ EP_{FB} = || d_{I0,I1} + d_{I1,I0} || \f]
  398. * is larger than threshold given by this function then the status will not be used by the following
  399. * vector field interpolation. \f$ d_{I1,I0} \f$ denotes the backward flow. Note, the forward backward test
  400. * will only be applied if the threshold > 0. This may results into a doubled runtime for the motion estimation.
  401. * @see setForwardBackward
  402. */
  403. CV_WRAP virtual void setForwardBackward(float val) = 0;
  404. /** @copybrief setForwardBackward
  405. * @see setForwardBackward
  406. */
  407. CV_WRAP virtual float getForwardBackward() const = 0;
  408. //! @brief Creates instance of SparseRLOFOpticalFlow
  409. /**
  410. * @param rlofParam see setRLOFOpticalFlowParameter
  411. * @param forwardBackwardThreshold see setForwardBackward
  412. */
  413. CV_WRAP static Ptr<SparseRLOFOpticalFlow> create(
  414. Ptr<RLOFOpticalFlowParameter> rlofParam = Ptr<RLOFOpticalFlowParameter>(),
  415. float forwardBackwardThreshold = 1.f);
  416. };
  417. /** @brief Fast dense optical flow computation based on robust local optical flow (RLOF) algorithms and sparse-to-dense interpolation scheme.
  418. *
  419. * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014
  420. * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as
  421. * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019.
  422. * The implementation is derived from optflow::calcOpticalFlowPyrLK().
  423. *
  424. * The sparse-to-dense interpolation scheme allows for fast computation of dense optical flow using RLOF (see @cite Geistert2016).
  425. * For this scheme the following steps are applied:
  426. * -# motion vector seeded at a regular sampled grid are computed. The sparsity of this grid can be configured with setGridStep
  427. * -# (optinally) errornous motion vectors are filter based on the forward backward confidence. The threshold can be configured
  428. * with setForwardBackward. The filter is only applied if the threshold >0 but than the runtime is doubled due to the estimation
  429. * of the backward flow.
  430. * -# Vector field interpolation is applied to the motion vector set to obtain a dense vector field.
  431. *
  432. * @param I0 first 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType
  433. * = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image.
  434. * @param I1 second 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType
  435. * = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image.
  436. * @param flow computed flow image that has the same size as I0 and type CV_32FC2.
  437. * @param rlofParam see optflow::RLOFOpticalFlowParameter
  438. * @param forwardBackwardThreshold Threshold for the forward backward confidence check.
  439. * For each grid point \f$ \mathbf{x} \f$ a motion vector \f$ d_{I0,I1}(\mathbf{x}) \f$ is computed.
  440. * If the forward backward error \f[ EP_{FB} = || d_{I0,I1} + d_{I1,I0} || \f]
  441. * is larger than threshold given by this function then the motion vector will not be used by the following
  442. * vector field interpolation. \f$ d_{I1,I0} \f$ denotes the backward flow. Note, the forward backward test
  443. * will only be applied if the threshold > 0. This may results into a doubled runtime for the motion estimation.
  444. * @param gridStep Size of the grid to spawn the motion vectors. For each grid point a motion vector is computed.
  445. * Some motion vectors will be removed due to the forwatd backward threshold (if set >0). The rest will be the
  446. * base of the vector field interpolation.
  447. * @param interp_type interpolation method used to compute the dense optical flow. Two interpolation algorithms are
  448. * supported:
  449. * - **INTERP_GEO** applies the fast geodesic interpolation, see @cite Geistert2016.
  450. * - **INTERP_EPIC_RESIDUAL** applies the edge-preserving interpolation, see @cite Revaud2015,Geistert2016.
  451. * @param epicK see ximgproc::EdgeAwareInterpolator sets the respective parameter.
  452. * @param epicSigma see ximgproc::EdgeAwareInterpolator sets the respective parameter.
  453. * @param epicLambda see ximgproc::EdgeAwareInterpolator sets the respective parameter.
  454. * @param ricSPSize see ximgproc::RICInterpolator sets the respective parameter.
  455. * @param ricSLICType see ximgproc::RICInterpolator sets the respective parameter.
  456. * @param use_post_proc enables ximgproc::fastGlobalSmootherFilter() parameter.
  457. * @param fgsLambda sets the respective ximgproc::fastGlobalSmootherFilter() parameter.
  458. * @param fgsSigma sets the respective ximgproc::fastGlobalSmootherFilter() parameter.
  459. * @param use_variational_refinement enables VariationalRefinement
  460. *
  461. * Parameters have been described in @cite Senst2012, @cite Senst2013, @cite Senst2014, @cite Senst2016.
  462. * For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details.
  463. * @note If the grid size is set to (1,1) and the forward backward threshold <= 0 that the dense optical flow field is purely
  464. * computed with the RLOF.
  465. *
  466. * @note SIMD parallelization is only available when compiling with SSE4.1.
  467. * @note Note that in output, if no correspondences are found between \a I0 and \a I1, the \a flow is set to 0.
  468. *
  469. * @sa optflow::DenseRLOFOpticalFlow, optflow::RLOFOpticalFlowParameter
  470. */
  471. CV_EXPORTS_W void calcOpticalFlowDenseRLOF(InputArray I0, InputArray I1, InputOutputArray flow,
  472. Ptr<RLOFOpticalFlowParameter> rlofParam = Ptr<RLOFOpticalFlowParameter>(),
  473. float forwardBackwardThreshold = 0, Size gridStep = Size(6, 6),
  474. InterpolationType interp_type = InterpolationType::INTERP_EPIC,
  475. int epicK = 128, float epicSigma = 0.05f, float epicLambda = 100.f,
  476. int ricSPSize = 15, int ricSLICType = 100,
  477. bool use_post_proc = true, float fgsLambda = 500.0f, float fgsSigma = 1.5f,
  478. bool use_variational_refinement = false);
  479. /** @brief Calculates fast optical flow for a sparse feature set using the robust local optical flow (RLOF) similar
  480. * to optflow::calcOpticalFlowPyrLK().
  481. *
  482. * The RLOF is a fast local optical flow approach described in @cite Senst2012 @cite Senst2013 @cite Senst2014
  483. * and @cite Senst2016 similar to the pyramidal iterative Lucas-Kanade method as
  484. * proposed by @cite Bouguet00. More details and experiments can be found in the following thesis @cite Senst2019.
  485. * The implementation is derived from optflow::calcOpticalFlowPyrLK().
  486. *
  487. * @param prevImg first 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType
  488. * = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image.
  489. * @param nextImg second 8-bit input image. If The cross-based RLOF is used (by selecting optflow::RLOFOpticalFlowParameter::supportRegionType
  490. * = SupportRegionType::SR_CROSS) image has to be a 8-bit 3 channel image.
  491. * @param prevPts vector of 2D points for which the flow needs to be found; point coordinates must be single-precision
  492. * floating-point numbers.
  493. * @param nextPts output vector of 2D points (with single-precision floating-point coordinates) containing the calculated
  494. * new positions of input features in the second image; when optflow::RLOFOpticalFlowParameter::useInitialFlow variable is true the vector must
  495. * have the same size as in the input and contain the initialization point correspondences.
  496. * @param status output status vector (of unsigned chars); each element of the vector is set to 1 if the flow for the
  497. * corresponding features has passed the forward backward check.
  498. * @param err output vector of errors; each element of the vector is set to the forward backward error for the corresponding feature.
  499. * @param rlofParam see optflow::RLOFOpticalFlowParameter
  500. * @param forwardBackwardThreshold Threshold for the forward backward confidence check. If forewardBackwardThreshold <=0 the forward
  501. *
  502. * @note SIMD parallelization is only available when compiling with SSE4.1.
  503. *
  504. * Parameters have been described in @cite Senst2012, @cite Senst2013, @cite Senst2014 and @cite Senst2016.
  505. * For the RLOF configuration see optflow::RLOFOpticalFlowParameter for further details.
  506. */
  507. CV_EXPORTS_W void calcOpticalFlowSparseRLOF(InputArray prevImg, InputArray nextImg,
  508. InputArray prevPts, InputOutputArray nextPts,
  509. OutputArray status, OutputArray err,
  510. Ptr<RLOFOpticalFlowParameter> rlofParam = Ptr<RLOFOpticalFlowParameter>(),
  511. float forwardBackwardThreshold = 0);
  512. //! Additional interface to the Dense RLOF algorithm - optflow::calcOpticalFlowDenseRLOF()
  513. CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_DenseRLOF();
  514. //! Additional interface to the Sparse RLOF algorithm - optflow::calcOpticalFlowSparseRLOF()
  515. CV_EXPORTS_W Ptr<SparseOpticalFlow> createOptFlow_SparseRLOF();
  516. //! @}
  517. } // namespace
  518. } // namespace
  519. #endif