global_motion.rst 8.52 KB

Global Motion Estimation

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

Describes motion model between two point clouds.

videostab::RansacParams

Describes RANSAC method parameters.

struct 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

videostab::RansacParams::RansacParams

videostab::RansacParams::niters

videostab::RansacParams::default2dMotion

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.

videostab::estimateGlobalMotionRansac

Estimates best global motion between two 2D point clouds robustly (using RANSAC method).

videostab::getMotion

Computes motion between two frames assuming that all the intermediate motions are known.

videostab::MotionEstimatorBase

Base class for all global motion estimation methods.

class 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.

videostab::MotionEstimatorBase::motionModel

videostab::MotionEstimatorBase::estimate

Estimates global motion between two 2D point clouds.

videostab::MotionEstimatorRansacL2

Describes a robust RANSAC-based global 2D motion estimation method which minimizes L2 error.

class 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

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 MotionEstimatorL1 : public MotionEstimatorBase
{
public:
    MotionEstimatorL1(MotionModel model = MM_AFFINE);

    virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
};

videostab::ImageMotionEstimatorBase

Base class for global 2D motion estimation methods which take frames as input.

class 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

Describes a global 2D motion estimation method which uses keypoints detection and optical flow for matching.

class 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);
};