Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__
00044 #define __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__
00045
00046 #include <vector>
00047 #include "opencv2/core/core.hpp"
00048 #include "opencv2/features2d/features2d.hpp"
00049 #include "opencv2/videostab/optical_flow.hpp"
00050
00051 namespace cv
00052 {
00053 namespace videostab
00054 {
00055
00056 enum MotionModel
00057 {
00058 TRANSLATION = 0,
00059 TRANSLATION_AND_SCALE = 1,
00060 LINEAR_SIMILARITY = 2,
00061 AFFINE = 3
00062 };
00063
00064 CV_EXPORTS Mat estimateGlobalMotionLeastSquares(
00065 const std::vector<Point2f> &points0, const std::vector<Point2f> &points1,
00066 int model = AFFINE, float *rmse = 0);
00067
00068 struct CV_EXPORTS RansacParams
00069 {
00070 int size;
00071 float thresh;
00072 float eps;
00073 float prob;
00074
00075 RansacParams(int _size, float _thresh, float _eps, float _prob)
00076 : size(_size), thresh(_thresh), eps(_eps), prob(_prob) {}
00077
00078 static RansacParams translationMotionStd() { return RansacParams(2, 0.5f, 0.5f, 0.99f); }
00079 static RansacParams translationAndScale2dMotionStd() { return RansacParams(3, 0.5f, 0.5f, 0.99f); }
00080 static RansacParams linearSimilarityMotionStd() { return RansacParams(4, 0.5f, 0.5f, 0.99f); }
00081 static RansacParams affine2dMotionStd() { return RansacParams(6, 0.5f, 0.5f, 0.99f); }
00082 };
00083
00084 CV_EXPORTS Mat estimateGlobalMotionRobust(
00085 const std::vector<Point2f> &points0, const std::vector<Point2f> &points1,
00086 int model = AFFINE, const RansacParams ¶ms = RansacParams::affine2dMotionStd(),
00087 float *rmse = 0, int *ninliers = 0);
00088
00089 class CV_EXPORTS IGlobalMotionEstimator
00090 {
00091 public:
00092 virtual ~IGlobalMotionEstimator() {}
00093 virtual Mat estimate(const Mat &frame0, const Mat &frame1) = 0;
00094 };
00095
00096 class CV_EXPORTS PyrLkRobustMotionEstimator : public IGlobalMotionEstimator
00097 {
00098 public:
00099 PyrLkRobustMotionEstimator();
00100
00101 void setDetector(Ptr<FeatureDetector> val) { detector_ = val; }
00102 Ptr<FeatureDetector> detector() const { return detector_; }
00103
00104 void setOptFlowEstimator(Ptr<ISparseOptFlowEstimator> val) { optFlowEstimator_ = val; }
00105 Ptr<ISparseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
00106
00107 void setMotionModel(MotionModel val) { motionModel_ = val; }
00108 MotionModel motionModel() const { return motionModel_; }
00109
00110 void setRansacParams(const RansacParams &val) { ransacParams_ = val; }
00111 RansacParams ransacParams() const { return ransacParams_; }
00112
00113 void setMaxRmse(float val) { maxRmse_ = val; }
00114 float maxRmse() const { return maxRmse_; }
00115
00116 void setMinInlierRatio(float val) { minInlierRatio_ = val; }
00117 float minInlierRatio() const { return minInlierRatio_; }
00118
00119 virtual Mat estimate(const Mat &frame0, const Mat &frame1);
00120
00121 private:
00122 Ptr<FeatureDetector> detector_;
00123 Ptr<ISparseOptFlowEstimator> optFlowEstimator_;
00124 MotionModel motionModel_;
00125 RansacParams ransacParams_;
00126 std::vector<uchar> status_;
00127 std::vector<KeyPoint> keypointsPrev_;
00128 std::vector<Point2f> pointsPrev_, points_;
00129 std::vector<Point2f> pointsPrevGood_, pointsGood_;
00130 float maxRmse_;
00131 float minInlierRatio_;
00132 };
00133
00134 CV_EXPORTS Mat getMotion(int from, int to, const Mat *motions, int size);
00135
00136 CV_EXPORTS Mat getMotion(int from, int to, const std::vector<Mat> &motions);
00137
00138 }
00139 }
00140
00141 #endif