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_INPAINTINT_HPP__
44 #define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
47 #include "opencv2/core/core.hpp"
48 #include "opencv2/videostab/optical_flow.hpp"
49 #include "opencv2/videostab/fast_marching.hpp"
50 #include "opencv2/photo/photo.hpp"
57 class CV_EXPORTS IInpainter
61 : radius_(0), frames_(0), motions_(0),
62 stabilizedFrames_(0), stabilizationMotions_(0) {}
64 virtual ~IInpainter() {}
66 virtual void setRadius(int val) { radius_ = val; }
67 int radius() const { return radius_; }
69 virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
70 const std::vector<Mat>& frames() const { return *frames_; }
72 virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; }
73 const std::vector<Mat>& motions() const { return *motions_; }
75 virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; }
76 const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; }
78 virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
79 const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
81 virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
85 const std::vector<Mat> *frames_;
86 const std::vector<Mat> *motions_;
87 const std::vector<Mat> *stabilizedFrames_;
88 const std::vector<Mat> *stabilizationMotions_;
91 class CV_EXPORTS NullInpainter : public IInpainter
94 virtual void inpaint(int /*idx*/, Mat &/*frame*/, Mat &/*mask*/) {}
97 class CV_EXPORTS InpaintingPipeline : public IInpainter
100 void pushBack(Ptr<IInpainter> inpainter) { inpainters_.push_back(inpainter); }
101 bool empty() const { return inpainters_.empty(); }
103 virtual void setRadius(int val);
104 virtual void setFrames(const std::vector<Mat> &val);
105 virtual void setMotions(const std::vector<Mat> &val);
106 virtual void setStabilizedFrames(const std::vector<Mat> &val);
107 virtual void setStabilizationMotions(const std::vector<Mat> &val);
109 virtual void inpaint(int idx, Mat &frame, Mat &mask);
112 std::vector<Ptr<IInpainter> > inpainters_;
115 class CV_EXPORTS ConsistentMosaicInpainter : public IInpainter
118 ConsistentMosaicInpainter();
120 void setStdevThresh(float val) { stdevThresh_ = val; }
121 float stdevThresh() const { return stdevThresh_; }
123 virtual void inpaint(int idx, Mat &frame, Mat &mask);
129 class CV_EXPORTS MotionInpainter : public IInpainter
134 void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; }
135 Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
137 void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
138 float flowErrorThreshold() const { return flowErrorThreshold_; }
140 void setDistThreshold(float val) { distThresh_ = val; }
141 float distThresh() const { return distThresh_; }
143 void setBorderMode(int val) { borderMode_ = val; }
144 int borderMode() const { return borderMode_; }
146 virtual void inpaint(int idx, Mat &frame, Mat &mask);
149 FastMarchingMethod fmm_;
150 Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
151 float flowErrorThreshold_;
155 Mat frame1_, transformedFrame1_;
156 Mat_<uchar> grayFrame_, transformedGrayFrame1_;
157 Mat_<uchar> mask1_, transformedMask1_;
158 Mat_<float> flowX_, flowY_, flowErrors_;
159 Mat_<uchar> flowMask_;
162 class CV_EXPORTS ColorAverageInpainter : public IInpainter
165 virtual void inpaint(int idx, Mat &frame, Mat &mask);
168 FastMarchingMethod fmm_;
171 class CV_EXPORTS ColorInpainter : public IInpainter
174 ColorInpainter(int method = INPAINT_TELEA, double radius = 2.)
175 : method_(method), radius_(radius) {}
177 virtual void inpaint(int idx, Mat &frame, Mat &mask);
185 CV_EXPORTS void calcFlowMask(
186 const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError,
187 const Mat &mask0, const Mat &mask1, Mat &flowMask);
189 CV_EXPORTS void completeFrameAccordingToFlow(
190 const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
191 float distThresh, Mat& frame0, Mat &mask0);
193 } // namespace videostab