Joe Verbout
/
main
opencv on mbed
opencv2/videostab/motion_stabilizing.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_MOTION_STABILIZING_HPP__ |
joeverbout | 0:ea44dc9ed014 | 44 | #define __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__ |
joeverbout | 0:ea44dc9ed014 | 45 | |
joeverbout | 0:ea44dc9ed014 | 46 | #include <vector> |
joeverbout | 0:ea44dc9ed014 | 47 | #include <utility> |
joeverbout | 0:ea44dc9ed014 | 48 | #include "opencv2/core.hpp" |
joeverbout | 0:ea44dc9ed014 | 49 | #include "opencv2/videostab/global_motion.hpp" |
joeverbout | 0:ea44dc9ed014 | 50 | |
joeverbout | 0:ea44dc9ed014 | 51 | namespace cv |
joeverbout | 0:ea44dc9ed014 | 52 | { |
joeverbout | 0:ea44dc9ed014 | 53 | namespace videostab |
joeverbout | 0:ea44dc9ed014 | 54 | { |
joeverbout | 0:ea44dc9ed014 | 55 | |
joeverbout | 0:ea44dc9ed014 | 56 | //! @addtogroup videostab_motion |
joeverbout | 0:ea44dc9ed014 | 57 | //! @{ |
joeverbout | 0:ea44dc9ed014 | 58 | |
joeverbout | 0:ea44dc9ed014 | 59 | class CV_EXPORTS IMotionStabilizer |
joeverbout | 0:ea44dc9ed014 | 60 | { |
joeverbout | 0:ea44dc9ed014 | 61 | public: |
joeverbout | 0:ea44dc9ed014 | 62 | virtual ~IMotionStabilizer() {} |
joeverbout | 0:ea44dc9ed014 | 63 | |
joeverbout | 0:ea44dc9ed014 | 64 | //! assumes that [0, size-1) is in or equals to [range.first, range.second) |
joeverbout | 0:ea44dc9ed014 | 65 | virtual void stabilize( |
joeverbout | 0:ea44dc9ed014 | 66 | int size, const std::vector<Mat> &motions, std::pair<int,int> range, |
joeverbout | 0:ea44dc9ed014 | 67 | Mat *stabilizationMotions) = 0; |
joeverbout | 0:ea44dc9ed014 | 68 | }; |
joeverbout | 0:ea44dc9ed014 | 69 | |
joeverbout | 0:ea44dc9ed014 | 70 | class CV_EXPORTS MotionStabilizationPipeline : public IMotionStabilizer |
joeverbout | 0:ea44dc9ed014 | 71 | { |
joeverbout | 0:ea44dc9ed014 | 72 | public: |
joeverbout | 0:ea44dc9ed014 | 73 | void pushBack(Ptr<IMotionStabilizer> stabilizer) { stabilizers_.push_back(stabilizer); } |
joeverbout | 0:ea44dc9ed014 | 74 | bool empty() const { return stabilizers_.empty(); } |
joeverbout | 0:ea44dc9ed014 | 75 | |
joeverbout | 0:ea44dc9ed014 | 76 | virtual void stabilize( |
joeverbout | 0:ea44dc9ed014 | 77 | int size, const std::vector<Mat> &motions, std::pair<int,int> range, |
joeverbout | 0:ea44dc9ed014 | 78 | Mat *stabilizationMotions); |
joeverbout | 0:ea44dc9ed014 | 79 | |
joeverbout | 0:ea44dc9ed014 | 80 | private: |
joeverbout | 0:ea44dc9ed014 | 81 | std::vector<Ptr<IMotionStabilizer> > stabilizers_; |
joeverbout | 0:ea44dc9ed014 | 82 | }; |
joeverbout | 0:ea44dc9ed014 | 83 | |
joeverbout | 0:ea44dc9ed014 | 84 | class CV_EXPORTS MotionFilterBase : public IMotionStabilizer |
joeverbout | 0:ea44dc9ed014 | 85 | { |
joeverbout | 0:ea44dc9ed014 | 86 | public: |
joeverbout | 0:ea44dc9ed014 | 87 | virtual ~MotionFilterBase() {} |
joeverbout | 0:ea44dc9ed014 | 88 | |
joeverbout | 0:ea44dc9ed014 | 89 | virtual Mat stabilize( |
joeverbout | 0:ea44dc9ed014 | 90 | int idx, const std::vector<Mat> &motions, std::pair<int,int> range) = 0; |
joeverbout | 0:ea44dc9ed014 | 91 | |
joeverbout | 0:ea44dc9ed014 | 92 | virtual void stabilize( |
joeverbout | 0:ea44dc9ed014 | 93 | int size, const std::vector<Mat> &motions, std::pair<int,int> range, |
joeverbout | 0:ea44dc9ed014 | 94 | Mat *stabilizationMotions); |
joeverbout | 0:ea44dc9ed014 | 95 | }; |
joeverbout | 0:ea44dc9ed014 | 96 | |
joeverbout | 0:ea44dc9ed014 | 97 | class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase |
joeverbout | 0:ea44dc9ed014 | 98 | { |
joeverbout | 0:ea44dc9ed014 | 99 | public: |
joeverbout | 0:ea44dc9ed014 | 100 | GaussianMotionFilter(int radius = 15, float stdev = -1.f); |
joeverbout | 0:ea44dc9ed014 | 101 | |
joeverbout | 0:ea44dc9ed014 | 102 | void setParams(int radius, float stdev = -1.f); |
joeverbout | 0:ea44dc9ed014 | 103 | int radius() const { return radius_; } |
joeverbout | 0:ea44dc9ed014 | 104 | float stdev() const { return stdev_; } |
joeverbout | 0:ea44dc9ed014 | 105 | |
joeverbout | 0:ea44dc9ed014 | 106 | virtual Mat stabilize( |
joeverbout | 0:ea44dc9ed014 | 107 | int idx, const std::vector<Mat> &motions, std::pair<int,int> range); |
joeverbout | 0:ea44dc9ed014 | 108 | |
joeverbout | 0:ea44dc9ed014 | 109 | private: |
joeverbout | 0:ea44dc9ed014 | 110 | int radius_; |
joeverbout | 0:ea44dc9ed014 | 111 | float stdev_; |
joeverbout | 0:ea44dc9ed014 | 112 | std::vector<float> weight_; |
joeverbout | 0:ea44dc9ed014 | 113 | }; |
joeverbout | 0:ea44dc9ed014 | 114 | |
joeverbout | 0:ea44dc9ed014 | 115 | inline GaussianMotionFilter::GaussianMotionFilter(int _radius, float _stdev) { setParams(_radius, _stdev); } |
joeverbout | 0:ea44dc9ed014 | 116 | |
joeverbout | 0:ea44dc9ed014 | 117 | class CV_EXPORTS LpMotionStabilizer : public IMotionStabilizer |
joeverbout | 0:ea44dc9ed014 | 118 | { |
joeverbout | 0:ea44dc9ed014 | 119 | public: |
joeverbout | 0:ea44dc9ed014 | 120 | LpMotionStabilizer(MotionModel model = MM_SIMILARITY); |
joeverbout | 0:ea44dc9ed014 | 121 | |
joeverbout | 0:ea44dc9ed014 | 122 | void setMotionModel(MotionModel val) { model_ = val; } |
joeverbout | 0:ea44dc9ed014 | 123 | MotionModel motionModel() const { return model_; } |
joeverbout | 0:ea44dc9ed014 | 124 | |
joeverbout | 0:ea44dc9ed014 | 125 | void setFrameSize(Size val) { frameSize_ = val; } |
joeverbout | 0:ea44dc9ed014 | 126 | Size frameSize() const { return frameSize_; } |
joeverbout | 0:ea44dc9ed014 | 127 | |
joeverbout | 0:ea44dc9ed014 | 128 | void setTrimRatio(float val) { trimRatio_ = val; } |
joeverbout | 0:ea44dc9ed014 | 129 | float trimRatio() const { return trimRatio_; } |
joeverbout | 0:ea44dc9ed014 | 130 | |
joeverbout | 0:ea44dc9ed014 | 131 | void setWeight1(float val) { w1_ = val; } |
joeverbout | 0:ea44dc9ed014 | 132 | float weight1() const { return w1_; } |
joeverbout | 0:ea44dc9ed014 | 133 | |
joeverbout | 0:ea44dc9ed014 | 134 | void setWeight2(float val) { w2_ = val; } |
joeverbout | 0:ea44dc9ed014 | 135 | float weight2() const { return w2_; } |
joeverbout | 0:ea44dc9ed014 | 136 | |
joeverbout | 0:ea44dc9ed014 | 137 | void setWeight3(float val) { w3_ = val; } |
joeverbout | 0:ea44dc9ed014 | 138 | float weight3() const { return w3_; } |
joeverbout | 0:ea44dc9ed014 | 139 | |
joeverbout | 0:ea44dc9ed014 | 140 | void setWeight4(float val) { w4_ = val; } |
joeverbout | 0:ea44dc9ed014 | 141 | float weight4() const { return w4_; } |
joeverbout | 0:ea44dc9ed014 | 142 | |
joeverbout | 0:ea44dc9ed014 | 143 | virtual void stabilize( |
joeverbout | 0:ea44dc9ed014 | 144 | int size, const std::vector<Mat> &motions, std::pair<int,int> range, |
joeverbout | 0:ea44dc9ed014 | 145 | Mat *stabilizationMotions); |
joeverbout | 0:ea44dc9ed014 | 146 | |
joeverbout | 0:ea44dc9ed014 | 147 | private: |
joeverbout | 0:ea44dc9ed014 | 148 | MotionModel model_; |
joeverbout | 0:ea44dc9ed014 | 149 | Size frameSize_; |
joeverbout | 0:ea44dc9ed014 | 150 | float trimRatio_; |
joeverbout | 0:ea44dc9ed014 | 151 | float w1_, w2_, w3_, w4_; |
joeverbout | 0:ea44dc9ed014 | 152 | |
joeverbout | 0:ea44dc9ed014 | 153 | std::vector<double> obj_, collb_, colub_; |
joeverbout | 0:ea44dc9ed014 | 154 | std::vector<int> rows_, cols_; |
joeverbout | 0:ea44dc9ed014 | 155 | std::vector<double> elems_, rowlb_, rowub_; |
joeverbout | 0:ea44dc9ed014 | 156 | |
joeverbout | 0:ea44dc9ed014 | 157 | void set(int row, int col, double coef) |
joeverbout | 0:ea44dc9ed014 | 158 | { |
joeverbout | 0:ea44dc9ed014 | 159 | rows_.push_back(row); |
joeverbout | 0:ea44dc9ed014 | 160 | cols_.push_back(col); |
joeverbout | 0:ea44dc9ed014 | 161 | elems_.push_back(coef); |
joeverbout | 0:ea44dc9ed014 | 162 | } |
joeverbout | 0:ea44dc9ed014 | 163 | }; |
joeverbout | 0:ea44dc9ed014 | 164 | |
joeverbout | 0:ea44dc9ed014 | 165 | CV_EXPORTS Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio); |
joeverbout | 0:ea44dc9ed014 | 166 | |
joeverbout | 0:ea44dc9ed014 | 167 | CV_EXPORTS float estimateOptimalTrimRatio(const Mat &M, Size size); |
joeverbout | 0:ea44dc9ed014 | 168 | |
joeverbout | 0:ea44dc9ed014 | 169 | //! @} |
joeverbout | 0:ea44dc9ed014 | 170 | |
joeverbout | 0:ea44dc9ed014 | 171 | } // namespace videostab |
joeverbout | 0:ea44dc9ed014 | 172 | } // namespace |
joeverbout | 0:ea44dc9ed014 | 173 | |
joeverbout | 0:ea44dc9ed014 | 174 | #endif |
joeverbout | 0:ea44dc9ed014 | 175 |