OpenCV 4.5.3(日本語機械翻訳)
videostab/inpainting.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_INPAINTINT_HPP
44 #define OPENCV_VIDEOSTAB_INPAINTINT_HPP
45
46 #include <vector>
47 #include "opencv2/core.hpp"
48 #include "opencv2/videostab/optical_flow.hpp"
49 #include "opencv2/videostab/fast_marching.hpp"
50 #include "opencv2/videostab/global_motion.hpp"
51 #include "opencv2/photo.hpp"
52
53 namespace cv
54{
55 namespace videostab
56{
57
60
61 class CV_EXPORTS InpainterBase
62{
63 public:
65 : radius_(0), motionModel_(MM_UNKNOWN), frames_(0), motions_(0),
66 stabilizedFrames_(0), stabilizationMotions_(0) {}
67
68 virtual ~InpainterBase() {}
69
70 virtual void setRadius(int val) { radius_ = val; }
71 virtual int radius() const { return radius_; }
72
73 virtual void setMotionModel(MotionModel val) { motionModel_ = val; }
74 virtual MotionModel motionModel() const { return motionModel_; }
75
76 virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
77
78
79 // data from stabilizer
80
81 virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
82 virtual const std::vector<Mat>& frames() const { return *frames_; }
83
84 virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; }
85 virtual const std::vector<Mat>& motions() const { return *motions_; }
86
87 virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; }
88 virtual const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; }
89
90 virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
91 virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
92
93 protected:
94 int radius_;
95 MotionModel motionModel_;
96 const std::vector<Mat> *frames_;
97 const std::vector<Mat> *motions_;
98 const std::vector<Mat> *stabilizedFrames_;
99 const std::vector<Mat> *stabilizationMotions_;
100};
101
102 class CV_EXPORTS NullInpainter : public InpainterBase
103{
104 public:
105 virtual void inpaint(int /*idx*/, Mat &/*frame*/, Mat &/*mask*/) CV_OVERRIDE {}
106};
107
108 class CV_EXPORTS InpaintingPipeline : public InpainterBase
109{
110 public:
111 void pushBack(Ptr<InpainterBase> inpainter) { inpainters_.push_back(inpainter); }
112 bool empty() const { return inpainters_.empty(); }
113
114 virtual void setRadius(int val) CV_OVERRIDE;
115 virtual void setMotionModel(MotionModel val) CV_OVERRIDE;
116 virtual void setFrames(const std::vector<Mat> &val) CV_OVERRIDE;
117 virtual void setMotions(const std::vector<Mat> &val) CV_OVERRIDE;
118 virtual void setStabilizedFrames(const std::vector<Mat> &val) CV_OVERRIDE;
119 virtual void setStabilizationMotions(const std::vector<Mat> &val) CV_OVERRIDE;
120
121 virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE;
122
123 private:
124 std::vector<Ptr<InpainterBase> > inpainters_;
125};
126
127 class CV_EXPORTS ConsistentMosaicInpainter : public InpainterBase
128{
129 public:
131
132 void setStdevThresh(float val) { stdevThresh_ = val; }
133 float stdevThresh() const { return stdevThresh_; }
134
135 virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE;
136
137 private:
138 float stdevThresh_;
139};
140
141 class CV_EXPORTS MotionInpainter : public InpainterBase
142{
143 public:
145
146 void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; }
147 Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
148
149 void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
150 float flowErrorThreshold() const { return flowErrorThreshold_; }
151
152 void setDistThreshold(float val) { distThresh_ = val; }
153 float distThresh() const { return distThresh_; }
154
155 void setBorderMode(int val) { borderMode_ = val; }
156 int borderMode() const { return borderMode_; }
157
158 virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE;
159
160 private:
162 Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
163 float flowErrorThreshold_;
164 float distThresh_;
165 int borderMode_;
166
167 Mat frame1_, transformedFrame1_;
168 Mat_<uchar> grayFrame_, transformedGrayFrame1_;
169 Mat_<uchar> mask1_, transformedMask1_;
170 Mat_<float> flowX_, flowY_, flowErrors_;
171 Mat_<uchar> flowMask_;
172};
173
174 class CV_EXPORTS ColorAverageInpainter : public InpainterBase
175{
176 public:
177 virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE;
178
179 private:
181};
182
183 class CV_EXPORTS ColorInpainter : public InpainterBase
184{
185 public:
186 ColorInpainter(int method = INPAINT_TELEA, double radius = 2.);
187
188 virtual void inpaint(int idx, Mat &frame, Mat &mask) CV_OVERRIDE;
189
190 private:
191 int method_;
192 double radius_;
193 Mat invMask_;
194};
195
196 inline ColorInpainter::ColorInpainter(int _method, double _radius)
197 : method_(_method), radius_(_radius) {}
198
199CV_EXPORTS void calcFlowMask(
200 const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError,
201 const Mat &mask0, const Mat &mask1, Mat &flowMask);
202
203CV_EXPORTS void completeFrameAccordingToFlow(
204 const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
205 float distThresh, Mat& frame0, Mat &mask0);
206
208
209} // namespace videostab
210} // namespace cv
211
212 #endif
Template matrix class derived from Mat
Definition: mat.hpp:2199
n-dimensional dense array class
Definition: mat.hpp:802
Definition: videostab/inpainting.hpp:175
Definition: videostab/inpainting.hpp:184
Definition: videostab/inpainting.hpp:128
Describes the Fast Marching Method implementation.
Definition: fast_marching.hpp:64
Definition: videostab/inpainting.hpp:62
Definition: videostab/inpainting.hpp:109
Definition: videostab/inpainting.hpp:142
Definition: videostab/inpainting.hpp:103
CV_EXPORTS_W void inpaint(InputArray src, InputArray inpaintMask, OutputArray dst, double inpaintRadius, int flags)
Restores the selected region in an image using the region neighborhood.
@ INPAINT_TELEA
Use the algorithm proposed by Alexandru Telea
Definition: photo.hpp:97
MotionModel
Describes motion model between two point clouds.
Definition: motion_core.hpp:60
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74