opencv on mbed

Dependencies:   mbed

Committer:
joeverbout
Date:
Thu Mar 31 21:16:38 2016 +0000
Revision:
0:ea44dc9ed014
OpenCV on mbed attempt

Who changed what in which revision?

UserRevisionLine numberNew 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_INPAINTINT_HPP__
joeverbout 0:ea44dc9ed014 44 #define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
joeverbout 0:ea44dc9ed014 45
joeverbout 0:ea44dc9ed014 46 #include <vector>
joeverbout 0:ea44dc9ed014 47 #include "opencv2/core.hpp"
joeverbout 0:ea44dc9ed014 48 #include "opencv2/videostab/optical_flow.hpp"
joeverbout 0:ea44dc9ed014 49 #include "opencv2/videostab/fast_marching.hpp"
joeverbout 0:ea44dc9ed014 50 #include "opencv2/videostab/global_motion.hpp"
joeverbout 0:ea44dc9ed014 51 #include "opencv2/photo.hpp"
joeverbout 0:ea44dc9ed014 52
joeverbout 0:ea44dc9ed014 53 namespace cv
joeverbout 0:ea44dc9ed014 54 {
joeverbout 0:ea44dc9ed014 55 namespace videostab
joeverbout 0:ea44dc9ed014 56 {
joeverbout 0:ea44dc9ed014 57
joeverbout 0:ea44dc9ed014 58 //! @addtogroup videostab
joeverbout 0:ea44dc9ed014 59 //! @{
joeverbout 0:ea44dc9ed014 60
joeverbout 0:ea44dc9ed014 61 class CV_EXPORTS InpainterBase
joeverbout 0:ea44dc9ed014 62 {
joeverbout 0:ea44dc9ed014 63 public:
joeverbout 0:ea44dc9ed014 64 InpainterBase()
joeverbout 0:ea44dc9ed014 65 : radius_(0), motionModel_(MM_UNKNOWN), frames_(0), motions_(0),
joeverbout 0:ea44dc9ed014 66 stabilizedFrames_(0), stabilizationMotions_(0) {}
joeverbout 0:ea44dc9ed014 67
joeverbout 0:ea44dc9ed014 68 virtual ~InpainterBase() {}
joeverbout 0:ea44dc9ed014 69
joeverbout 0:ea44dc9ed014 70 virtual void setRadius(int val) { radius_ = val; }
joeverbout 0:ea44dc9ed014 71 virtual int radius() const { return radius_; }
joeverbout 0:ea44dc9ed014 72
joeverbout 0:ea44dc9ed014 73 virtual void setMotionModel(MotionModel val) { motionModel_ = val; }
joeverbout 0:ea44dc9ed014 74 virtual MotionModel motionModel() const { return motionModel_; }
joeverbout 0:ea44dc9ed014 75
joeverbout 0:ea44dc9ed014 76 virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
joeverbout 0:ea44dc9ed014 77
joeverbout 0:ea44dc9ed014 78
joeverbout 0:ea44dc9ed014 79 // data from stabilizer
joeverbout 0:ea44dc9ed014 80
joeverbout 0:ea44dc9ed014 81 virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
joeverbout 0:ea44dc9ed014 82 virtual const std::vector<Mat>& frames() const { return *frames_; }
joeverbout 0:ea44dc9ed014 83
joeverbout 0:ea44dc9ed014 84 virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; }
joeverbout 0:ea44dc9ed014 85 virtual const std::vector<Mat>& motions() const { return *motions_; }
joeverbout 0:ea44dc9ed014 86
joeverbout 0:ea44dc9ed014 87 virtual void setStabilizedFrames(const std::vector<Mat> &val) { stabilizedFrames_ = &val; }
joeverbout 0:ea44dc9ed014 88 virtual const std::vector<Mat>& stabilizedFrames() const { return *stabilizedFrames_; }
joeverbout 0:ea44dc9ed014 89
joeverbout 0:ea44dc9ed014 90 virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
joeverbout 0:ea44dc9ed014 91 virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
joeverbout 0:ea44dc9ed014 92
joeverbout 0:ea44dc9ed014 93 protected:
joeverbout 0:ea44dc9ed014 94 int radius_;
joeverbout 0:ea44dc9ed014 95 MotionModel motionModel_;
joeverbout 0:ea44dc9ed014 96 const std::vector<Mat> *frames_;
joeverbout 0:ea44dc9ed014 97 const std::vector<Mat> *motions_;
joeverbout 0:ea44dc9ed014 98 const std::vector<Mat> *stabilizedFrames_;
joeverbout 0:ea44dc9ed014 99 const std::vector<Mat> *stabilizationMotions_;
joeverbout 0:ea44dc9ed014 100 };
joeverbout 0:ea44dc9ed014 101
joeverbout 0:ea44dc9ed014 102 class CV_EXPORTS NullInpainter : public InpainterBase
joeverbout 0:ea44dc9ed014 103 {
joeverbout 0:ea44dc9ed014 104 public:
joeverbout 0:ea44dc9ed014 105 virtual void inpaint(int /*idx*/, Mat &/*frame*/, Mat &/*mask*/) {}
joeverbout 0:ea44dc9ed014 106 };
joeverbout 0:ea44dc9ed014 107
joeverbout 0:ea44dc9ed014 108 class CV_EXPORTS InpaintingPipeline : public InpainterBase
joeverbout 0:ea44dc9ed014 109 {
joeverbout 0:ea44dc9ed014 110 public:
joeverbout 0:ea44dc9ed014 111 void pushBack(Ptr<InpainterBase> inpainter) { inpainters_.push_back(inpainter); }
joeverbout 0:ea44dc9ed014 112 bool empty() const { return inpainters_.empty(); }
joeverbout 0:ea44dc9ed014 113
joeverbout 0:ea44dc9ed014 114 virtual void setRadius(int val);
joeverbout 0:ea44dc9ed014 115 virtual void setMotionModel(MotionModel val);
joeverbout 0:ea44dc9ed014 116 virtual void setFrames(const std::vector<Mat> &val);
joeverbout 0:ea44dc9ed014 117 virtual void setMotions(const std::vector<Mat> &val);
joeverbout 0:ea44dc9ed014 118 virtual void setStabilizedFrames(const std::vector<Mat> &val);
joeverbout 0:ea44dc9ed014 119 virtual void setStabilizationMotions(const std::vector<Mat> &val);
joeverbout 0:ea44dc9ed014 120
joeverbout 0:ea44dc9ed014 121 virtual void inpaint(int idx, Mat &frame, Mat &mask);
joeverbout 0:ea44dc9ed014 122
joeverbout 0:ea44dc9ed014 123 private:
joeverbout 0:ea44dc9ed014 124 std::vector<Ptr<InpainterBase> > inpainters_;
joeverbout 0:ea44dc9ed014 125 };
joeverbout 0:ea44dc9ed014 126
joeverbout 0:ea44dc9ed014 127 class CV_EXPORTS ConsistentMosaicInpainter : public InpainterBase
joeverbout 0:ea44dc9ed014 128 {
joeverbout 0:ea44dc9ed014 129 public:
joeverbout 0:ea44dc9ed014 130 ConsistentMosaicInpainter();
joeverbout 0:ea44dc9ed014 131
joeverbout 0:ea44dc9ed014 132 void setStdevThresh(float val) { stdevThresh_ = val; }
joeverbout 0:ea44dc9ed014 133 float stdevThresh() const { return stdevThresh_; }
joeverbout 0:ea44dc9ed014 134
joeverbout 0:ea44dc9ed014 135 virtual void inpaint(int idx, Mat &frame, Mat &mask);
joeverbout 0:ea44dc9ed014 136
joeverbout 0:ea44dc9ed014 137 private:
joeverbout 0:ea44dc9ed014 138 float stdevThresh_;
joeverbout 0:ea44dc9ed014 139 };
joeverbout 0:ea44dc9ed014 140
joeverbout 0:ea44dc9ed014 141 class CV_EXPORTS MotionInpainter : public InpainterBase
joeverbout 0:ea44dc9ed014 142 {
joeverbout 0:ea44dc9ed014 143 public:
joeverbout 0:ea44dc9ed014 144 MotionInpainter();
joeverbout 0:ea44dc9ed014 145
joeverbout 0:ea44dc9ed014 146 void setOptFlowEstimator(Ptr<IDenseOptFlowEstimator> val) { optFlowEstimator_ = val; }
joeverbout 0:ea44dc9ed014 147 Ptr<IDenseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
joeverbout 0:ea44dc9ed014 148
joeverbout 0:ea44dc9ed014 149 void setFlowErrorThreshold(float val) { flowErrorThreshold_ = val; }
joeverbout 0:ea44dc9ed014 150 float flowErrorThreshold() const { return flowErrorThreshold_; }
joeverbout 0:ea44dc9ed014 151
joeverbout 0:ea44dc9ed014 152 void setDistThreshold(float val) { distThresh_ = val; }
joeverbout 0:ea44dc9ed014 153 float distThresh() const { return distThresh_; }
joeverbout 0:ea44dc9ed014 154
joeverbout 0:ea44dc9ed014 155 void setBorderMode(int val) { borderMode_ = val; }
joeverbout 0:ea44dc9ed014 156 int borderMode() const { return borderMode_; }
joeverbout 0:ea44dc9ed014 157
joeverbout 0:ea44dc9ed014 158 virtual void inpaint(int idx, Mat &frame, Mat &mask);
joeverbout 0:ea44dc9ed014 159
joeverbout 0:ea44dc9ed014 160 private:
joeverbout 0:ea44dc9ed014 161 FastMarchingMethod fmm_;
joeverbout 0:ea44dc9ed014 162 Ptr<IDenseOptFlowEstimator> optFlowEstimator_;
joeverbout 0:ea44dc9ed014 163 float flowErrorThreshold_;
joeverbout 0:ea44dc9ed014 164 float distThresh_;
joeverbout 0:ea44dc9ed014 165 int borderMode_;
joeverbout 0:ea44dc9ed014 166
joeverbout 0:ea44dc9ed014 167 Mat frame1_, transformedFrame1_;
joeverbout 0:ea44dc9ed014 168 Mat_<uchar> grayFrame_, transformedGrayFrame1_;
joeverbout 0:ea44dc9ed014 169 Mat_<uchar> mask1_, transformedMask1_;
joeverbout 0:ea44dc9ed014 170 Mat_<float> flowX_, flowY_, flowErrors_;
joeverbout 0:ea44dc9ed014 171 Mat_<uchar> flowMask_;
joeverbout 0:ea44dc9ed014 172 };
joeverbout 0:ea44dc9ed014 173
joeverbout 0:ea44dc9ed014 174 class CV_EXPORTS ColorAverageInpainter : public InpainterBase
joeverbout 0:ea44dc9ed014 175 {
joeverbout 0:ea44dc9ed014 176 public:
joeverbout 0:ea44dc9ed014 177 virtual void inpaint(int idx, Mat &frame, Mat &mask);
joeverbout 0:ea44dc9ed014 178
joeverbout 0:ea44dc9ed014 179 private:
joeverbout 0:ea44dc9ed014 180 FastMarchingMethod fmm_;
joeverbout 0:ea44dc9ed014 181 };
joeverbout 0:ea44dc9ed014 182
joeverbout 0:ea44dc9ed014 183 class CV_EXPORTS ColorInpainter : public InpainterBase
joeverbout 0:ea44dc9ed014 184 {
joeverbout 0:ea44dc9ed014 185 public:
joeverbout 0:ea44dc9ed014 186 ColorInpainter(int method = INPAINT_TELEA, double radius = 2.);
joeverbout 0:ea44dc9ed014 187
joeverbout 0:ea44dc9ed014 188 virtual void inpaint(int idx, Mat &frame, Mat &mask);
joeverbout 0:ea44dc9ed014 189
joeverbout 0:ea44dc9ed014 190 private:
joeverbout 0:ea44dc9ed014 191 int method_;
joeverbout 0:ea44dc9ed014 192 double radius_;
joeverbout 0:ea44dc9ed014 193 Mat invMask_;
joeverbout 0:ea44dc9ed014 194 };
joeverbout 0:ea44dc9ed014 195
joeverbout 0:ea44dc9ed014 196 inline ColorInpainter::ColorInpainter(int _method, double _radius)
joeverbout 0:ea44dc9ed014 197 : method_(_method), radius_(_radius) {}
joeverbout 0:ea44dc9ed014 198
joeverbout 0:ea44dc9ed014 199 CV_EXPORTS void calcFlowMask(
joeverbout 0:ea44dc9ed014 200 const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError,
joeverbout 0:ea44dc9ed014 201 const Mat &mask0, const Mat &mask1, Mat &flowMask);
joeverbout 0:ea44dc9ed014 202
joeverbout 0:ea44dc9ed014 203 CV_EXPORTS void completeFrameAccordingToFlow(
joeverbout 0:ea44dc9ed014 204 const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
joeverbout 0:ea44dc9ed014 205 float distThresh, Mat& frame0, Mat &mask0);
joeverbout 0:ea44dc9ed014 206
joeverbout 0:ea44dc9ed014 207 //! @}
joeverbout 0:ea44dc9ed014 208
joeverbout 0:ea44dc9ed014 209 } // namespace videostab
joeverbout 0:ea44dc9ed014 210 } // namespace cv
joeverbout 0:ea44dc9ed014 211
joeverbout 0:ea44dc9ed014 212 #endif
joeverbout 0:ea44dc9ed014 213