inpainting.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_INPAINTINT_HPP__
44 #define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
45 
46 #include <vector>
47 #include "opencv2/core/core.hpp"
50 #include "opencv2/photo/photo.hpp"
51 
52 namespace cv
53 {
54 namespace videostab
55 {
56 
57 class CV_EXPORTS InpainterBase
58 {
59 public:
61  : radius_(0), frames_(0), motions_(0),
62  stabilizedFrames_(0), stabilizationMotions_(0) {}
63 
64  virtual ~InpainterBase() {}
65 
66  virtual void setRadius(int val) { radius_ = val; }
67  virtual int radius() const { return radius_; }
68 
69  virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
70  virtual const std::vector<Mat>& frames() const { return *frames_; }
71 
72  virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; }
73  virtual const std::vector<Mat>& motions() const { return *motions_; }
74 
75  virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; }
76  virtual const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; }
77 
78  virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
79  virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
80 
81  virtual void update() {}
82 
83  virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
84 
85 protected:
86  int radius_;
87  const std::vector<Mat> *frames_;
88  const std::vector<Mat> *motions_;
89  const std::vector<Mat> *stabilizedFrames_;
90  const std::vector<Mat> *stabilizationMotions_;
91 };
92 
93 class CV_EXPORTS NullInpainter : public InpainterBase
94 {
95 public:
96  virtual void inpaint(int /*idx*/, Mat &/*frame*/, Mat &/*mask*/) {}
97 };
98 
99 class CV_EXPORTS InpaintingPipeline : public InpainterBase
100 {
101 public:
102  void pushBack(Ptr<InpainterBase> inpainter) { inpainters_.push_back(inpainter); }
103  bool empty() const { return inpainters_.empty(); }
104 
105  virtual void setRadius(int val);
106  virtual void setFrames(const std::vector<Mat> &val);
107  virtual void setMotions(const std::vector<Mat> &val);
108  virtual void setStabilizedFrames(const std::vector<Mat> &val);
109  virtual void setStabilizationMotions(const std::vector<Mat> &val);
110 
111  virtual void update();
112 
113  virtual void inpaint(int idx, Mat &frame, Mat &mask);
114 
115 private:
116  std::vector<Ptr<InpainterBase> > inpainters_;
117 };
118 
119 class CV_EXPORTS ConsistentMosaicInpainter : public InpainterBase
120 {
121 public:
123 
124  void setStdevThresh(float val) { stdevThresh_ = val; }
125  float stdevThresh() const { return stdevThresh_; }
126 
127  virtual void inpaint(int idx, Mat &frame, Mat &mask);
128 
129 private:
130  float stdevThresh_;
131 };
132 
133 class CV_EXPORTS MotionInpainter : public InpainterBase
134 {
135 public:
136  MotionInpainter();
137 
138  void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; }
139  Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
140 
141  void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
142  float flowErrorThreshold() const { return flowErrorThreshold_; }
143 
144  void setDistThreshold(float val) { distThresh_ = val; }
145  float distThresh() const { return distThresh_; }
146 
147  void setBorderMode(int val) { borderMode_ = val; }
148  int borderMode() const { return borderMode_; }
149 
150  virtual void inpaint(int idx, Mat &frame, Mat &mask);
151 
152 private:
153  FastMarchingMethod fmm_;
154  Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
155  float flowErrorThreshold_;
156  float distThresh_;
157  int borderMode_;
158 
159  Mat frame1_, transformedFrame1_;
160  Mat_<uchar> grayFrame_, transformedGrayFrame1_;
161  Mat_<uchar> mask1_, transformedMask1_;
162  Mat_<float> flowX_, flowY_, flowErrors_;
163  Mat_<uchar> flowMask_;
164 };
165 
166 class CV_EXPORTS ColorAverageInpainter : public InpainterBase
167 {
168 public:
169  virtual void inpaint(int idx, Mat &frame, Mat &mask);
170 
171 private:
172  FastMarchingMethod fmm_;
173 };
174 
175 class CV_EXPORTS ColorInpainter : public InpainterBase
176 {
177 public:
178  ColorInpainter(int method = INPAINT_TELEA, double _radius = 2.)
179  : method_(method), radius_(_radius) {}
180 
181  virtual void inpaint(int idx, Mat &frame, Mat &mask);
182 
183 private:
184  int method_;
185  double radius_;
186  Mat invMask_;
187 };
188 
189 CV_EXPORTS void calcFlowMask(
190  const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError,
191  const Mat &mask0, const Mat &mask1, Mat &flowMask);
192 
193 CV_EXPORTS void completeFrameAccordingToFlow(
194  const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
195  float distThresh, Mat& frame0, Mat &mask0);
196 
197 } // namespace videostab
198 } // namespace cv
199 
200 #endif
Definition: inpainting.hpp:133
void setFlowErrorThreshold(float val)
Definition: inpainting.hpp:141
virtual void setStabilizationMotions(const std::vector< Mat > &val)
Definition: inpainting.hpp:78
virtual void inpaint(int, Mat &, Mat &)
Definition: inpainting.hpp:96
bool empty() const
Definition: inpainting.hpp:103
const std::vector< Mat > * frames_
Definition: inpainting.hpp:87
CV_EXPORTS_W void inpaint(InputArray src, InputArray inpaintMask, OutputArray dst, double inpaintRadius, int flags)
restores the damaged image areas using one of the available intpainting algorithms ...
float flowErrorThreshold() const
Definition: inpainting.hpp:142
const int * idx
Definition: core_c.h:323
const std::vector< Mat > * motions_
Definition: inpainting.hpp:88
InpainterBase()
Definition: inpainting.hpp:60
const std::vector< Mat > * stabilizedFrames_
Definition: inpainting.hpp:89
void setStdevThresh(float val)
Definition: inpainting.hpp:124
virtual void update()
Definition: inpainting.hpp:81
virtual void setFrames(const std::vector< Mat > &val)
Definition: inpainting.hpp:69
const CvArr CvArr int method
Definition: imgproc_c.h:281
float distThresh() const
Definition: inpainting.hpp:145
float stdevThresh() const
Definition: inpainting.hpp:125
const std::vector< Mat > * stabilizationMotions_
Definition: inpainting.hpp:90
Definition: inpainting.hpp:93
virtual ~InpainterBase()
Definition: inpainting.hpp:64
CV_EXPORTS void calcFlowMask(const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError, const Mat &mask0, const Mat &mask1, Mat &flowMask)
GLuint GLfloat * val
virtual const std::vector< Mat > & stabilizedFrames() const
Definition: inpainting.hpp:76
Definition: fast_marching.hpp:57
Definition: inpainting.hpp:119
CV_EXPORTS void completeFrameAccordingToFlow(const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1, float distThresh, Mat &frame0, Mat &mask0)
Definition: inpainting.hpp:99
virtual void setMotions(const std::vector< Mat > &val)
Definition: inpainting.hpp:72
void setDistThreshold(float val)
Definition: inpainting.hpp:144
Ptr< IDenseOptFlowEstimator > optFlowEstimator() const
Definition: inpainting.hpp:139
virtual const std::vector< Mat > & motions() const
Definition: inpainting.hpp:73
void setOptFlowEstimator(Ptr< IDenseOptFlowEstimator > val)
Definition: inpainting.hpp:138
virtual void setStabilizedFrames(const std::vector< Mat > &val)
Definition: inpainting.hpp:75
The Core Functionality.
The n-dimensional matrix class.
Definition: core.hpp:1688
Definition: inpainting.hpp:166
Definition: photo.hpp:63
void void * frame
Definition: core_c.h:1459
int radius_
Definition: inpainting.hpp:86
void setBorderMode(int val)
Definition: inpainting.hpp:147
Definition: inpainting.hpp:57
void pushBack(Ptr< InpainterBase > inpainter)
Definition: inpainting.hpp:102
virtual const std::vector< Mat > & stabilizationMotions() const
Definition: inpainting.hpp:79
ColorInpainter(int method=INPAINT_TELEA, double _radius=2.)
Definition: inpainting.hpp:178
virtual const std::vector< Mat > & frames() const
Definition: inpainting.hpp:70
Definition: inpainting.hpp:175
Smart pointer to dynamically allocated objects.
Definition: core.hpp:1268
virtual void setRadius(int val)
Definition: inpainting.hpp:66
int borderMode() const
Definition: inpainting.hpp:148
GLenum GLint GLuint mask
Definition: tracking.hpp:132
virtual int radius() const
Definition: inpainting.hpp:67