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