2012-10-05 19:30:58 +02:00
Global Motion Estimation
========================
.. highlight :: cpp
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.
videostab::MotionModel
----------------------
2012-10-17 19:42:09 +02:00
Describes motion model between two point clouds.
2012-10-05 19:30:58 +02:00
::
enum MotionModel
{
MM_TRANSLATION = 0,
MM_TRANSLATION_AND_SCALE = 1,
MM_ROTATION = 2,
MM_RIGID = 3,
MM_SIMILARITY = 4,
MM_AFFINE = 5,
MM_HOMOGRAPHY = 6,
MM_UNKNOWN = 7
};
videostab::RansacParams
-----------------------
2012-10-18 10:16:04 +02:00
.. ocv:struct :: videostab::RansacParams
2012-10-05 19:30:58 +02:00
Describes RANSAC method parameters.
::
struct CV_EXPORTS RansacParams
{
int size; // subset size
float thresh; // max error to classify as inlier
float eps; // max outliers ratio
float prob; // probability of success
RansacParams() : size(0), thresh(0), eps(0), prob(0) {}
RansacParams(int size, float thresh, float eps, float prob);
int niters() const;
static RansacParams default2dMotion(MotionModel model);
};
videostab::RansacParams::RansacParams
-------------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:function :: videostab::RansacParams::RansacParams()
2012-10-05 19:30:58 +02:00
:return: RANSAC method empty parameters object.
videostab::RansacParams::RansacParams
-------------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:function :: videostab::RansacParams::RansacParams(int size, float thresh, float eps, float prob)
2012-10-05 19:30:58 +02:00
:param size: Subset size.
:param thresh: Maximum re-projection error value to classify as inlier.
:param eps: Maximum ratio of incorrect correspondences.
:param prob: Required success probability.
:return: RANSAC method parameters object.
videostab::RansacParams::niters
-------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:function :: int videostab::RansacParams::niters() const
2012-10-05 19:30:58 +02:00
:return: Number of iterations that'll be performed by RANSAC method.
videostab::RansacParams::default2dMotion
----------------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:function :: static RansacParams videostab::RansacParams::default2dMotion(MotionModel model)
2012-10-05 19:30:58 +02:00
:param model: Motion model. See :ocv:class:`videostab::MotionModel`.
:return: Default RANSAC method parameters for the given motion model.
videostab::estimateGlobalMotionLeastSquares
-------------------------------------------
Estimates best global motion between two 2D point clouds in the least-squares sense.
.. note :: Works in-place and changes input point arrays.
2012-10-18 10:16:04 +02:00
.. ocv:function :: Mat videostab::estimateGlobalMotionLeastSquares(InputOutputArray points0, InputOutputArray points1, int model = MM_AFFINE, float *rmse = 0)
2012-10-05 19:30:58 +02:00
:param points0: Source set of 2D points (``32F``).
:param points1: Destination set of 2D points (``32F``).
:param model: Motion model (up to ``MM_AFFINE``).
:param rmse: Final root-mean-square error.
:return: 3x3 2D transformation matrix (``32F``).
videostab::estimateGlobalMotionRansac
-------------------------------------
Estimates best global motion between two 2D point clouds robustly (using RANSAC method).
2012-10-18 10:16:04 +02:00
.. ocv:function :: Mat videostab::estimateGlobalMotionRansac(InputArray points0, InputArray points1, int model = MM_AFFINE, const RansacParams ¶ms = RansacParams::default2dMotion(MM_AFFINE), float *rmse = 0, int * ninliers = 0)
2012-10-05 19:30:58 +02:00
:param points0: Source set of 2D points (``32F``).
:param points1: Destination set of 2D points (``32F``).
:param model: Motion model. See :ocv:class:`videostab::MotionModel`.
:param params: RANSAC method parameters. See :ocv:class:`videostab::RansacParams`.
:param rmse: Final root-mean-square error.
:param ninliers: Final number of inliers.
videostab::getMotion
--------------------
Computes motion between two frames assuming that all the intermediate motions are known.
2012-10-18 10:16:04 +02:00
.. ocv:function :: Mat videostab::getMotion(int from, int to, const std::vector<Mat> &motions)
2012-10-05 19:30:58 +02:00
:param from: Source frame index.
:param to: Destination frame index.
:param motions: Pair-wise motions. ``motions[i]`` denotes motion from the frame ``i`` to the frame ``i+1``
:return: Motion from the frame ``from`` to the frame ``to``.
videostab::MotionEstimatorBase
------------------------------
.. ocv:class :: videostab::MotionEstimatorBase
Base class for all global motion estimation methods.
::
class CV_EXPORTS MotionEstimatorBase
{
public:
virtual ~MotionEstimatorBase();
virtual void setMotionModel(MotionModel val);
virtual MotionModel motionModel() const;
virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0) = 0;
};
videostab::MotionEstimatorBase::setMotionModel
----------------------------------------------
Sets motion model.
2012-10-18 10:16:04 +02:00
.. ocv:function :: void videostab::MotionEstimatorBase::setMotionModel(MotionModel val)
2012-10-05 19:30:58 +02:00
:param val: Motion model. See :ocv:class:`videostab::MotionModel`.
videostab::MotionEstimatorBase::motionModel
----------------------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:function :: MotionModel videostab::MotionEstimatorBase::motionModel() const
2012-10-05 19:30:58 +02:00
2012-10-17 19:42:09 +02:00
:return: Motion model. See :ocv:class:`videostab::MotionModel`.
2012-10-05 19:30:58 +02:00
videostab::MotionEstimatorBase::estimate
----------------------------------------
Estimates global motion between two 2D point clouds.
2012-10-18 10:16:04 +02:00
.. ocv:function :: Mat videostab::MotionEstimatorBase::estimate(InputArray points0, InputArray points1, bool *ok = 0)
2012-10-05 19:30:58 +02:00
:param points0: Source set of 2D points (``32F``).
:param points1: Destination set of 2D points (``32F``).
:param ok: Indicates whether motion was estimated successfully.
:return: 3x3 2D transformation matrix (``32F``).
videostab::MotionEstimatorRansacL2
----------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:class :: videostab::MotionEstimatorRansacL2 : public videostab::MotionEstimatorBase
2012-10-05 19:30:58 +02:00
Describes a robust RANSAC-based global 2D motion estimation method which minimizes L2 error.
::
class CV_EXPORTS MotionEstimatorRansacL2 : public MotionEstimatorBase
{
public:
MotionEstimatorRansacL2(MotionModel model = MM_AFFINE);
void setRansacParams(const RansacParams &val);
RansacParams ransacParams() const;
void setMinInlierRatio(float val);
float minInlierRatio() const;
virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
};
videostab::MotionEstimatorL1
----------------------------
2012-10-18 10:16:04 +02:00
.. ocv:class :: videostab::MotionEstimatorL1 : public videostab::MotionEstimatorBase
2012-10-05 19:30:58 +02:00
Describes a global 2D motion estimation method which minimizes L1 error.
.. note :: To be able to use this method you must build OpenCV with CLP library support.
::
class CV_EXPORTS MotionEstimatorL1 : public MotionEstimatorBase
{
public:
MotionEstimatorL1(MotionModel model = MM_AFFINE);
virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
};
videostab::ImageMotionEstimatorBase
-----------------------------------
.. ocv:class :: videostab::ImageMotionEstimatorBase
Base class for global 2D motion estimation methods which take frames as input.
::
class CV_EXPORTS ImageMotionEstimatorBase
{
public:
virtual ~ImageMotionEstimatorBase();
virtual void setMotionModel(MotionModel val);
virtual MotionModel motionModel() const;
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) = 0;
};
videostab::KeypointBasedMotionEstimator
---------------------------------------
2012-10-18 10:16:04 +02:00
.. ocv:class :: videostab::KeypointBasedMotionEstimator : public videostab::ImageMotionEstimatorBase
2012-10-05 19:30:58 +02:00
Describes a global 2D motion estimation method which uses keypoints detection and optical flow for matching.
::
class CV_EXPORTS KeypointBasedMotionEstimator : public ImageMotionEstimatorBase
{
public:
KeypointBasedMotionEstimator(Ptr<MotionEstimatorBase> estimator);
virtual void setMotionModel(MotionModel val);
virtual MotionModel motionModel() const;
void setDetector(Ptr<FeatureDetector> val);
Ptr<FeatureDetector> detector() const;
void setOpticalFlowEstimator(Ptr<ISparseOptFlowEstimator> val);
Ptr<ISparseOptFlowEstimator> opticalFlowEstimator() const;
void setOutlierRejector(Ptr<IOutlierRejector> val);
Ptr<IOutlierRejector> outlierRejector() const;
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
};