openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

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?

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