1 Global Motion Estimation
2 ========================
6 The video stabilization module contains a set of functions and classes for global motion estimation between point clouds or between images. In the last case features are extracted and matched internally. For the sake of convenience the motion estimation functions are wrapped into classes. Both the functions and the classes are available.
11 .. ocv:class:: videostab::MotionModel
13 Describes motion model between two point clouds.
20 MM_TRANSLATION_AND_SCALE = 1,
30 videostab::RansacParams
31 -----------------------
33 .. ocv:class:: videostab::RansacParams
35 Describes RANSAC method parameters.
39 struct CV_EXPORTS RansacParams
41 int size; // subset size
42 float thresh; // max error to classify as inlier
43 float eps; // max outliers ratio
44 float prob; // probability of success
46 RansacParams() : size(0), thresh(0), eps(0), prob(0) {}
47 RansacParams(int size, float thresh, float eps, float prob);
51 static RansacParams default2dMotion(MotionModel model);
55 videostab::RansacParams::RansacParams
56 -------------------------------------
58 .. ocv:function:: RansacParams::RansacParams()
60 :return: RANSAC method empty parameters object.
63 videostab::RansacParams::RansacParams
64 -------------------------------------
66 .. ocv:function:: RansacParams::RansacParams(int size, float thresh, float eps, float prob)
68 :param size: Subset size.
70 :param thresh: Maximum re-projection error value to classify as inlier.
72 :param eps: Maximum ratio of incorrect correspondences.
74 :param prob: Required success probability.
76 :return: RANSAC method parameters object.
79 videostab::RansacParams::niters
80 -------------------------------
82 .. ocv:function:: int RansacParams::niters() const
84 :return: Number of iterations that'll be performed by RANSAC method.
87 videostab::RansacParams::default2dMotion
88 ----------------------------------------
90 .. ocv:function:: static RansacParams RansacParams::default2dMotion(MotionModel model)
92 :param model: Motion model. See :ocv:class:`videostab::MotionModel`.
94 :return: Default RANSAC method parameters for the given motion model.
97 videostab::estimateGlobalMotionLeastSquares
98 -------------------------------------------
100 Estimates best global motion between two 2D point clouds in the least-squares sense.
102 .. note:: Works in-place and changes input point arrays.
104 .. ocv:function:: Mat estimateGlobalMotionLeastSquares(InputOutputArray points0, InputOutputArray points1, int model = MM_AFFINE, float *rmse = 0)
106 :param points0: Source set of 2D points (``32F``).
108 :param points1: Destination set of 2D points (``32F``).
110 :param model: Motion model (up to ``MM_AFFINE``).
112 :param rmse: Final root-mean-square error.
114 :return: 3x3 2D transformation matrix (``32F``).
117 videostab::estimateGlobalMotionRansac
118 -------------------------------------
120 Estimates best global motion between two 2D point clouds robustly (using RANSAC method).
122 .. ocv:function:: Mat estimateGlobalMotionRansac(InputArray points0, InputArray points1, int model = MM_AFFINE, const RansacParams ¶ms = RansacParams::default2dMotion(MM_AFFINE), float *rmse = 0, int *ninliers = 0)
124 :param points0: Source set of 2D points (``32F``).
126 :param points1: Destination set of 2D points (``32F``).
128 :param model: Motion model. See :ocv:class:`videostab::MotionModel`.
130 :param params: RANSAC method parameters. See :ocv:class:`videostab::RansacParams`.
132 :param rmse: Final root-mean-square error.
134 :param ninliers: Final number of inliers.
140 Computes motion between two frames assuming that all the intermediate motions are known.
142 .. ocv:function:: Mat getMotion(int from, int to, const std::vector<Mat> &motions)
144 :param from: Source frame index.
146 :param to: Destination frame index.
148 :param motions: Pair-wise motions. ``motions[i]`` denotes motion from the frame ``i`` to the frame ``i+1``
150 :return: Motion from the frame ``from`` to the frame ``to``.
153 videostab::MotionEstimatorBase
154 ------------------------------
156 .. ocv:class:: videostab::MotionEstimatorBase
158 Base class for all global motion estimation methods.
162 class CV_EXPORTS MotionEstimatorBase
165 virtual ~MotionEstimatorBase();
167 virtual void setMotionModel(MotionModel val);
168 virtual MotionModel motionModel() const;
170 virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0) = 0;
174 videostab::MotionEstimatorBase::setMotionModel
175 ----------------------------------------------
179 .. ocv:function:: void MotionEstimatorBase::setMotionModel(MotionModel val)
181 :param val: Motion model. See :ocv:class:`videostab::MotionModel`.
185 videostab::MotionEstimatorBase::motionModel
186 ----------------------------------------------
188 .. ocv:function:: MotionModel MotionEstimatorBase::motionModel() const
190 :return: Motion model. See :ocv:class:`videostab::MotionModel`.
193 videostab::MotionEstimatorBase::estimate
194 ----------------------------------------
196 Estimates global motion between two 2D point clouds.
198 .. ocv:function:: Mat MotionEstimatorBase::estimate(InputArray points0, InputArray points1, bool *ok = 0)
200 :param points0: Source set of 2D points (``32F``).
202 :param points1: Destination set of 2D points (``32F``).
204 :param ok: Indicates whether motion was estimated successfully.
206 :return: 3x3 2D transformation matrix (``32F``).
209 videostab::MotionEstimatorRansacL2
210 ----------------------------------
212 .. ocv:class:: videostab::MotionEstimatorRansacL2
214 Describes a robust RANSAC-based global 2D motion estimation method which minimizes L2 error.
218 class CV_EXPORTS MotionEstimatorRansacL2 : public MotionEstimatorBase
221 MotionEstimatorRansacL2(MotionModel model = MM_AFFINE);
223 void setRansacParams(const RansacParams &val);
224 RansacParams ransacParams() const;
226 void setMinInlierRatio(float val);
227 float minInlierRatio() const;
229 virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
233 videostab::MotionEstimatorL1
234 ----------------------------
236 .. ocv:class:: videostab::MotionEstimatorL1
238 Describes a global 2D motion estimation method which minimizes L1 error.
240 .. note:: To be able to use this method you must build OpenCV with CLP library support.
244 class CV_EXPORTS MotionEstimatorL1 : public MotionEstimatorBase
247 MotionEstimatorL1(MotionModel model = MM_AFFINE);
249 virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
253 videostab::ImageMotionEstimatorBase
254 -----------------------------------
256 .. ocv:class:: videostab::ImageMotionEstimatorBase
258 Base class for global 2D motion estimation methods which take frames as input.
262 class CV_EXPORTS ImageMotionEstimatorBase
265 virtual ~ImageMotionEstimatorBase();
267 virtual void setMotionModel(MotionModel val);
268 virtual MotionModel motionModel() const;
270 virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) = 0;
274 videostab::KeypointBasedMotionEstimator
275 ---------------------------------------
277 .. ocv:class:: videostab::KeypointBasedMotionEstimator
279 Describes a global 2D motion estimation method which uses keypoints detection and optical flow for matching.
283 class CV_EXPORTS KeypointBasedMotionEstimator : public ImageMotionEstimatorBase
286 KeypointBasedMotionEstimator(Ptr<MotionEstimatorBase> estimator);
288 virtual void setMotionModel(MotionModel val);
289 virtual MotionModel motionModel() const;
291 void setDetector(Ptr<FeatureDetector> val);
292 Ptr<FeatureDetector> detector() const;
294 void setOpticalFlowEstimator(Ptr<ISparseOptFlowEstimator> val);
295 Ptr<ISparseOptFlowEstimator> opticalFlowEstimator() const;
297 void setOutlierRejector(Ptr<IOutlierRejector> val);
298 Ptr<IOutlierRejector> outlierRejector() const;
300 virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);