Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 #ifndef __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
00044 #define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
00045
00046 #include <vector>
00047 #include "opencv2/core/core.hpp"
00048 #include "opencv2/videostab/optical_flow.hpp"
00049 #include "opencv2/videostab/fast_marching.hpp"
00050 #include "opencv2/photo/photo.hpp"
00051
00052 namespace cv
00053 {
00054 namespace videostab
00055 {
00056
00057 class CV_EXPORTS InpainterBase
00058 {
00059 public:
00060 InpainterBase()
00061 : radius_(0), frames_(0), motions_(0),
00062 stabilizedFrames_(0), stabilizationMotions_(0) {}
00063
00064 virtual ~InpainterBase() {}
00065
00066 virtual void setRadius(int val) { radius_ = val; }
00067 virtual int radius() const { return radius_; }
00068
00069 virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
00070 virtual const std::vector<Mat>& frames() const { return *frames_; }
00071
00072 virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; }
00073 virtual const std::vector<Mat>& motions() const { return *motions_; }
00074
00075 virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; }
00076 virtual const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; }
00077
00078 virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
00079 virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
00080
00081 virtual void update() {}
00082
00083 virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
00084
00085 protected:
00086 int radius_;
00087 const std::vector<Mat> *frames_;
00088 const std::vector<Mat> *motions_;
00089 const std::vector<Mat> *stabilizedFrames_;
00090 const std::vector<Mat> *stabilizationMotions_;
00091 };
00092
00093 class CV_EXPORTS NullInpainter : public InpainterBase
00094 {
00095 public:
00096 virtual void inpaint(int , Mat &, Mat &) {}
00097 };
00098
00099 class CV_EXPORTS InpaintingPipeline : public InpainterBase
00100 {
00101 public:
00102 void pushBack(Ptr<InpainterBase> inpainter) { inpainters_.push_back(inpainter); }
00103 bool empty() const { return inpainters_.empty(); }
00104
00105 virtual void setRadius(int val);
00106 virtual void setFrames(const std::vector<Mat> &val);
00107 virtual void setMotions(const std::vector<Mat> &val);
00108 virtual void setStabilizedFrames(const std::vector<Mat> &val);
00109 virtual void setStabilizationMotions(const std::vector<Mat> &val);
00110
00111 virtual void update();
00112
00113 virtual void inpaint(int idx, Mat &frame, Mat &mask);
00114
00115 private:
00116 std::vector<Ptr<InpainterBase> > inpainters_;
00117 };
00118
00119 class CV_EXPORTS ConsistentMosaicInpainter : public InpainterBase
00120 {
00121 public:
00122 ConsistentMosaicInpainter();
00123
00124 void setStdevThresh(float val) { stdevThresh_ = val; }
00125 float stdevThresh() const { return stdevThresh_; }
00126
00127 virtual void inpaint(int idx, Mat &frame, Mat &mask);
00128
00129 private:
00130 float stdevThresh_;
00131 };
00132
00133 class CV_EXPORTS MotionInpainter : public InpainterBase
00134 {
00135 public:
00136 MotionInpainter();
00137
00138 void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; }
00139 Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
00140
00141 void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
00142 float flowErrorThreshold() const { return flowErrorThreshold_; }
00143
00144 void setDistThreshold(float val) { distThresh_ = val; }
00145 float distThresh() const { return distThresh_; }
00146
00147 void setBorderMode(int val) { borderMode_ = val; }
00148 int borderMode() const { return borderMode_; }
00149
00150 virtual void inpaint(int idx, Mat &frame, Mat &mask);
00151
00152 private:
00153 FastMarchingMethod fmm_;
00154 Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
00155 float flowErrorThreshold_;
00156 float distThresh_;
00157 int borderMode_;
00158
00159 Mat frame1_, transformedFrame1_;
00160 Mat_<uchar> grayFrame_, transformedGrayFrame1_;
00161 Mat_<uchar> mask1_, transformedMask1_;
00162 Mat_<float> flowX_, flowY_, flowErrors_;
00163 Mat_<uchar> flowMask_;
00164 };
00165
00166 class CV_EXPORTS ColorAverageInpainter : public InpainterBase
00167 {
00168 public:
00169 virtual void inpaint(int idx, Mat &frame, Mat &mask);
00170
00171 private:
00172 FastMarchingMethod fmm_;
00173 };
00174
00175 class CV_EXPORTS ColorInpainter : public InpainterBase
00176 {
00177 public:
00178 ColorInpainter(int method = INPAINT_TELEA, double _radius = 2.)
00179 : method_(method), radius_(_radius) {}
00180
00181 virtual void inpaint(int idx, Mat &frame, Mat &mask);
00182
00183 private:
00184 int method_;
00185 double radius_;
00186 Mat invMask_;
00187 };
00188
00189 CV_EXPORTS void calcFlowMask(
00190 const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError,
00191 const Mat &mask0, const Mat &mask1, Mat &flowMask);
00192
00193 CV_EXPORTS void completeFrameAccordingToFlow(
00194 const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
00195 float distThresh, Mat& frame0, Mat &mask0);
00196
00197 }
00198 }
00199
00200 #endif