global_motion.hpp
Go to the documentation of this file.
1 /*M///////////////////////////////////////////////////////////////////////////////////////
2 //
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4 //
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
8 //
9 //
10 // License Agreement
11 // For Open Source Computer Vision Library
12 //
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14 // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
15 // Third party copyrights are property of their respective owners.
16 //
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
19 //
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
22 //
23 // * Redistribution's in binary form must reproduce the above copyright notice,
24 // this list of conditions and the following disclaimer in the documentation
25 // and/or other materials provided with the distribution.
26 //
27 // * The name of the copyright holders may not be used to endorse or promote products
28 // derived from this software without specific prior written permission.
29 //
30 // This software is provided by the copyright holders and contributors "as is" and
31 // any express or implied warranties, including, but not limited to, the implied
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.
33 // In no event shall the Intel Corporation or contributors be liable for any direct,
34 // indirect, incidental, special, exemplary, or consequential damages
35 // (including, but not limited to, procurement of substitute goods or services;
36 // loss of use, data, or profits; or business interruption) however caused
37 // and on any theory of liability, whether in contract, strict liability,
38 // or tort (including negligence or otherwise) arising in any way out of
39 // the use of this software, even if advised of the possibility of such damage.
40 //
41 //M*/
42 
43 #ifndef __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__
44 #define __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__
45 
46 #include <vector>
47 #include "opencv2/core/core.hpp"
50 
51 namespace cv
52 {
53 namespace videostab
54 {
55 
57 {
61  AFFINE = 3
62 };
63 
65  const std::vector<Point2f> &points0, const std::vector<Point2f> &points1,
66  int model = AFFINE, float *rmse = 0);
67 
68 struct CV_EXPORTS RansacParams
69 {
70  int size; // subset size
71  float thresh; // max error to classify as inlier
72  float eps; // max outliers ratio
73  float prob; // probability of success
74 
75  RansacParams(int _size, float _thresh, float _eps, float _prob)
76  : size(_size), thresh(_thresh), eps(_eps), prob(_prob) {}
77 
78  static RansacParams translationMotionStd() { return RansacParams(2, 0.5f, 0.5f, 0.99f); }
79  static RansacParams translationAndScale2dMotionStd() { return RansacParams(3, 0.5f, 0.5f, 0.99f); }
80  static RansacParams linearSimilarityMotionStd() { return RansacParams(4, 0.5f, 0.5f, 0.99f); }
81  static RansacParams affine2dMotionStd() { return RansacParams(6, 0.5f, 0.5f, 0.99f); }
82 };
83 
85  const std::vector<Point2f> &points0, const std::vector<Point2f> &points1,
86  int model = AFFINE, const RansacParams &params = RansacParams::affine2dMotionStd(),
87  float *rmse = 0, int *ninliers = 0);
88 
89 class CV_EXPORTS IGlobalMotionEstimator
90 {
91 public:
93  virtual Mat estimate(const Mat &frame0, const Mat &frame1) = 0;
94 };
95 
97 {
98 public:
100 
101  void setDetector(Ptr<FeatureDetector> val) { detector_ = val; }
102  Ptr<FeatureDetector> detector() const { return detector_; }
103 
104  void setOptFlowEstimator(Ptr<ISparseOptFlowEstimator> val) { optFlowEstimator_ = val; }
105  Ptr<ISparseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
106 
107  void setMotionModel(MotionModel val) { motionModel_ = val; }
108  MotionModel motionModel() const { return motionModel_; }
109 
110  void setRansacParams(const RansacParams &val) { ransacParams_ = val; }
111  RansacParams ransacParams() const { return ransacParams_; }
112 
113  void setMaxRmse(float val) { maxRmse_ = val; }
114  float maxRmse() const { return maxRmse_; }
115 
116  void setMinInlierRatio(float val) { minInlierRatio_ = val; }
117  float minInlierRatio() const { return minInlierRatio_; }
118 
119  virtual Mat estimate(const Mat &frame0, const Mat &frame1);
120 
121 private:
122  Ptr<FeatureDetector> detector_;
123  Ptr<ISparseOptFlowEstimator> optFlowEstimator_;
124  MotionModel motionModel_;
125  RansacParams ransacParams_;
126  std::vector<uchar> status_;
127  std::vector<KeyPoint> keypointsPrev_;
128  std::vector<Point2f> pointsPrev_, points_;
129  std::vector<Point2f> pointsPrevGood_, pointsGood_;
130  float maxRmse_;
131  float minInlierRatio_;
132 };
133 
134 CV_EXPORTS Mat getMotion(int from, int to, const Mat *motions, int size);
135 
136 CV_EXPORTS Mat getMotion(int from, int to, const std::vector<Mat> &motions);
137 
138 } // namespace videostab
139 } // namespace cv
140 
141 #endif
Ptr< FeatureDetector > detector() const
Definition: global_motion.hpp:102
float thresh
Definition: global_motion.hpp:71
float minInlierRatio() const
Definition: global_motion.hpp:117
Ptr< ISparseOptFlowEstimator > optFlowEstimator() const
Definition: global_motion.hpp:105
int size
Definition: global_motion.hpp:70
int CvMemStorage int double eps
Definition: imgproc_c.h:353
static RansacParams affine2dMotionStd()
Definition: global_motion.hpp:81
static RansacParams translationAndScale2dMotionStd()
Definition: global_motion.hpp:79
Definition: global_motion.hpp:59
Definition: global_motion.hpp:96
void setMaxRmse(float val)
Definition: global_motion.hpp:113
GLuint GLfloat * val
float eps
Definition: global_motion.hpp:72
RansacParams(int _size, float _thresh, float _eps, float _prob)
Definition: global_motion.hpp:75
float maxRmse() const
Definition: global_motion.hpp:114
RansacParams ransacParams() const
Definition: global_motion.hpp:111
Definition: global_motion.hpp:89
void setMinInlierRatio(float val)
Definition: global_motion.hpp:116
static RansacParams linearSimilarityMotionStd()
Definition: global_motion.hpp:80
void setDetector(Ptr< FeatureDetector > val)
Definition: global_motion.hpp:101
Definition: global_motion.hpp:60
static RansacParams translationMotionStd()
Definition: global_motion.hpp:78
MotionModel
Definition: global_motion.hpp:56
void setRansacParams(const RansacParams &val)
Definition: global_motion.hpp:110
The Core Functionality.
The n-dimensional matrix class.
Definition: core.hpp:1688
CV_EXPORTS Mat getMotion(int from, int to, const Mat *motions, int size)
void setMotionModel(MotionModel val)
Definition: global_motion.hpp:107
Definition: global_motion.hpp:68
GLenum const GLfloat * params
Definition: compat.hpp:688
Definition: global_motion.hpp:58
CV_EXPORTS Mat estimateGlobalMotionRobust(const std::vector< Point2f > &points0, const std::vector< Point2f > &points1, int model=AFFINE, const RansacParams &params=RansacParams::affine2dMotionStd(), float *rmse=0, int *ninliers=0)
virtual ~IGlobalMotionEstimator()
Definition: global_motion.hpp:92
Smart pointer to dynamically allocated objects.
Definition: core.hpp:1268
Definition: global_motion.hpp:61
CvMat * points1
Definition: calib3d.hpp:117
GLclampf f
float prob
Definition: global_motion.hpp:73
GLsizeiptr size
Definition: core_c.h:939
void setOptFlowEstimator(Ptr< ISparseOptFlowEstimator > val)
Definition: global_motion.hpp:104
MotionModel motionModel() const
Definition: global_motion.hpp:108
CV_EXPORTS Mat estimateGlobalMotionLeastSquares(const std::vector< Point2f > &points0, const std::vector< Point2f > &points1, int model=AFFINE, float *rmse=0)