Joe Verbout
/
main
opencv on mbed
Embed:
(wiki syntax)
Show/hide line numbers
inpainting.hpp
00001 /*M/////////////////////////////////////////////////////////////////////////////////////// 00002 // 00003 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 00004 // 00005 // By downloading, copying, installing or using the software you agree to this license. 00006 // If you do not agree to this license, do not download, install, 00007 // copy or use the software. 00008 // 00009 // 00010 // License Agreement 00011 // For Open Source Computer Vision Library 00012 // 00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 00014 // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. 00015 // Third party copyrights are property of their respective owners. 00016 // 00017 // Redistribution and use in source and binary forms, with or without modification, 00018 // are permitted provided that the following conditions are met: 00019 // 00020 // * Redistribution's of source code must retain the above copyright notice, 00021 // this list of conditions and the following disclaimer. 00022 // 00023 // * Redistribution's in binary form must reproduce the above copyright notice, 00024 // this list of conditions and the following disclaimer in the documentation 00025 // and/or other materials provided with the distribution. 00026 // 00027 // * The name of the copyright holders may not be used to endorse or promote products 00028 // derived from this software without specific prior written permission. 00029 // 00030 // This software is provided by the copyright holders and contributors "as is" and 00031 // any express or implied warranties, including, but not limited to, the implied 00032 // warranties of merchantability and fitness for a particular purpose are disclaimed. 00033 // In no event shall the Intel Corporation or contributors be liable for any direct, 00034 // indirect, incidental, special, exemplary, or consequential damages 00035 // (including, but not limited to, procurement of substitute goods or services; 00036 // loss of use, data, or profits; or business interruption) however caused 00037 // and on any theory of liability, whether in contract, strict liability, 00038 // or tort (including negligence or otherwise) arising in any way out of 00039 // the use of this software, even if advised of the possibility of such damage. 00040 // 00041 //M*/ 00042 00043 #ifndef __OPENCV_VIDEOSTAB_INPAINTINT_HPP__ 00044 #define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__ 00045 00046 #include <vector> 00047 #include "opencv2/core.hpp" 00048 #include "opencv2/videostab/optical_flow.hpp" 00049 #include "opencv2/videostab/fast_marching.hpp" 00050 #include "opencv2/videostab/global_motion.hpp" 00051 #include "opencv2/photo.hpp" 00052 00053 namespace cv 00054 { 00055 namespace videostab 00056 { 00057 00058 //! @addtogroup videostab 00059 //! @{ 00060 00061 class CV_EXPORTS InpainterBase 00062 { 00063 public: 00064 InpainterBase() 00065 : radius_(0), motionModel_(MM_UNKNOWN), frames_(0), motions_(0), 00066 stabilizedFrames_(0), stabilizationMotions_(0) {} 00067 00068 virtual ~InpainterBase() {} 00069 00070 virtual void setRadius(int val) { radius_ = val; } 00071 virtual int radius() const { return radius_; } 00072 00073 virtual void setMotionModel(MotionModel val) { motionModel_ = val; } 00074 virtual MotionModel motionModel() const { return motionModel_; } 00075 00076 virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0; 00077 00078 00079 // data from stabilizer 00080 00081 virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; } 00082 virtual const std::vector<Mat>& frames() const { return *frames_; } 00083 00084 virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; } 00085 virtual const std::vector<Mat>& motions() const { return *motions_; } 00086 00087 virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; } 00088 virtual const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; } 00089 00090 virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; } 00091 virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; } 00092 00093 protected: 00094 int radius_; 00095 MotionModel motionModel_; 00096 const std::vector<Mat> *frames_; 00097 const std::vector<Mat> *motions_; 00098 const std::vector<Mat> *stabilizedFrames_; 00099 const std::vector<Mat> *stabilizationMotions_; 00100 }; 00101 00102 class CV_EXPORTS NullInpainter : public InpainterBase 00103 { 00104 public: 00105 virtual void inpaint(int /*idx*/, Mat &/*frame*/, Mat &/*mask*/) {} 00106 }; 00107 00108 class CV_EXPORTS InpaintingPipeline : public InpainterBase 00109 { 00110 public: 00111 void pushBack(Ptr<InpainterBase> inpainter) { inpainters_.push_back(inpainter); } 00112 bool empty() const { return inpainters_.empty(); } 00113 00114 virtual void setRadius(int val); 00115 virtual void setMotionModel(MotionModel val); 00116 virtual void setFrames(const std::vector<Mat> &val); 00117 virtual void setMotions(const std::vector<Mat> &val); 00118 virtual void setStabilizedFrames(const std::vector<Mat> &val); 00119 virtual void setStabilizationMotions(const std::vector<Mat> &val); 00120 00121 virtual void inpaint(int idx, Mat &frame, Mat &mask); 00122 00123 private: 00124 std::vector<Ptr<InpainterBase> > inpainters_; 00125 }; 00126 00127 class CV_EXPORTS ConsistentMosaicInpainter : public InpainterBase 00128 { 00129 public: 00130 ConsistentMosaicInpainter(); 00131 00132 void setStdevThresh(float val) { stdevThresh_ = val; } 00133 float stdevThresh() const { return stdevThresh_; } 00134 00135 virtual void inpaint(int idx, Mat &frame, Mat &mask); 00136 00137 private: 00138 float stdevThresh_; 00139 }; 00140 00141 class CV_EXPORTS MotionInpainter : public InpainterBase 00142 { 00143 public: 00144 MotionInpainter(); 00145 00146 void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; } 00147 Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; } 00148 00149 void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; } 00150 float flowErrorThreshold() const { return flowErrorThreshold_; } 00151 00152 void setDistThreshold(float val) { distThresh_ = val; } 00153 float distThresh() const { return distThresh_; } 00154 00155 void setBorderMode(int val) { borderMode_ = val; } 00156 int borderMode() const { return borderMode_; } 00157 00158 virtual void inpaint(int idx, Mat &frame, Mat &mask); 00159 00160 private: 00161 FastMarchingMethod fmm_; 00162 Ptr<IDenseOptFlowEstimator> optFlowEstimator_; 00163 float flowErrorThreshold_; 00164 float distThresh_; 00165 int borderMode_; 00166 00167 Mat frame1_, transformedFrame1_; 00168 Mat_<uchar> grayFrame_, transformedGrayFrame1_; 00169 Mat_<uchar> mask1_, transformedMask1_; 00170 Mat_<float> flowX_, flowY_, flowErrors_; 00171 Mat_<uchar> flowMask_; 00172 }; 00173 00174 class CV_EXPORTS ColorAverageInpainter : public InpainterBase 00175 { 00176 public: 00177 virtual void inpaint(int idx, Mat &frame, Mat &mask); 00178 00179 private: 00180 FastMarchingMethod fmm_; 00181 }; 00182 00183 class CV_EXPORTS ColorInpainter : public InpainterBase 00184 { 00185 public: 00186 ColorInpainter(int method = INPAINT_TELEA, double radius = 2.); 00187 00188 virtual void inpaint(int idx, Mat &frame, Mat &mask); 00189 00190 private: 00191 int method_; 00192 double radius_; 00193 Mat invMask_; 00194 }; 00195 00196 inline ColorInpainter::ColorInpainter(int _method, double _radius) 00197 : method_(_method), radius_(_radius) {} 00198 00199 CV_EXPORTS void calcFlowMask( 00200 const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError, 00201 const Mat &mask0, const Mat &mask1, Mat &flowMask); 00202 00203 CV_EXPORTS void completeFrameAccordingToFlow( 00204 const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1, 00205 float distThresh, Mat& frame0, Mat &mask0); 00206 00207 //! @} 00208 00209 } // namespace videostab 00210 } // namespace cv 00211 00212 #endif 00213
Generated on Tue Jul 12 2022 16:42:38 by 1.7.2