Renesas / opencv-lib

Dependents:   RZ_A2M_Mbed_samples

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers motion_stabilizing.hpp Source File

motion_stabilizing.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_MOTION_STABILIZING_HPP
00044 #define OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP
00045 
00046 #include <vector>
00047 #include <utility>
00048 #include "opencv2/core.hpp"
00049 #include "opencv2/videostab/global_motion.hpp"
00050 
00051 namespace cv
00052 {
00053 namespace videostab
00054 {
00055 
00056 //! @addtogroup videostab_motion
00057 //! @{
00058 
00059 class CV_EXPORTS IMotionStabilizer
00060 {
00061 public:
00062     virtual ~IMotionStabilizer() {}
00063 
00064     //! assumes that [0, size-1) is in or equals to [range.first, range.second)
00065     virtual void stabilize(
00066             int size, const std::vector<Mat> &motions, std::pair<int,int> range,
00067             Mat *stabilizationMotions) = 0;
00068 };
00069 
00070 class CV_EXPORTS MotionStabilizationPipeline : public IMotionStabilizer
00071 {
00072 public:
00073     void pushBack(Ptr<IMotionStabilizer> stabilizer) { stabilizers_.push_back(stabilizer); }
00074     bool empty() const { return stabilizers_.empty(); }
00075 
00076     virtual void stabilize(
00077             int size, const std::vector<Mat> &motions, std::pair<int,int> range,
00078             Mat *stabilizationMotions);
00079 
00080 private:
00081     std::vector<Ptr<IMotionStabilizer> > stabilizers_;
00082 };
00083 
00084 class CV_EXPORTS MotionFilterBase : public IMotionStabilizer
00085 {
00086 public:
00087     virtual ~MotionFilterBase() {}
00088 
00089     virtual Mat stabilize(
00090             int idx, const std::vector<Mat> &motions, std::pair<int,int> range) = 0;
00091 
00092     virtual void stabilize(
00093             int size, const std::vector<Mat> &motions, std::pair<int,int> range,
00094             Mat *stabilizationMotions);
00095 };
00096 
00097 class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase
00098 {
00099 public:
00100     GaussianMotionFilter(int radius = 15, float stdev = -1.f);
00101 
00102     void setParams(int radius, float stdev = -1.f);
00103     int radius() const { return radius_; }
00104     float stdev() const { return stdev_; }
00105 
00106     virtual Mat stabilize(
00107             int idx, const std::vector<Mat> &motions, std::pair<int,int> range);
00108 
00109 private:
00110     int radius_;
00111     float stdev_;
00112     std::vector<float> weight_;
00113 };
00114 
00115 inline GaussianMotionFilter::GaussianMotionFilter(int _radius, float _stdev) { setParams(_radius, _stdev); }
00116 
00117 class CV_EXPORTS LpMotionStabilizer : public IMotionStabilizer
00118 {
00119 public:
00120     LpMotionStabilizer(MotionModel model = MM_SIMILARITY);
00121 
00122     void setMotionModel(MotionModel val) { model_ = val; }
00123     MotionModel motionModel() const { return model_; }
00124 
00125     void setFrameSize(Size val) { frameSize_ = val; }
00126     Size frameSize() const { return frameSize_; }
00127 
00128     void setTrimRatio(float val) { trimRatio_ = val; }
00129     float trimRatio() const { return trimRatio_; }
00130 
00131     void setWeight1(float val) { w1_ = val; }
00132     float weight1() const { return w1_; }
00133 
00134     void setWeight2(float val) { w2_ = val; }
00135     float weight2() const { return w2_; }
00136 
00137     void setWeight3(float val) { w3_ = val; }
00138     float weight3() const { return w3_; }
00139 
00140     void setWeight4(float val) { w4_ = val; }
00141     float weight4() const { return w4_; }
00142 
00143     virtual void stabilize(
00144             int size, const std::vector<Mat> &motions, std::pair<int,int> range,
00145             Mat *stabilizationMotions);
00146 
00147 private:
00148     MotionModel model_;
00149     Size frameSize_;
00150     float trimRatio_;
00151     float w1_, w2_, w3_, w4_;
00152 
00153     std::vector<double> obj_, collb_, colub_;
00154     std::vector<int> rows_, cols_;
00155     std::vector<double> elems_, rowlb_, rowub_;
00156 
00157     void set(int row, int col, double coef)
00158     {
00159         rows_.push_back(row);
00160         cols_.push_back(col);
00161         elems_.push_back(coef);
00162     }
00163 };
00164 
00165 CV_EXPORTS Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio);
00166 
00167 CV_EXPORTS float estimateOptimalTrimRatio(const Mat &M, Size size);
00168 
00169 //! @}
00170 
00171 } // namespace videostab
00172 } // namespace
00173 
00174 #endif