Joe Verbout
/
main
opencv on mbed
opencv2/videostab/stabilizer.hpp@0:ea44dc9ed014, 2016-03-31 (annotated)
- Committer:
- joeverbout
- Date:
- Thu Mar 31 21:16:38 2016 +0000
- Revision:
- 0:ea44dc9ed014
OpenCV on mbed attempt
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
joeverbout | 0:ea44dc9ed014 | 1 | /*M/////////////////////////////////////////////////////////////////////////////////////// |
joeverbout | 0:ea44dc9ed014 | 2 | // |
joeverbout | 0:ea44dc9ed014 | 3 | // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. |
joeverbout | 0:ea44dc9ed014 | 4 | // |
joeverbout | 0:ea44dc9ed014 | 5 | // By downloading, copying, installing or using the software you agree to this license. |
joeverbout | 0:ea44dc9ed014 | 6 | // If you do not agree to this license, do not download, install, |
joeverbout | 0:ea44dc9ed014 | 7 | // copy or use the software. |
joeverbout | 0:ea44dc9ed014 | 8 | // |
joeverbout | 0:ea44dc9ed014 | 9 | // |
joeverbout | 0:ea44dc9ed014 | 10 | // License Agreement |
joeverbout | 0:ea44dc9ed014 | 11 | // For Open Source Computer Vision Library |
joeverbout | 0:ea44dc9ed014 | 12 | // |
joeverbout | 0:ea44dc9ed014 | 13 | // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 14 | // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. |
joeverbout | 0:ea44dc9ed014 | 15 | // Third party copyrights are property of their respective owners. |
joeverbout | 0:ea44dc9ed014 | 16 | // |
joeverbout | 0:ea44dc9ed014 | 17 | // Redistribution and use in source and binary forms, with or without modification, |
joeverbout | 0:ea44dc9ed014 | 18 | // are permitted provided that the following conditions are met: |
joeverbout | 0:ea44dc9ed014 | 19 | // |
joeverbout | 0:ea44dc9ed014 | 20 | // * Redistribution's of source code must retain the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 21 | // this list of conditions and the following disclaimer. |
joeverbout | 0:ea44dc9ed014 | 22 | // |
joeverbout | 0:ea44dc9ed014 | 23 | // * Redistribution's in binary form must reproduce the above copyright notice, |
joeverbout | 0:ea44dc9ed014 | 24 | // this list of conditions and the following disclaimer in the documentation |
joeverbout | 0:ea44dc9ed014 | 25 | // and/or other materials provided with the distribution. |
joeverbout | 0:ea44dc9ed014 | 26 | // |
joeverbout | 0:ea44dc9ed014 | 27 | // * The name of the copyright holders may not be used to endorse or promote products |
joeverbout | 0:ea44dc9ed014 | 28 | // derived from this software without specific prior written permission. |
joeverbout | 0:ea44dc9ed014 | 29 | // |
joeverbout | 0:ea44dc9ed014 | 30 | // This software is provided by the copyright holders and contributors "as is" and |
joeverbout | 0:ea44dc9ed014 | 31 | // any express or implied warranties, including, but not limited to, the implied |
joeverbout | 0:ea44dc9ed014 | 32 | // warranties of merchantability and fitness for a particular purpose are disclaimed. |
joeverbout | 0:ea44dc9ed014 | 33 | // In no event shall the Intel Corporation or contributors be liable for any direct, |
joeverbout | 0:ea44dc9ed014 | 34 | // indirect, incidental, special, exemplary, or consequential damages |
joeverbout | 0:ea44dc9ed014 | 35 | // (including, but not limited to, procurement of substitute goods or services; |
joeverbout | 0:ea44dc9ed014 | 36 | // loss of use, data, or profits; or business interruption) however caused |
joeverbout | 0:ea44dc9ed014 | 37 | // and on any theory of liability, whether in contract, strict liability, |
joeverbout | 0:ea44dc9ed014 | 38 | // or tort (including negligence or otherwise) arising in any way out of |
joeverbout | 0:ea44dc9ed014 | 39 | // the use of this software, even if advised of the possibility of such damage. |
joeverbout | 0:ea44dc9ed014 | 40 | // |
joeverbout | 0:ea44dc9ed014 | 41 | //M*/ |
joeverbout | 0:ea44dc9ed014 | 42 | |
joeverbout | 0:ea44dc9ed014 | 43 | #ifndef __OPENCV_VIDEOSTAB_STABILIZER_HPP__ |
joeverbout | 0:ea44dc9ed014 | 44 | #define __OPENCV_VIDEOSTAB_STABILIZER_HPP__ |
joeverbout | 0:ea44dc9ed014 | 45 | |
joeverbout | 0:ea44dc9ed014 | 46 | #include <vector> |
joeverbout | 0:ea44dc9ed014 | 47 | #include <ctime> |
joeverbout | 0:ea44dc9ed014 | 48 | #include "opencv2/core.hpp" |
joeverbout | 0:ea44dc9ed014 | 49 | #include "opencv2/imgproc.hpp" |
joeverbout | 0:ea44dc9ed014 | 50 | #include "opencv2/videostab/global_motion.hpp" |
joeverbout | 0:ea44dc9ed014 | 51 | #include "opencv2/videostab/motion_stabilizing.hpp" |
joeverbout | 0:ea44dc9ed014 | 52 | #include "opencv2/videostab/frame_source.hpp" |
joeverbout | 0:ea44dc9ed014 | 53 | #include "opencv2/videostab/log.hpp" |
joeverbout | 0:ea44dc9ed014 | 54 | #include "opencv2/videostab/inpainting.hpp" |
joeverbout | 0:ea44dc9ed014 | 55 | #include "opencv2/videostab/deblurring.hpp" |
joeverbout | 0:ea44dc9ed014 | 56 | #include "opencv2/videostab/wobble_suppression.hpp" |
joeverbout | 0:ea44dc9ed014 | 57 | |
joeverbout | 0:ea44dc9ed014 | 58 | namespace cv |
joeverbout | 0:ea44dc9ed014 | 59 | { |
joeverbout | 0:ea44dc9ed014 | 60 | namespace videostab |
joeverbout | 0:ea44dc9ed014 | 61 | { |
joeverbout | 0:ea44dc9ed014 | 62 | |
joeverbout | 0:ea44dc9ed014 | 63 | //! @addtogroup videostab |
joeverbout | 0:ea44dc9ed014 | 64 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 65 | |
joeverbout | 0:ea44dc9ed014 | 66 | class CV_EXPORTS StabilizerBase |
joeverbout | 0:ea44dc9ed014 | 67 | { |
joeverbout | 0:ea44dc9ed014 | 68 | public: |
joeverbout | 0:ea44dc9ed014 | 69 | virtual ~StabilizerBase() {} |
joeverbout | 0:ea44dc9ed014 | 70 | |
joeverbout | 0:ea44dc9ed014 | 71 | void setLog(Ptr<ILog> ilog) { log_ = ilog; } |
joeverbout | 0:ea44dc9ed014 | 72 | Ptr<ILog> log() const { return log_; } |
joeverbout | 0:ea44dc9ed014 | 73 | |
joeverbout | 0:ea44dc9ed014 | 74 | void setRadius(int val) { radius_ = val; } |
joeverbout | 0:ea44dc9ed014 | 75 | int radius() const { return radius_; } |
joeverbout | 0:ea44dc9ed014 | 76 | |
joeverbout | 0:ea44dc9ed014 | 77 | void setFrameSource(Ptr<IFrameSource> val) { frameSource_ = val; } |
joeverbout | 0:ea44dc9ed014 | 78 | Ptr<IFrameSource> frameSource() const { return frameSource_; } |
joeverbout | 0:ea44dc9ed014 | 79 | |
joeverbout | 0:ea44dc9ed014 | 80 | void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; } |
joeverbout | 0:ea44dc9ed014 | 81 | Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; } |
joeverbout | 0:ea44dc9ed014 | 82 | |
joeverbout | 0:ea44dc9ed014 | 83 | void setDeblurer(Ptr<DeblurerBase> val) { deblurer_ = val; } |
joeverbout | 0:ea44dc9ed014 | 84 | Ptr<DeblurerBase> deblurrer() const { return deblurer_; } |
joeverbout | 0:ea44dc9ed014 | 85 | |
joeverbout | 0:ea44dc9ed014 | 86 | void setTrimRatio(float val) { trimRatio_ = val; } |
joeverbout | 0:ea44dc9ed014 | 87 | float trimRatio() const { return trimRatio_; } |
joeverbout | 0:ea44dc9ed014 | 88 | |
joeverbout | 0:ea44dc9ed014 | 89 | void setCorrectionForInclusion(bool val) { doCorrectionForInclusion_ = val; } |
joeverbout | 0:ea44dc9ed014 | 90 | bool doCorrectionForInclusion() const { return doCorrectionForInclusion_; } |
joeverbout | 0:ea44dc9ed014 | 91 | |
joeverbout | 0:ea44dc9ed014 | 92 | void setBorderMode(int val) { borderMode_ = val; } |
joeverbout | 0:ea44dc9ed014 | 93 | int borderMode() const { return borderMode_; } |
joeverbout | 0:ea44dc9ed014 | 94 | |
joeverbout | 0:ea44dc9ed014 | 95 | void setInpainter(Ptr<InpainterBase> val) { inpainter_ = val; } |
joeverbout | 0:ea44dc9ed014 | 96 | Ptr<InpainterBase> inpainter() const { return inpainter_; } |
joeverbout | 0:ea44dc9ed014 | 97 | |
joeverbout | 0:ea44dc9ed014 | 98 | protected: |
joeverbout | 0:ea44dc9ed014 | 99 | StabilizerBase(); |
joeverbout | 0:ea44dc9ed014 | 100 | |
joeverbout | 0:ea44dc9ed014 | 101 | void reset(); |
joeverbout | 0:ea44dc9ed014 | 102 | Mat nextStabilizedFrame(); |
joeverbout | 0:ea44dc9ed014 | 103 | bool doOneIteration(); |
joeverbout | 0:ea44dc9ed014 | 104 | virtual void setUp(const Mat &firstFrame); |
joeverbout | 0:ea44dc9ed014 | 105 | virtual Mat estimateMotion() = 0; |
joeverbout | 0:ea44dc9ed014 | 106 | virtual Mat estimateStabilizationMotion() = 0; |
joeverbout | 0:ea44dc9ed014 | 107 | void stabilizeFrame(); |
joeverbout | 0:ea44dc9ed014 | 108 | virtual Mat postProcessFrame(const Mat &frame); |
joeverbout | 0:ea44dc9ed014 | 109 | void logProcessingTime(); |
joeverbout | 0:ea44dc9ed014 | 110 | |
joeverbout | 0:ea44dc9ed014 | 111 | Ptr<ILog> log_; |
joeverbout | 0:ea44dc9ed014 | 112 | Ptr<IFrameSource> frameSource_; |
joeverbout | 0:ea44dc9ed014 | 113 | Ptr<ImageMotionEstimatorBase> motionEstimator_; |
joeverbout | 0:ea44dc9ed014 | 114 | Ptr<DeblurerBase> deblurer_; |
joeverbout | 0:ea44dc9ed014 | 115 | Ptr<InpainterBase> inpainter_; |
joeverbout | 0:ea44dc9ed014 | 116 | int radius_; |
joeverbout | 0:ea44dc9ed014 | 117 | float trimRatio_; |
joeverbout | 0:ea44dc9ed014 | 118 | bool doCorrectionForInclusion_; |
joeverbout | 0:ea44dc9ed014 | 119 | int borderMode_; |
joeverbout | 0:ea44dc9ed014 | 120 | |
joeverbout | 0:ea44dc9ed014 | 121 | Size frameSize_; |
joeverbout | 0:ea44dc9ed014 | 122 | Mat frameMask_; |
joeverbout | 0:ea44dc9ed014 | 123 | int curPos_; |
joeverbout | 0:ea44dc9ed014 | 124 | int curStabilizedPos_; |
joeverbout | 0:ea44dc9ed014 | 125 | bool doDeblurring_; |
joeverbout | 0:ea44dc9ed014 | 126 | Mat preProcessedFrame_; |
joeverbout | 0:ea44dc9ed014 | 127 | bool doInpainting_; |
joeverbout | 0:ea44dc9ed014 | 128 | Mat inpaintingMask_; |
joeverbout | 0:ea44dc9ed014 | 129 | Mat finalFrame_; |
joeverbout | 0:ea44dc9ed014 | 130 | std::vector<Mat> frames_; |
joeverbout | 0:ea44dc9ed014 | 131 | std::vector<Mat> motions_; // motions_[i] is the motion from i-th to i+1-th frame |
joeverbout | 0:ea44dc9ed014 | 132 | std::vector<float> blurrinessRates_; |
joeverbout | 0:ea44dc9ed014 | 133 | std::vector<Mat> stabilizedFrames_; |
joeverbout | 0:ea44dc9ed014 | 134 | std::vector<Mat> stabilizedMasks_; |
joeverbout | 0:ea44dc9ed014 | 135 | std::vector<Mat> stabilizationMotions_; |
joeverbout | 0:ea44dc9ed014 | 136 | clock_t processingStartTime_; |
joeverbout | 0:ea44dc9ed014 | 137 | }; |
joeverbout | 0:ea44dc9ed014 | 138 | |
joeverbout | 0:ea44dc9ed014 | 139 | class CV_EXPORTS OnePassStabilizer : public StabilizerBase, public IFrameSource |
joeverbout | 0:ea44dc9ed014 | 140 | { |
joeverbout | 0:ea44dc9ed014 | 141 | public: |
joeverbout | 0:ea44dc9ed014 | 142 | OnePassStabilizer(); |
joeverbout | 0:ea44dc9ed014 | 143 | |
joeverbout | 0:ea44dc9ed014 | 144 | void setMotionFilter(Ptr<MotionFilterBase> val) { motionFilter_ = val; } |
joeverbout | 0:ea44dc9ed014 | 145 | Ptr<MotionFilterBase> motionFilter() const { return motionFilter_; } |
joeverbout | 0:ea44dc9ed014 | 146 | |
joeverbout | 0:ea44dc9ed014 | 147 | virtual void reset(); |
joeverbout | 0:ea44dc9ed014 | 148 | virtual Mat nextFrame() { return nextStabilizedFrame(); } |
joeverbout | 0:ea44dc9ed014 | 149 | |
joeverbout | 0:ea44dc9ed014 | 150 | protected: |
joeverbout | 0:ea44dc9ed014 | 151 | virtual void setUp(const Mat &firstFrame); |
joeverbout | 0:ea44dc9ed014 | 152 | virtual Mat estimateMotion(); |
joeverbout | 0:ea44dc9ed014 | 153 | virtual Mat estimateStabilizationMotion(); |
joeverbout | 0:ea44dc9ed014 | 154 | virtual Mat postProcessFrame(const Mat &frame); |
joeverbout | 0:ea44dc9ed014 | 155 | |
joeverbout | 0:ea44dc9ed014 | 156 | Ptr<MotionFilterBase> motionFilter_; |
joeverbout | 0:ea44dc9ed014 | 157 | }; |
joeverbout | 0:ea44dc9ed014 | 158 | |
joeverbout | 0:ea44dc9ed014 | 159 | class CV_EXPORTS TwoPassStabilizer : public StabilizerBase, public IFrameSource |
joeverbout | 0:ea44dc9ed014 | 160 | { |
joeverbout | 0:ea44dc9ed014 | 161 | public: |
joeverbout | 0:ea44dc9ed014 | 162 | TwoPassStabilizer(); |
joeverbout | 0:ea44dc9ed014 | 163 | |
joeverbout | 0:ea44dc9ed014 | 164 | void setMotionStabilizer(Ptr<IMotionStabilizer> val) { motionStabilizer_ = val; } |
joeverbout | 0:ea44dc9ed014 | 165 | Ptr<IMotionStabilizer> motionStabilizer() const { return motionStabilizer_; } |
joeverbout | 0:ea44dc9ed014 | 166 | |
joeverbout | 0:ea44dc9ed014 | 167 | void setWobbleSuppressor(Ptr<WobbleSuppressorBase> val) { wobbleSuppressor_ = val; } |
joeverbout | 0:ea44dc9ed014 | 168 | Ptr<WobbleSuppressorBase> wobbleSuppressor() const { return wobbleSuppressor_; } |
joeverbout | 0:ea44dc9ed014 | 169 | |
joeverbout | 0:ea44dc9ed014 | 170 | void setEstimateTrimRatio(bool val) { mustEstTrimRatio_ = val; } |
joeverbout | 0:ea44dc9ed014 | 171 | bool mustEstimateTrimaRatio() const { return mustEstTrimRatio_; } |
joeverbout | 0:ea44dc9ed014 | 172 | |
joeverbout | 0:ea44dc9ed014 | 173 | virtual void reset(); |
joeverbout | 0:ea44dc9ed014 | 174 | virtual Mat nextFrame(); |
joeverbout | 0:ea44dc9ed014 | 175 | |
joeverbout | 0:ea44dc9ed014 | 176 | protected: |
joeverbout | 0:ea44dc9ed014 | 177 | void runPrePassIfNecessary(); |
joeverbout | 0:ea44dc9ed014 | 178 | |
joeverbout | 0:ea44dc9ed014 | 179 | virtual void setUp(const Mat &firstFrame); |
joeverbout | 0:ea44dc9ed014 | 180 | virtual Mat estimateMotion(); |
joeverbout | 0:ea44dc9ed014 | 181 | virtual Mat estimateStabilizationMotion(); |
joeverbout | 0:ea44dc9ed014 | 182 | virtual Mat postProcessFrame(const Mat &frame); |
joeverbout | 0:ea44dc9ed014 | 183 | |
joeverbout | 0:ea44dc9ed014 | 184 | Ptr<IMotionStabilizer> motionStabilizer_; |
joeverbout | 0:ea44dc9ed014 | 185 | Ptr<WobbleSuppressorBase> wobbleSuppressor_; |
joeverbout | 0:ea44dc9ed014 | 186 | bool mustEstTrimRatio_; |
joeverbout | 0:ea44dc9ed014 | 187 | |
joeverbout | 0:ea44dc9ed014 | 188 | int frameCount_; |
joeverbout | 0:ea44dc9ed014 | 189 | bool isPrePassDone_; |
joeverbout | 0:ea44dc9ed014 | 190 | bool doWobbleSuppression_; |
joeverbout | 0:ea44dc9ed014 | 191 | std::vector<Mat> motions2_; |
joeverbout | 0:ea44dc9ed014 | 192 | Mat suppressedFrame_; |
joeverbout | 0:ea44dc9ed014 | 193 | }; |
joeverbout | 0:ea44dc9ed014 | 194 | |
joeverbout | 0:ea44dc9ed014 | 195 | //! @} |
joeverbout | 0:ea44dc9ed014 | 196 | |
joeverbout | 0:ea44dc9ed014 | 197 | } // namespace videostab |
joeverbout | 0:ea44dc9ed014 | 198 | } // namespace cv |
joeverbout | 0:ea44dc9ed014 | 199 | |
joeverbout | 0:ea44dc9ed014 | 200 | #endif |
joeverbout | 0:ea44dc9ed014 | 201 |