OpenCV 4.5.3(日本語機械翻訳)
stabilizer.hpp
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_STABILIZER_HPP
44 #define OPENCV_VIDEOSTAB_STABILIZER_HPP
45
46 #include <vector>
47 #include <ctime>
48 #include "opencv2/core.hpp"
49 #include "opencv2/imgproc.hpp"
50 #include "opencv2/videostab/global_motion.hpp"
51 #include "opencv2/videostab/motion_stabilizing.hpp"
52 #include "opencv2/videostab/frame_source.hpp"
53 #include "opencv2/videostab/log.hpp"
54 #include "opencv2/videostab/inpainting.hpp"
55 #include "opencv2/videostab/deblurring.hpp"
56 #include "opencv2/videostab/wobble_suppression.hpp"
57
58 namespace cv
59{
60 namespace videostab
61{
62
65
66 class CV_EXPORTS StabilizerBase
67{
68 public:
69 virtual ~StabilizerBase() {}
70
71 void setLog(Ptr<ILog> ilog) { log_ = ilog; }
72 Ptr<ILog> log() const { return log_; }
73
74 void setRadius(int val) { radius_ = val; }
75 int radius() const { return radius_; }
76
77 void setFrameSource(Ptr<IFrameSource> val) { frameSource_ = val; }
78 Ptr<IFrameSource> frameSource() const { return frameSource_; }
79
80 void setMaskSource(const Ptr<IFrameSource>& val) { maskSource_ = val; }
81 Ptr<IFrameSource> maskSource() const { return maskSource_; }
82
83 void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; }
84 Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; }
85
86 void setDeblurer(Ptr<DeblurerBase> val) { deblurer_ = val; }
87 Ptr<DeblurerBase> deblurrer() const { return deblurer_; }
88
89 void setTrimRatio(float val) { trimRatio_ = val; }
90 float trimRatio() const { return trimRatio_; }
91
92 void setCorrectionForInclusion(bool val) { doCorrectionForInclusion_ = val; }
93 bool doCorrectionForInclusion() const { return doCorrectionForInclusion_; }
94
95 void setBorderMode(int val) { borderMode_ = val; }
96 int borderMode() const { return borderMode_; }
97
98 void setInpainter(Ptr<InpainterBase> val) { inpainter_ = val; }
99 Ptr<InpainterBase> inpainter() const { return inpainter_; }
100
101 protected:
103
104 void reset();
105 Mat nextStabilizedFrame();
106 bool doOneIteration();
107 virtual void setUp(const Mat &firstFrame);
108 virtual Mat estimateMotion() = 0;
109 virtual Mat estimateStabilizationMotion() = 0;
110 void stabilizeFrame();
111 virtual Mat postProcessFrame(const Mat &frame);
112 void logProcessingTime();
113
114 Ptr<ILog> log_;
115 Ptr<IFrameSource> frameSource_;
116 Ptr<IFrameSource> maskSource_;
117 Ptr<ImageMotionEstimatorBase> motionEstimator_;
118 Ptr<DeblurerBase> deblurer_;
119 Ptr<InpainterBase> inpainter_;
120 int radius_;
121 float trimRatio_;
122 bool doCorrectionForInclusion_;
123 int borderMode_;
124
125 Size frameSize_;
126 Mat frameMask_;
127 int curPos_;
128 int curStabilizedPos_;
129 bool doDeblurring_;
130 Mat preProcessedFrame_;
131 bool doInpainting_;
132 Mat inpaintingMask_;
133 Mat finalFrame_;
134 std::vector<Mat> frames_;
135 std::vector<Mat> motions_; // motions_[i] is the motion from i-th to i+1-th frame
136 std::vector<float> blurrinessRates_;
137 std::vector<Mat> stabilizedFrames_;
138 std::vector<Mat> stabilizedMasks_;
139 std::vector<Mat> stabilizationMotions_;
140 clock_t processingStartTime_;
141};
142
143 class CV_EXPORTS OnePassStabilizer : public StabilizerBase, public IFrameSource
144{
145 public:
147
148 void setMotionFilter(Ptr<MotionFilterBase> val) { motionFilter_ = val; }
149 Ptr<MotionFilterBase> motionFilter() const { return motionFilter_; }
150
151 virtual void reset() CV_OVERRIDE;
152 virtual Mat nextFrame() CV_OVERRIDE { return nextStabilizedFrame(); }
153
154 protected:
155 virtual void setUp(const Mat &firstFrame) CV_OVERRIDE;
156 virtual Mat estimateMotion() CV_OVERRIDE;
157 virtual Mat estimateStabilizationMotion() CV_OVERRIDE;
158 virtual Mat postProcessFrame(const Mat &frame) CV_OVERRIDE;
159
160 Ptr<MotionFilterBase> motionFilter_;
161};
162
163 class CV_EXPORTS TwoPassStabilizer : public StabilizerBase, public IFrameSource
164{
165 public:
167
168 void setMotionStabilizer(Ptr<IMotionStabilizer> val) { motionStabilizer_ = val; }
169 Ptr<IMotionStabilizer> motionStabilizer() const { return motionStabilizer_; }
170
171 void setWobbleSuppressor(Ptr<WobbleSuppressorBase> val) { wobbleSuppressor_ = val; }
172 Ptr<WobbleSuppressorBase> wobbleSuppressor() const { return wobbleSuppressor_; }
173
174 void setEstimateTrimRatio(bool val) { mustEstTrimRatio_ = val; }
175 bool mustEstimateTrimaRatio() const { return mustEstTrimRatio_; }
176
177 virtual void reset() CV_OVERRIDE;
178 virtual Mat nextFrame() CV_OVERRIDE;
179
180 protected:
181 void runPrePassIfNecessary();
182
183 virtual void setUp(const Mat &firstFrame) CV_OVERRIDE;
184 virtual Mat estimateMotion() CV_OVERRIDE;
185 virtual Mat estimateStabilizationMotion() CV_OVERRIDE;
186 virtual Mat postProcessFrame(const Mat &frame) CV_OVERRIDE;
187
188 Ptr<IMotionStabilizer> motionStabilizer_;
189 Ptr<WobbleSuppressorBase> wobbleSuppressor_;
190 bool mustEstTrimRatio_;
191
192 int frameCount_;
193 bool isPrePassDone_;
194 bool doWobbleSuppression_;
195 std::vector<Mat> motions2_;
196 Mat suppressedFrame_;
197};
198
200
201} // namespace videostab
202} // namespace cv
203
204 #endif
n-dimensional dense array class
Definition: mat.hpp:802
Template class for specifying the size of an image or rectangle.
Definition: core/types.hpp:316
Definition: frame_source.hpp:58
Definition: stabilizer.hpp:144
Definition: stabilizer.hpp:67
Definition: stabilizer.hpp:164
CV_EXPORTS_W void log(InputArray src, OutputArray dst)
Calculates the natural logarithm of every array element.
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74