1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
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.
11 // For Open Source Computer Vision Library
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.
17 // Redistribution and use in source and binary forms, with or without modification,
18 // are permitted provided that the following conditions are met:
20 // * Redistribution's of source code must retain the above copyright notice,
21 // this list of conditions and the following disclaimer.
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.
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.
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.
43 #ifndef __OPENCV_VIDEOSTAB_STABILIZER_HPP__
44 #define __OPENCV_VIDEOSTAB_STABILIZER_HPP__
47 #include "opencv2/core/core.hpp"
48 #include "opencv2/imgproc/imgproc.hpp"
49 #include "opencv2/videostab/global_motion.hpp"
50 #include "opencv2/videostab/motion_stabilizing.hpp"
51 #include "opencv2/videostab/frame_source.hpp"
52 #include "opencv2/videostab/log.hpp"
53 #include "opencv2/videostab/inpainting.hpp"
54 #include "opencv2/videostab/deblurring.hpp"
55 #include "opencv2/videostab/wobble_suppression.hpp"
62 class CV_EXPORTS StabilizerBase
65 virtual ~StabilizerBase() {}
67 void setLog(Ptr<ILog> log) { log_ = log; }
68 Ptr<ILog> log() const { return log_; }
70 void setRadius(int val) { radius_ = val; }
71 int radius() const { return radius_; }
73 void setFrameSource(Ptr<IFrameSource> val) { frameSource_ = val; }
74 Ptr<IFrameSource> frameSource() const { return frameSource_; }
76 void setMotionEstimator(Ptr<GlobalMotionEstimatorBase> val) { motionEstimator_ = val; }
77 Ptr<GlobalMotionEstimatorBase> motionEstimator() const { return motionEstimator_; }
79 void setDeblurer(Ptr<DeblurerBase> val) { deblurer_ = val; }
80 Ptr<DeblurerBase> deblurrer() const { return deblurer_; }
82 void setTrimRatio(float val) { trimRatio_ = val; }
83 float trimRatio() const { return trimRatio_; }
85 void setCorrectionForInclusion(bool val) { doCorrectionForInclusion_ = val; }
86 bool doCorrectionForInclusion() const { return doCorrectionForInclusion_; }
88 void setBorderMode(int val) { borderMode_ = val; }
89 int borderMode() const { return borderMode_; }
91 void setInpainter(Ptr<InpainterBase> val) { inpainter_ = val; }
92 Ptr<InpainterBase> inpainter() const { return inpainter_; }
98 Mat nextStabilizedFrame();
99 bool doOneIteration();
100 virtual void setUp(const Mat &firstFrame);
101 virtual Mat estimateMotion() = 0;
102 virtual Mat estimateStabilizationMotion() = 0;
103 void stabilizeFrame();
104 virtual Mat postProcessFrame(const Mat &frame);
107 Ptr<IFrameSource> frameSource_;
108 Ptr<GlobalMotionEstimatorBase> motionEstimator_;
109 Ptr<DeblurerBase> deblurer_;
110 Ptr<InpainterBase> inpainter_;
113 bool doCorrectionForInclusion_;
119 int curStabilizedPos_;
121 Mat preProcessedFrame_;
125 std::vector<Mat> frames_;
126 std::vector<Mat> motions_; // motions_[i] is the motion from i-th to i+1-th frame
127 std::vector<float> blurrinessRates_;
128 std::vector<Mat> stabilizedFrames_;
129 std::vector<Mat> stabilizedMasks_;
130 std::vector<Mat> stabilizationMotions_;
133 class CV_EXPORTS OnePassStabilizer : public StabilizerBase, public IFrameSource
138 void setMotionFilter(Ptr<MotionFilterBase> val) { motionFilter_ = val; }
139 Ptr<MotionFilterBase> motionFilter() const { return motionFilter_; }
141 virtual void reset();
142 virtual Mat nextFrame() { return nextStabilizedFrame(); }
145 virtual void setUp(const Mat &firstFrame);
146 virtual Mat estimateMotion();
147 virtual Mat estimateStabilizationMotion();
148 virtual Mat postProcessFrame(const Mat &frame);
150 Ptr<MotionFilterBase> motionFilter_;
153 class CV_EXPORTS TwoPassStabilizer : public StabilizerBase, public IFrameSource
158 void setMotionStabilizer(Ptr<IMotionStabilizer> val) { motionStabilizer_ = val; }
159 Ptr<IMotionStabilizer> motionStabilizer() const { return motionStabilizer_; }
161 void setWobbleSuppressor(Ptr<WobbleSuppressorBase> val) { wobbleSuppressor_ = val; }
162 Ptr<WobbleSuppressorBase> wobbleSuppressor() const { return wobbleSuppressor_; }
164 void setEstimateTrimRatio(bool val) { mustEstTrimRatio_ = val; }
165 bool mustEstimateTrimaRatio() const { return mustEstTrimRatio_; }
167 virtual void reset();
168 virtual Mat nextFrame();
170 // available after pre-pass, before it's empty
171 std::vector<Mat> motions() const;
174 void runPrePassIfNecessary();
176 virtual void setUp(const Mat &firstFrame);
177 virtual Mat estimateMotion();
178 virtual Mat estimateStabilizationMotion();
179 virtual Mat postProcessFrame(const Mat &frame);
181 Ptr<IMotionStabilizer> motionStabilizer_;
182 Ptr<WobbleSuppressorBase> wobbleSuppressor_;
183 bool mustEstTrimRatio_;
187 Mat suppressedFrame_;
190 } // namespace videostab