Joe Verbout
/
main
opencv on mbed
Embed:
(wiki syntax)
Show/hide line numbers
stabilizer.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_STABILIZER_HPP__ 00044 #define __OPENCV_VIDEOSTAB_STABILIZER_HPP__ 00045 00046 #include <vector> 00047 #include <ctime> 00048 #include "opencv2/core.hpp" 00049 #include "opencv2/imgproc.hpp" 00050 #include "opencv2/videostab/global_motion.hpp" 00051 #include "opencv2/videostab/motion_stabilizing.hpp" 00052 #include "opencv2/videostab/frame_source.hpp" 00053 #include "opencv2/videostab/log.hpp" 00054 #include "opencv2/videostab/inpainting.hpp" 00055 #include "opencv2/videostab/deblurring.hpp" 00056 #include "opencv2/videostab/wobble_suppression.hpp" 00057 00058 namespace cv 00059 { 00060 namespace videostab 00061 { 00062 00063 //! @addtogroup videostab 00064 //! @{ 00065 00066 class CV_EXPORTS StabilizerBase 00067 { 00068 public: 00069 virtual ~StabilizerBase() {} 00070 00071 void setLog(Ptr<ILog> ilog) { log_ = ilog; } 00072 Ptr<ILog> log() const { return log_; } 00073 00074 void setRadius(int val) { radius_ = val; } 00075 int radius() const { return radius_; } 00076 00077 void setFrameSource(Ptr<IFrameSource> val) { frameSource_ = val; } 00078 Ptr<IFrameSource> frameSource() const { return frameSource_; } 00079 00080 void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; } 00081 Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; } 00082 00083 void setDeblurer(Ptr<DeblurerBase> val) { deblurer_ = val; } 00084 Ptr<DeblurerBase> deblurrer() const { return deblurer_; } 00085 00086 void setTrimRatio(float val) { trimRatio_ = val; } 00087 float trimRatio() const { return trimRatio_; } 00088 00089 void setCorrectionForInclusion(bool val) { doCorrectionForInclusion_ = val; } 00090 bool doCorrectionForInclusion() const { return doCorrectionForInclusion_; } 00091 00092 void setBorderMode(int val) { borderMode_ = val; } 00093 int borderMode() const { return borderMode_; } 00094 00095 void setInpainter(Ptr<InpainterBase> val) { inpainter_ = val; } 00096 Ptr<InpainterBase> inpainter() const { return inpainter_; } 00097 00098 protected: 00099 StabilizerBase(); 00100 00101 void reset(); 00102 Mat nextStabilizedFrame(); 00103 bool doOneIteration(); 00104 virtual void setUp(const Mat &firstFrame); 00105 virtual Mat estimateMotion() = 0; 00106 virtual Mat estimateStabilizationMotion() = 0; 00107 void stabilizeFrame(); 00108 virtual Mat postProcessFrame(const Mat &frame); 00109 void logProcessingTime(); 00110 00111 Ptr<ILog> log_; 00112 Ptr<IFrameSource> frameSource_; 00113 Ptr<ImageMotionEstimatorBase> motionEstimator_; 00114 Ptr<DeblurerBase> deblurer_; 00115 Ptr<InpainterBase> inpainter_; 00116 int radius_; 00117 float trimRatio_; 00118 bool doCorrectionForInclusion_; 00119 int borderMode_; 00120 00121 Size frameSize_; 00122 Mat frameMask_; 00123 int curPos_; 00124 int curStabilizedPos_; 00125 bool doDeblurring_; 00126 Mat preProcessedFrame_; 00127 bool doInpainting_; 00128 Mat inpaintingMask_; 00129 Mat finalFrame_; 00130 std::vector<Mat> frames_; 00131 std::vector<Mat> motions_; // motions_[i] is the motion from i-th to i+1-th frame 00132 std::vector<float> blurrinessRates_; 00133 std::vector<Mat> stabilizedFrames_; 00134 std::vector<Mat> stabilizedMasks_; 00135 std::vector<Mat> stabilizationMotions_; 00136 clock_t processingStartTime_; 00137 }; 00138 00139 class CV_EXPORTS OnePassStabilizer : public StabilizerBase, public IFrameSource 00140 { 00141 public: 00142 OnePassStabilizer(); 00143 00144 void setMotionFilter(Ptr<MotionFilterBase> val) { motionFilter_ = val; } 00145 Ptr<MotionFilterBase> motionFilter() const { return motionFilter_; } 00146 00147 virtual void reset(); 00148 virtual Mat nextFrame() { return nextStabilizedFrame(); } 00149 00150 protected: 00151 virtual void setUp(const Mat &firstFrame); 00152 virtual Mat estimateMotion(); 00153 virtual Mat estimateStabilizationMotion(); 00154 virtual Mat postProcessFrame(const Mat &frame); 00155 00156 Ptr<MotionFilterBase> motionFilter_; 00157 }; 00158 00159 class CV_EXPORTS TwoPassStabilizer : public StabilizerBase, public IFrameSource 00160 { 00161 public: 00162 TwoPassStabilizer(); 00163 00164 void setMotionStabilizer(Ptr<IMotionStabilizer> val) { motionStabilizer_ = val; } 00165 Ptr<IMotionStabilizer> motionStabilizer() const { return motionStabilizer_; } 00166 00167 void setWobbleSuppressor(Ptr<WobbleSuppressorBase> val) { wobbleSuppressor_ = val; } 00168 Ptr<WobbleSuppressorBase> wobbleSuppressor() const { return wobbleSuppressor_; } 00169 00170 void setEstimateTrimRatio(bool val) { mustEstTrimRatio_ = val; } 00171 bool mustEstimateTrimaRatio() const { return mustEstTrimRatio_; } 00172 00173 virtual void reset(); 00174 virtual Mat nextFrame(); 00175 00176 protected: 00177 void runPrePassIfNecessary(); 00178 00179 virtual void setUp(const Mat &firstFrame); 00180 virtual Mat estimateMotion(); 00181 virtual Mat estimateStabilizationMotion(); 00182 virtual Mat postProcessFrame(const Mat &frame); 00183 00184 Ptr<IMotionStabilizer> motionStabilizer_; 00185 Ptr<WobbleSuppressorBase> wobbleSuppressor_; 00186 bool mustEstTrimRatio_; 00187 00188 int frameCount_; 00189 bool isPrePassDone_; 00190 bool doWobbleSuppression_; 00191 std::vector<Mat> motions2_; 00192 Mat suppressedFrame_; 00193 }; 00194 00195 //! @} 00196 00197 } // namespace videostab 00198 } // namespace cv 00199 00200 #endif 00201
Generated on Tue Jul 12 2022 16:42:40 by 1.7.2