1
/*M///////////////////////////////////////////////////////////////////////////////////////
3
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5
// By downloading, copying, installing or using the software you agree to this license.
6
// If you do not agree to this license, do not download, install,
7
// copy or use the software.
11
// For Open Source Computer Vision Library
13
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
15
// Third party copyrights are property of their respective owners.
17
// Redistribution and use in source and binary forms, with or without modification,
18
// are permitted provided that the following conditions are met:
20
// * Redistribution's of source code must retain the above copyright notice,
21
// this list of conditions and the following disclaimer.
23
// * Redistribution's in binary form must reproduce the above copyright notice,
24
// this list of conditions and the following disclaimer in the documentation
25
// and/or other materials provided with the distribution.
27
// * The name of the copyright holders may not be used to endorse or promote products
28
// derived from this software without specific prior written permission.
30
// This software is provided by the copyright holders and contributors "as is" and
31
// any express or implied warranties, including, but not limited to, the implied
32
// warranties of merchantability and fitness for a particular purpose are disclaimed.
33
// In no event shall the Intel Corporation or contributors be liable for any direct,
34
// indirect, incidental, special, exemplary, or consequential damages
35
// (including, but not limited to, procurement of substitute goods or services;
36
// loss of use, data, or profits; or business interruption) however caused
37
// and on any theory of liability, whether in contract, strict liability,
38
// or tort (including negligence or otherwise) arising in any way out of
39
// the use of this software, even if advised of the possibility of such damage.
43
#ifndef __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__
44
#define __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__
48
#include "opencv2/core.hpp"
49
#include "opencv2/videostab/global_motion.hpp"
56
//! @addtogroup videostab_motion
59
class CV_EXPORTS IMotionStabilizer
62
virtual ~IMotionStabilizer() {}
64
//! assumes that [0, size-1) is in or equals to [range.first, range.second)
65
virtual void stabilize(
66
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
67
Mat *stabilizationMotions) = 0;
70
class CV_EXPORTS MotionStabilizationPipeline : public IMotionStabilizer
73
void pushBack(Ptr<IMotionStabilizer> stabilizer) { stabilizers_.push_back(stabilizer); }
74
bool empty() const { return stabilizers_.empty(); }
76
virtual void stabilize(
77
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
78
Mat *stabilizationMotions);
81
std::vector<Ptr<IMotionStabilizer> > stabilizers_;
84
class CV_EXPORTS MotionFilterBase : public IMotionStabilizer
87
virtual ~MotionFilterBase() {}
89
virtual Mat stabilize(
90
int idx, const std::vector<Mat> &motions, std::pair<int,int> range) = 0;
92
virtual void stabilize(
93
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
94
Mat *stabilizationMotions);
97
class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase
100
GaussianMotionFilter(int radius = 15, float stdev = -1.f);
102
void setParams(int radius, float stdev = -1.f);
103
int radius() const { return radius_; }
104
float stdev() const { return stdev_; }
106
virtual Mat stabilize(
107
int idx, const std::vector<Mat> &motions, std::pair<int,int> range);
112
std::vector<float> weight_;
115
inline GaussianMotionFilter::GaussianMotionFilter(int _radius, float _stdev) { setParams(_radius, _stdev); }
117
class CV_EXPORTS LpMotionStabilizer : public IMotionStabilizer
120
LpMotionStabilizer(MotionModel model = MM_SIMILARITY);
122
void setMotionModel(MotionModel val) { model_ = val; }
123
MotionModel motionModel() const { return model_; }
125
void setFrameSize(Size val) { frameSize_ = val; }
126
Size frameSize() const { return frameSize_; }
128
void setTrimRatio(float val) { trimRatio_ = val; }
129
float trimRatio() const { return trimRatio_; }
131
void setWeight1(float val) { w1_ = val; }
132
float weight1() const { return w1_; }
134
void setWeight2(float val) { w2_ = val; }
135
float weight2() const { return w2_; }
137
void setWeight3(float val) { w3_ = val; }
138
float weight3() const { return w3_; }
140
void setWeight4(float val) { w4_ = val; }
141
float weight4() const { return w4_; }
143
virtual void stabilize(
144
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
145
Mat *stabilizationMotions);
151
float w1_, w2_, w3_, w4_;
153
std::vector<double> obj_, collb_, colub_;
154
std::vector<int> rows_, cols_;
155
std::vector<double> elems_, rowlb_, rowub_;
157
void set(int row, int col, double coef)
159
rows_.push_back(row);
160
cols_.push_back(col);
161
elems_.push_back(coef);
165
CV_EXPORTS Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio);
167
CV_EXPORTS float estimateOptimalTrimRatio(const Mat &M, Size size);
171
} // namespace videostab