mirror of
https://github.com/storytold/LiveScan3D.git
synced 2026-10-17 00:23:00 +00:00
Moved to Visual Studio 2015, OpenCV 3.2.0, x64
This commit is contained in:
@@ -40,29 +40,37 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_DEBLURRING_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_DEBLURRING_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_DEBLURRING_HPP
|
||||
#define OPENCV_VIDEOSTAB_DEBLURRING_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
CV_EXPORTS float calcBlurriness(const Mat &frame);
|
||||
|
||||
class CV_EXPORTS DeblurerBase
|
||||
{
|
||||
public:
|
||||
DeblurerBase() : radius_(0), frames_(0), motions_(0) {}
|
||||
DeblurerBase() : radius_(0), frames_(0), motions_(0), blurrinessRates_(0) {}
|
||||
|
||||
virtual ~DeblurerBase() {}
|
||||
|
||||
virtual void setRadius(int val) { radius_ = val; }
|
||||
virtual int radius() const { return radius_; }
|
||||
|
||||
virtual void deblur(int idx, Mat &frame) = 0;
|
||||
|
||||
|
||||
// data from stabilizer
|
||||
|
||||
virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
|
||||
virtual const std::vector<Mat>& frames() const { return *frames_; }
|
||||
|
||||
@@ -72,10 +80,6 @@ public:
|
||||
virtual void setBlurrinessRates(const std::vector<float> &val) { blurrinessRates_ = &val; }
|
||||
virtual const std::vector<float>& blurrinessRates() const { return *blurrinessRates_; }
|
||||
|
||||
virtual void update() {}
|
||||
|
||||
virtual void deblur(int idx, Mat &frame) = 0;
|
||||
|
||||
protected:
|
||||
int radius_;
|
||||
const std::vector<Mat> *frames_;
|
||||
@@ -104,6 +108,8 @@ private:
|
||||
Mat_<float> bSum_, gSum_, rSum_, wSum_;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -40,28 +40,44 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_FAST_MARCHING_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_FAST_MARCHING_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_FAST_MARCHING_HPP
|
||||
#define OPENCV_VIDEOSTAB_FAST_MARCHING_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include <queue>
|
||||
#include <algorithm>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
// See http://iwi.eldoc.ub.rug.nl/FILES/root/2004/JGraphToolsTelea/2004JGraphToolsTelea.pdf
|
||||
//! @addtogroup videostab_marching
|
||||
//! @{
|
||||
|
||||
/** @brief Describes the Fast Marching Method implementation.
|
||||
|
||||
See http://iwi.eldoc.ub.rug.nl/FILES/root/2004/JGraphToolsTelea/2004JGraphToolsTelea.pdf
|
||||
*/
|
||||
class CV_EXPORTS FastMarchingMethod
|
||||
{
|
||||
public:
|
||||
FastMarchingMethod() : inf_(1e6f) {}
|
||||
|
||||
/** @brief Template method that runs the Fast Marching Method.
|
||||
|
||||
@param mask Image mask. 0 value indicates that the pixel value must be inpainted, 255 indicates
|
||||
that the pixel value is known, other values aren't acceptable.
|
||||
@param inpaint Inpainting functor that overloads void operator ()(int x, int y).
|
||||
@return Inpainting functor.
|
||||
*/
|
||||
template <typename Inpaint>
|
||||
Inpaint run(const Mat &mask, Inpaint inpaint);
|
||||
|
||||
/**
|
||||
@return Distance map that's created during working of the method.
|
||||
*/
|
||||
Mat distanceMap() const { return dist_; }
|
||||
|
||||
private:
|
||||
@@ -95,6 +111,8 @@ private:
|
||||
int size_; // narrow band size
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP
|
||||
#define OPENCV_VIDEOSTAB_FAST_MARCHING_INL_HPP
|
||||
|
||||
#include "opencv2/videostab/fast_marching.hpp"
|
||||
|
||||
@@ -53,7 +53,6 @@ namespace videostab
|
||||
template <typename Inpaint>
|
||||
Inpaint FastMarchingMethod::run(const cv::Mat &mask, Inpaint inpaint)
|
||||
{
|
||||
using namespace std;
|
||||
using namespace cv;
|
||||
|
||||
CV_Assert(mask.type() == CV_8U);
|
||||
@@ -129,8 +128,8 @@ Inpaint FastMarchingMethod::run(const cv::Mat &mask, Inpaint inpaint)
|
||||
|
||||
if (xn >= 0 && xn < flag_.cols && yn >= 0 && yn < flag_.rows && flag_(yn,xn) != KNOWN)
|
||||
{
|
||||
dist_(yn,xn) = min(min(solve(xn-1, yn, xn, yn-1), solve(xn+1, yn, xn, yn-1)),
|
||||
min(solve(xn-1, yn, xn, yn+1), solve(xn+1, yn, xn, yn+1)));
|
||||
dist_(yn,xn) = std::min(std::min(solve(xn-1, yn, xn, yn-1), solve(xn+1, yn, xn, yn-1)),
|
||||
std::min(solve(xn-1, yn, xn, yn+1), solve(xn+1, yn, xn, yn+1)));
|
||||
|
||||
if (flag_(yn,xn) == INSIDE)
|
||||
{
|
||||
|
||||
@@ -40,19 +40,20 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP
|
||||
#define OPENCV_VIDEOSTAB_FRAME_SOURCE_HPP
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/highgui/highgui.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS IFrameSource
|
||||
{
|
||||
public:
|
||||
@@ -71,20 +72,22 @@ public:
|
||||
class CV_EXPORTS VideoFileSource : public IFrameSource
|
||||
{
|
||||
public:
|
||||
VideoFileSource(const std::string &path, bool volatileFrame = false);
|
||||
VideoFileSource(const String &path, bool volatileFrame = false);
|
||||
|
||||
virtual void reset();
|
||||
virtual Mat nextFrame();
|
||||
|
||||
int frameCount() { return static_cast<int>(reader_.get(CV_CAP_PROP_FRAME_COUNT)); }
|
||||
double fps() { return reader_.get(CV_CAP_PROP_FPS); }
|
||||
int width();
|
||||
int height();
|
||||
int count();
|
||||
double fps();
|
||||
|
||||
private:
|
||||
std::string path_;
|
||||
bool volatileFrame_;
|
||||
VideoCapture reader_;
|
||||
Ptr<IFrameSource> impl;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -40,101 +40,259 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP
|
||||
#define OPENCV_VIDEOSTAB_GLOBAL_MOTION_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/features2d/features2d.hpp"
|
||||
#include <fstream>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/features2d.hpp"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
#include "opencv2/videostab/optical_flow.hpp"
|
||||
#include "opencv2/videostab/motion_core.hpp"
|
||||
#include "opencv2/videostab/outlier_rejection.hpp"
|
||||
|
||||
#ifdef HAVE_OPENCV_CUDAIMGPROC
|
||||
# include "opencv2/cudaimgproc.hpp"
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
enum MotionModel
|
||||
{
|
||||
TRANSLATION = 0,
|
||||
TRANSLATION_AND_SCALE = 1,
|
||||
LINEAR_SIMILARITY = 2,
|
||||
AFFINE = 3
|
||||
};
|
||||
//! @addtogroup videostab_motion
|
||||
//! @{
|
||||
|
||||
/** @brief Estimates best global motion between two 2D point clouds in the least-squares sense.
|
||||
|
||||
@note Works in-place and changes input point arrays.
|
||||
|
||||
@param points0 Source set of 2D points (32F).
|
||||
@param points1 Destination set of 2D points (32F).
|
||||
@param model Motion model (up to MM_AFFINE).
|
||||
@param rmse Final root-mean-square error.
|
||||
@return 3x3 2D transformation matrix (32F).
|
||||
*/
|
||||
CV_EXPORTS Mat estimateGlobalMotionLeastSquares(
|
||||
const std::vector<Point2f> &points0, const std::vector<Point2f> &points1,
|
||||
int model = AFFINE, float *rmse = 0);
|
||||
InputOutputArray points0, InputOutputArray points1, int model = MM_AFFINE,
|
||||
float *rmse = 0);
|
||||
|
||||
struct CV_EXPORTS RansacParams
|
||||
{
|
||||
int size; // subset size
|
||||
float thresh; // max error to classify as inlier
|
||||
float eps; // max outliers ratio
|
||||
float prob; // probability of success
|
||||
/** @brief Estimates best global motion between two 2D point clouds robustly (using RANSAC method).
|
||||
|
||||
RansacParams(int _size, float _thresh, float _eps, float _prob)
|
||||
: size(_size), thresh(_thresh), eps(_eps), prob(_prob) {}
|
||||
|
||||
static RansacParams translationMotionStd() { return RansacParams(2, 0.5f, 0.5f, 0.99f); }
|
||||
static RansacParams translationAndScale2dMotionStd() { return RansacParams(3, 0.5f, 0.5f, 0.99f); }
|
||||
static RansacParams linearSimilarityMotionStd() { return RansacParams(4, 0.5f, 0.5f, 0.99f); }
|
||||
static RansacParams affine2dMotionStd() { return RansacParams(6, 0.5f, 0.5f, 0.99f); }
|
||||
};
|
||||
|
||||
CV_EXPORTS Mat estimateGlobalMotionRobust(
|
||||
const std::vector<Point2f> &points0, const std::vector<Point2f> &points1,
|
||||
int model = AFFINE, const RansacParams ¶ms = RansacParams::affine2dMotionStd(),
|
||||
@param points0 Source set of 2D points (32F).
|
||||
@param points1 Destination set of 2D points (32F).
|
||||
@param model Motion model. See cv::videostab::MotionModel.
|
||||
@param params RANSAC method parameters. See videostab::RansacParams.
|
||||
@param rmse Final root-mean-square error.
|
||||
@param ninliers Final number of inliers.
|
||||
*/
|
||||
CV_EXPORTS Mat estimateGlobalMotionRansac(
|
||||
InputArray points0, InputArray points1, int model = MM_AFFINE,
|
||||
const RansacParams ¶ms = RansacParams::default2dMotion(MM_AFFINE),
|
||||
float *rmse = 0, int *ninliers = 0);
|
||||
|
||||
class CV_EXPORTS IGlobalMotionEstimator
|
||||
/** @brief Base class for all global motion estimation methods.
|
||||
*/
|
||||
class CV_EXPORTS MotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
virtual ~IGlobalMotionEstimator() {}
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1) = 0;
|
||||
virtual ~MotionEstimatorBase() {}
|
||||
|
||||
/** @brief Sets motion model.
|
||||
|
||||
@param val Motion model. See cv::videostab::MotionModel.
|
||||
*/
|
||||
virtual void setMotionModel(MotionModel val) { motionModel_ = val; }
|
||||
|
||||
/**
|
||||
@return Motion model. See cv::videostab::MotionModel.
|
||||
*/
|
||||
virtual MotionModel motionModel() const { return motionModel_; }
|
||||
|
||||
/** @brief Estimates global motion between two 2D point clouds.
|
||||
|
||||
@param points0 Source set of 2D points (32F).
|
||||
@param points1 Destination set of 2D points (32F).
|
||||
@param ok Indicates whether motion was estimated successfully.
|
||||
@return 3x3 2D transformation matrix (32F).
|
||||
*/
|
||||
virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0) = 0;
|
||||
|
||||
protected:
|
||||
MotionEstimatorBase(MotionModel model) { setMotionModel(model); }
|
||||
|
||||
private:
|
||||
MotionModel motionModel_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS PyrLkRobustMotionEstimator : public IGlobalMotionEstimator
|
||||
/** @brief Describes a robust RANSAC-based global 2D motion estimation method which minimizes L2 error.
|
||||
*/
|
||||
class CV_EXPORTS MotionEstimatorRansacL2 : public MotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
PyrLkRobustMotionEstimator();
|
||||
|
||||
void setDetector(Ptr<FeatureDetector> val) { detector_ = val; }
|
||||
Ptr<FeatureDetector> detector() const { return detector_; }
|
||||
|
||||
void setOptFlowEstimator(Ptr<ISparseOptFlowEstimator> val) { optFlowEstimator_ = val; }
|
||||
Ptr<ISparseOptFlowEstimator> optFlowEstimator() const { return optFlowEstimator_; }
|
||||
|
||||
void setMotionModel(MotionModel val) { motionModel_ = val; }
|
||||
MotionModel motionModel() const { return motionModel_; }
|
||||
MotionEstimatorRansacL2(MotionModel model = MM_AFFINE);
|
||||
|
||||
void setRansacParams(const RansacParams &val) { ransacParams_ = val; }
|
||||
RansacParams ransacParams() const { return ransacParams_; }
|
||||
|
||||
void setMaxRmse(float val) { maxRmse_ = val; }
|
||||
float maxRmse() const { return maxRmse_; }
|
||||
|
||||
void setMinInlierRatio(float val) { minInlierRatio_ = val; }
|
||||
float minInlierRatio() const { return minInlierRatio_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1);
|
||||
virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
RansacParams ransacParams_;
|
||||
float minInlierRatio_;
|
||||
};
|
||||
|
||||
/** @brief Describes a global 2D motion estimation method which minimizes L1 error.
|
||||
|
||||
@note To be able to use this method you must build OpenCV with CLP library support. :
|
||||
*/
|
||||
class CV_EXPORTS MotionEstimatorL1 : public MotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
MotionEstimatorL1(MotionModel model = MM_AFFINE);
|
||||
|
||||
virtual Mat estimate(InputArray points0, InputArray points1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
std::vector<double> obj_, collb_, colub_;
|
||||
std::vector<double> elems_, rowlb_, rowub_;
|
||||
std::vector<int> rows_, cols_;
|
||||
|
||||
void set(int row, int col, double coef)
|
||||
{
|
||||
rows_.push_back(row);
|
||||
cols_.push_back(col);
|
||||
elems_.push_back(coef);
|
||||
}
|
||||
};
|
||||
|
||||
/** @brief Base class for global 2D motion estimation methods which take frames as input.
|
||||
*/
|
||||
class CV_EXPORTS ImageMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
virtual ~ImageMotionEstimatorBase() {}
|
||||
|
||||
virtual void setMotionModel(MotionModel val) { motionModel_ = val; }
|
||||
virtual MotionModel motionModel() const { return motionModel_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) = 0;
|
||||
|
||||
protected:
|
||||
ImageMotionEstimatorBase(MotionModel model) { setMotionModel(model); }
|
||||
|
||||
private:
|
||||
MotionModel motionModel_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS FromFileMotionReader : public ImageMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
FromFileMotionReader(const String &path);
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
std::ifstream file_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS ToFileMotionWriter : public ImageMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
ToFileMotionWriter(const String &path, Ptr<ImageMotionEstimatorBase> estimator);
|
||||
|
||||
virtual void setMotionModel(MotionModel val) { motionEstimator_->setMotionModel(val); }
|
||||
virtual MotionModel motionModel() const { return motionEstimator_->motionModel(); }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
std::ofstream file_;
|
||||
Ptr<ImageMotionEstimatorBase> motionEstimator_;
|
||||
};
|
||||
|
||||
/** @brief Describes a global 2D motion estimation method which uses keypoints detection and optical flow for
|
||||
matching.
|
||||
*/
|
||||
class CV_EXPORTS KeypointBasedMotionEstimator : public ImageMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
KeypointBasedMotionEstimator(Ptr<MotionEstimatorBase> estimator);
|
||||
|
||||
virtual void setMotionModel(MotionModel val) { motionEstimator_->setMotionModel(val); }
|
||||
virtual MotionModel motionModel() const { return motionEstimator_->motionModel(); }
|
||||
|
||||
void setDetector(Ptr<FeatureDetector> val) { detector_ = val; }
|
||||
Ptr<FeatureDetector> detector() const { return detector_; }
|
||||
|
||||
void setOpticalFlowEstimator(Ptr<ISparseOptFlowEstimator> val) { optFlowEstimator_ = val; }
|
||||
Ptr<ISparseOptFlowEstimator> opticalFlowEstimator() const { return optFlowEstimator_; }
|
||||
|
||||
void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; }
|
||||
Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
Ptr<MotionEstimatorBase> motionEstimator_;
|
||||
Ptr<FeatureDetector> detector_;
|
||||
Ptr<ISparseOptFlowEstimator> optFlowEstimator_;
|
||||
MotionModel motionModel_;
|
||||
RansacParams ransacParams_;
|
||||
Ptr<IOutlierRejector> outlierRejector_;
|
||||
|
||||
std::vector<uchar> status_;
|
||||
std::vector<KeyPoint> keypointsPrev_;
|
||||
std::vector<Point2f> pointsPrev_, points_;
|
||||
std::vector<Point2f> pointsPrevGood_, pointsGood_;
|
||||
float maxRmse_;
|
||||
float minInlierRatio_;
|
||||
};
|
||||
|
||||
CV_EXPORTS Mat getMotion(int from, int to, const Mat *motions, int size);
|
||||
#if defined(HAVE_OPENCV_CUDAIMGPROC) && defined(HAVE_OPENCV_CUDAOPTFLOW)
|
||||
|
||||
class CV_EXPORTS KeypointBasedMotionEstimatorGpu : public ImageMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
KeypointBasedMotionEstimatorGpu(Ptr<MotionEstimatorBase> estimator);
|
||||
|
||||
virtual void setMotionModel(MotionModel val) { motionEstimator_->setMotionModel(val); }
|
||||
virtual MotionModel motionModel() const { return motionEstimator_->motionModel(); }
|
||||
|
||||
void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; }
|
||||
Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
Mat estimate(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
Ptr<MotionEstimatorBase> motionEstimator_;
|
||||
Ptr<cuda::CornersDetector> detector_;
|
||||
SparsePyrLkOptFlowEstimatorGpu optFlowEstimator_;
|
||||
Ptr<IOutlierRejector> outlierRejector_;
|
||||
|
||||
cuda::GpuMat frame0_, grayFrame0_, frame1_;
|
||||
cuda::GpuMat pointsPrev_, points_;
|
||||
cuda::GpuMat status_;
|
||||
|
||||
Mat hostPointsPrev_, hostPoints_;
|
||||
std::vector<Point2f> hostPointsPrevTmp_, hostPointsTmp_;
|
||||
std::vector<uchar> rejectionStatus_;
|
||||
};
|
||||
|
||||
#endif // defined(HAVE_OPENCV_CUDAIMGPROC) && defined(HAVE_OPENCV_CUDAOPTFLOW)
|
||||
|
||||
/** @brief Computes motion between two frames assuming that all the intermediate motions are known.
|
||||
|
||||
@param from Source frame index.
|
||||
@param to Destination frame index.
|
||||
@param motions Pair-wise motions. motions[i] denotes motion from the frame i to the frame i+1
|
||||
@return Motion from the frame from to the frame to.
|
||||
*/
|
||||
CV_EXPORTS Mat getMotion(int from, int to, const std::vector<Mat> &motions);
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -40,25 +40,29 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_INPAINTINT_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_INPAINTINT_HPP
|
||||
#define OPENCV_VIDEOSTAB_INPAINTINT_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/videostab/optical_flow.hpp"
|
||||
#include "opencv2/videostab/fast_marching.hpp"
|
||||
#include "opencv2/photo/photo.hpp"
|
||||
#include "opencv2/videostab/global_motion.hpp"
|
||||
#include "opencv2/photo.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS InpainterBase
|
||||
{
|
||||
public:
|
||||
InpainterBase()
|
||||
: radius_(0), frames_(0), motions_(0),
|
||||
: radius_(0), motionModel_(MM_UNKNOWN), frames_(0), motions_(0),
|
||||
stabilizedFrames_(0), stabilizationMotions_(0) {}
|
||||
|
||||
virtual ~InpainterBase() {}
|
||||
@@ -66,6 +70,14 @@ public:
|
||||
virtual void setRadius(int val) { radius_ = val; }
|
||||
virtual int radius() const { return radius_; }
|
||||
|
||||
virtual void setMotionModel(MotionModel val) { motionModel_ = val; }
|
||||
virtual MotionModel motionModel() const { return motionModel_; }
|
||||
|
||||
virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
|
||||
|
||||
|
||||
// data from stabilizer
|
||||
|
||||
virtual void setFrames(const std::vector<Mat> &val) { frames_ = &val; }
|
||||
virtual const std::vector<Mat>& frames() const { return *frames_; }
|
||||
|
||||
@@ -78,12 +90,9 @@ public:
|
||||
virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
|
||||
virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
|
||||
|
||||
virtual void update() {}
|
||||
|
||||
virtual void inpaint(int idx, Mat &frame, Mat &mask) = 0;
|
||||
|
||||
protected:
|
||||
int radius_;
|
||||
MotionModel motionModel_;
|
||||
const std::vector<Mat> *frames_;
|
||||
const std::vector<Mat> *motions_;
|
||||
const std::vector<Mat> *stabilizedFrames_;
|
||||
@@ -103,13 +112,12 @@ public:
|
||||
bool empty() const { return inpainters_.empty(); }
|
||||
|
||||
virtual void setRadius(int val);
|
||||
virtual void setMotionModel(MotionModel val);
|
||||
virtual void setFrames(const std::vector<Mat> &val);
|
||||
virtual void setMotions(const std::vector<Mat> &val);
|
||||
virtual void setStabilizedFrames(const std::vector<Mat> &val);
|
||||
virtual void setStabilizationMotions(const std::vector<Mat> &val);
|
||||
|
||||
virtual void update();
|
||||
|
||||
virtual void inpaint(int idx, Mat &frame, Mat &mask);
|
||||
|
||||
private:
|
||||
@@ -175,8 +183,7 @@ private:
|
||||
class CV_EXPORTS ColorInpainter : public InpainterBase
|
||||
{
|
||||
public:
|
||||
ColorInpainter(int method = INPAINT_TELEA, double _radius = 2.)
|
||||
: method_(method), radius_(_radius) {}
|
||||
ColorInpainter(int method = INPAINT_TELEA, double radius = 2.);
|
||||
|
||||
virtual void inpaint(int idx, Mat &frame, Mat &mask);
|
||||
|
||||
@@ -186,6 +193,9 @@ private:
|
||||
Mat invMask_;
|
||||
};
|
||||
|
||||
inline ColorInpainter::ColorInpainter(int _method, double _radius)
|
||||
: method_(_method), radius_(_radius) {}
|
||||
|
||||
CV_EXPORTS void calcFlowMask(
|
||||
const Mat &flowX, const Mat &flowY, const Mat &errors, float maxError,
|
||||
const Mat &mask0, const Mat &mask1, Mat &flowMask);
|
||||
@@ -194,6 +204,8 @@ CV_EXPORTS void completeFrameAccordingToFlow(
|
||||
const Mat &flowMask, const Mat &flowX, const Mat &flowY, const Mat &frame1, const Mat &mask1,
|
||||
float distThresh, Mat& frame0, Mat &mask0);
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -40,16 +40,19 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_LOG_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_LOG_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_LOG_HPP
|
||||
#define OPENCV_VIDEOSTAB_LOG_HPP
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS ILog
|
||||
{
|
||||
public:
|
||||
@@ -69,6 +72,8 @@ public:
|
||||
virtual void print(const char *format, ...);
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -0,0 +1,129 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIDEOSTAB_MOTION_CORE_HPP
|
||||
#define OPENCV_VIDEOSTAB_MOTION_CORE_HPP
|
||||
|
||||
#include <cmath>
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab_motion
|
||||
//! @{
|
||||
|
||||
/** @brief Describes motion model between two point clouds.
|
||||
*/
|
||||
enum MotionModel
|
||||
{
|
||||
MM_TRANSLATION = 0,
|
||||
MM_TRANSLATION_AND_SCALE = 1,
|
||||
MM_ROTATION = 2,
|
||||
MM_RIGID = 3,
|
||||
MM_SIMILARITY = 4,
|
||||
MM_AFFINE = 5,
|
||||
MM_HOMOGRAPHY = 6,
|
||||
MM_UNKNOWN = 7
|
||||
};
|
||||
|
||||
/** @brief Describes RANSAC method parameters.
|
||||
*/
|
||||
struct CV_EXPORTS RansacParams
|
||||
{
|
||||
int size; //!< subset size
|
||||
float thresh; //!< max error to classify as inlier
|
||||
float eps; //!< max outliers ratio
|
||||
float prob; //!< probability of success
|
||||
|
||||
RansacParams() : size(0), thresh(0), eps(0), prob(0) {}
|
||||
/** @brief Constructor
|
||||
@param size Subset size.
|
||||
@param thresh Maximum re-projection error value to classify as inlier.
|
||||
@param eps Maximum ratio of incorrect correspondences.
|
||||
@param prob Required success probability.
|
||||
*/
|
||||
RansacParams(int size, float thresh, float eps, float prob);
|
||||
|
||||
/**
|
||||
@return Number of iterations that'll be performed by RANSAC method.
|
||||
*/
|
||||
int niters() const
|
||||
{
|
||||
return static_cast<int>(
|
||||
std::ceil(std::log(1 - prob) / std::log(1 - std::pow(1 - eps, size))));
|
||||
}
|
||||
|
||||
/**
|
||||
@param model Motion model. See cv::videostab::MotionModel.
|
||||
@return Default RANSAC method parameters for the given motion model.
|
||||
*/
|
||||
static RansacParams default2dMotion(MotionModel model)
|
||||
{
|
||||
CV_Assert(model < MM_UNKNOWN);
|
||||
if (model == MM_TRANSLATION)
|
||||
return RansacParams(1, 0.5f, 0.5f, 0.99f);
|
||||
if (model == MM_TRANSLATION_AND_SCALE)
|
||||
return RansacParams(2, 0.5f, 0.5f, 0.99f);
|
||||
if (model == MM_ROTATION)
|
||||
return RansacParams(1, 0.5f, 0.5f, 0.99f);
|
||||
if (model == MM_RIGID)
|
||||
return RansacParams(2, 0.5f, 0.5f, 0.99f);
|
||||
if (model == MM_SIMILARITY)
|
||||
return RansacParams(2, 0.5f, 0.5f, 0.99f);
|
||||
if (model == MM_AFFINE)
|
||||
return RansacParams(3, 0.5f, 0.5f, 0.99f);
|
||||
return RansacParams(4, 0.5f, 0.5f, 0.99f);
|
||||
}
|
||||
};
|
||||
|
||||
inline RansacParams::RansacParams(int _size, float _thresh, float _eps, float _prob)
|
||||
: size(_size), thresh(_thresh), eps(_eps), prob(_prob) {}
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
#endif
|
||||
@@ -40,66 +40,134 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP
|
||||
#define OPENCV_VIDEOSTAB_MOTION_STABILIZING_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include <utility>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/videostab/global_motion.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab_motion
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS IMotionStabilizer
|
||||
{
|
||||
public:
|
||||
virtual void stabilize(const Mat *motions, int size, Mat *stabilizationMotions) const = 0;
|
||||
|
||||
#ifdef OPENCV_CAN_BREAK_BINARY_COMPATIBILITY
|
||||
virtual ~IMotionStabilizer() {}
|
||||
#endif
|
||||
|
||||
//! assumes that [0, size-1) is in or equals to [range.first, range.second)
|
||||
virtual void stabilize(
|
||||
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
|
||||
Mat *stabilizationMotions) = 0;
|
||||
};
|
||||
|
||||
class CV_EXPORTS MotionStabilizationPipeline : public IMotionStabilizer
|
||||
{
|
||||
public:
|
||||
void pushBack(Ptr<IMotionStabilizer> stabilizer) { stabilizers_.push_back(stabilizer); }
|
||||
bool empty() const { return stabilizers_.empty(); }
|
||||
|
||||
virtual void stabilize(
|
||||
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
|
||||
Mat *stabilizationMotions);
|
||||
|
||||
private:
|
||||
std::vector<Ptr<IMotionStabilizer> > stabilizers_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS MotionFilterBase : public IMotionStabilizer
|
||||
{
|
||||
public:
|
||||
MotionFilterBase() : radius_(0) {}
|
||||
virtual ~MotionFilterBase() {}
|
||||
|
||||
virtual void setRadius(int val) { radius_ = val; }
|
||||
virtual int radius() const { return radius_; }
|
||||
virtual Mat stabilize(
|
||||
int idx, const std::vector<Mat> &motions, std::pair<int,int> range) = 0;
|
||||
|
||||
virtual void update() {}
|
||||
|
||||
virtual Mat stabilize(int index, const Mat *motions, int size) const = 0;
|
||||
virtual void stabilize(const Mat *motions, int size, Mat *stabilizationMotions) const;
|
||||
|
||||
protected:
|
||||
int radius_;
|
||||
virtual void stabilize(
|
||||
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
|
||||
Mat *stabilizationMotions);
|
||||
};
|
||||
|
||||
class CV_EXPORTS GaussianMotionFilter : public MotionFilterBase
|
||||
{
|
||||
public:
|
||||
GaussianMotionFilter() : stdev_(-1.f) {}
|
||||
GaussianMotionFilter(int radius = 15, float stdev = -1.f);
|
||||
|
||||
void setStdev(float val) { stdev_ = val; }
|
||||
void setParams(int radius, float stdev = -1.f);
|
||||
int radius() const { return radius_; }
|
||||
float stdev() const { return stdev_; }
|
||||
|
||||
virtual void update();
|
||||
|
||||
virtual Mat stabilize(int index, const Mat *motions, int size) const;
|
||||
virtual Mat stabilize(
|
||||
int idx, const std::vector<Mat> &motions, std::pair<int,int> range);
|
||||
|
||||
private:
|
||||
int radius_;
|
||||
float stdev_;
|
||||
std::vector<float> weight_;
|
||||
};
|
||||
|
||||
inline GaussianMotionFilter::GaussianMotionFilter(int _radius, float _stdev) { setParams(_radius, _stdev); }
|
||||
|
||||
class CV_EXPORTS LpMotionStabilizer : public IMotionStabilizer
|
||||
{
|
||||
public:
|
||||
LpMotionStabilizer(MotionModel model = MM_SIMILARITY);
|
||||
|
||||
void setMotionModel(MotionModel val) { model_ = val; }
|
||||
MotionModel motionModel() const { return model_; }
|
||||
|
||||
void setFrameSize(Size val) { frameSize_ = val; }
|
||||
Size frameSize() const { return frameSize_; }
|
||||
|
||||
void setTrimRatio(float val) { trimRatio_ = val; }
|
||||
float trimRatio() const { return trimRatio_; }
|
||||
|
||||
void setWeight1(float val) { w1_ = val; }
|
||||
float weight1() const { return w1_; }
|
||||
|
||||
void setWeight2(float val) { w2_ = val; }
|
||||
float weight2() const { return w2_; }
|
||||
|
||||
void setWeight3(float val) { w3_ = val; }
|
||||
float weight3() const { return w3_; }
|
||||
|
||||
void setWeight4(float val) { w4_ = val; }
|
||||
float weight4() const { return w4_; }
|
||||
|
||||
virtual void stabilize(
|
||||
int size, const std::vector<Mat> &motions, std::pair<int,int> range,
|
||||
Mat *stabilizationMotions);
|
||||
|
||||
private:
|
||||
MotionModel model_;
|
||||
Size frameSize_;
|
||||
float trimRatio_;
|
||||
float w1_, w2_, w3_, w4_;
|
||||
|
||||
std::vector<double> obj_, collb_, colub_;
|
||||
std::vector<int> rows_, cols_;
|
||||
std::vector<double> elems_, rowlb_, rowub_;
|
||||
|
||||
void set(int row, int col, double coef)
|
||||
{
|
||||
rows_.push_back(row);
|
||||
cols_.push_back(col);
|
||||
elems_.push_back(coef);
|
||||
}
|
||||
};
|
||||
|
||||
CV_EXPORTS Mat ensureInclusionConstraint(const Mat &M, Size size, float trimRatio);
|
||||
|
||||
CV_EXPORTS float estimateOptimalTrimRatio(const Mat &M, Size size);
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace
|
||||
|
||||
|
||||
@@ -40,14 +40,14 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP
|
||||
#define OPENCV_VIDEOSTAB_OPTICAL_FLOW_HPP
|
||||
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/opencv_modules.hpp"
|
||||
|
||||
#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID)
|
||||
# include "opencv2/gpu/gpu.hpp"
|
||||
#ifdef HAVE_OPENCV_CUDAOPTFLOW
|
||||
#include "opencv2/cudaoptflow.hpp"
|
||||
#endif
|
||||
|
||||
namespace cv
|
||||
@@ -55,6 +55,9 @@ namespace cv
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS ISparseOptFlowEstimator
|
||||
{
|
||||
public:
|
||||
@@ -78,11 +81,12 @@ class CV_EXPORTS PyrLkOptFlowEstimatorBase
|
||||
public:
|
||||
PyrLkOptFlowEstimatorBase() { setWinSize(Size(21, 21)); setMaxLevel(3); }
|
||||
|
||||
void setWinSize(Size val) { winSize_ = val; }
|
||||
Size winSize() const { return winSize_; }
|
||||
virtual void setWinSize(Size val) { winSize_ = val; }
|
||||
virtual Size winSize() const { return winSize_; }
|
||||
|
||||
void setMaxLevel(int val) { maxLevel_ = val; }
|
||||
int maxLevel() const { return maxLevel_; }
|
||||
virtual void setMaxLevel(int val) { maxLevel_ = val; }
|
||||
virtual int maxLevel() const { return maxLevel_; }
|
||||
virtual ~PyrLkOptFlowEstimatorBase() {}
|
||||
|
||||
protected:
|
||||
Size winSize_;
|
||||
@@ -98,7 +102,29 @@ public:
|
||||
OutputArray status, OutputArray errors);
|
||||
};
|
||||
|
||||
#if defined(HAVE_OPENCV_GPU) && !defined(ANDROID)
|
||||
#ifdef HAVE_OPENCV_CUDAOPTFLOW
|
||||
|
||||
class CV_EXPORTS SparsePyrLkOptFlowEstimatorGpu
|
||||
: public PyrLkOptFlowEstimatorBase, public ISparseOptFlowEstimator
|
||||
{
|
||||
public:
|
||||
SparsePyrLkOptFlowEstimatorGpu();
|
||||
|
||||
virtual void run(
|
||||
InputArray frame0, InputArray frame1, InputArray points0, InputOutputArray points1,
|
||||
OutputArray status, OutputArray errors);
|
||||
|
||||
void run(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1,
|
||||
cuda::GpuMat &status, cuda::GpuMat &errors);
|
||||
|
||||
void run(const cuda::GpuMat &frame0, const cuda::GpuMat &frame1, const cuda::GpuMat &points0, cuda::GpuMat &points1,
|
||||
cuda::GpuMat &status);
|
||||
|
||||
private:
|
||||
Ptr<cuda::SparsePyrLKOpticalFlow> optFlowEstimator_;
|
||||
cuda::GpuMat frame0_, frame1_, points0_, points1_, status_, errors_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS DensePyrLkOptFlowEstimatorGpu
|
||||
: public PyrLkOptFlowEstimatorBase, public IDenseOptFlowEstimator
|
||||
{
|
||||
@@ -108,12 +134,16 @@ public:
|
||||
virtual void run(
|
||||
InputArray frame0, InputArray frame1, InputOutputArray flowX, InputOutputArray flowY,
|
||||
OutputArray errors);
|
||||
|
||||
private:
|
||||
gpu::PyrLKOpticalFlow optFlowEstimator_;
|
||||
gpu::GpuMat frame0_, frame1_, flowX_, flowY_, errors_;
|
||||
Ptr<cuda::DensePyrLKOpticalFlow> optFlowEstimator_;
|
||||
cuda::GpuMat frame0_, frame1_, flowX_, flowY_, errors_;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -0,0 +1,101 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP
|
||||
#define OPENCV_VIDEOSTAB_OUTLIER_REJECTION_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/videostab/motion_core.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS IOutlierRejector
|
||||
{
|
||||
public:
|
||||
virtual ~IOutlierRejector() {}
|
||||
|
||||
virtual void process(
|
||||
Size frameSize, InputArray points0, InputArray points1, OutputArray mask) = 0;
|
||||
};
|
||||
|
||||
class CV_EXPORTS NullOutlierRejector : public IOutlierRejector
|
||||
{
|
||||
public:
|
||||
virtual void process(
|
||||
Size frameSize, InputArray points0, InputArray points1, OutputArray mask);
|
||||
};
|
||||
|
||||
class CV_EXPORTS TranslationBasedLocalOutlierRejector : public IOutlierRejector
|
||||
{
|
||||
public:
|
||||
TranslationBasedLocalOutlierRejector();
|
||||
|
||||
void setCellSize(Size val) { cellSize_ = val; }
|
||||
Size cellSize() const { return cellSize_; }
|
||||
|
||||
void setRansacParams(RansacParams val) { ransacParams_ = val; }
|
||||
RansacParams ransacParams() const { return ransacParams_; }
|
||||
|
||||
virtual void process(
|
||||
Size frameSize, InputArray points0, InputArray points1, OutputArray mask);
|
||||
|
||||
private:
|
||||
Size cellSize_;
|
||||
RansacParams ransacParams_;
|
||||
|
||||
typedef std::vector<int> Cell;
|
||||
std::vector<Cell> grid_;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
#endif
|
||||
+27
-3
@@ -40,9 +40,33 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_RING_BUFFER_HPP
|
||||
#define OPENCV_VIDEOSTAB_RING_BUFFER_HPP
|
||||
|
||||
#include "opencv2/videostab/stabilizer.hpp"
|
||||
#include <vector>
|
||||
#include "opencv2/imgproc.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
template <typename T> inline T& at(int idx, std::vector<T> &items)
|
||||
{
|
||||
return items[cv::borderInterpolate(idx, static_cast<int>(items.size()), cv::BORDER_WRAP)];
|
||||
}
|
||||
|
||||
template <typename T> inline const T& at(int idx, const std::vector<T> &items)
|
||||
{
|
||||
return items[cv::borderInterpolate(idx, static_cast<int>(items.size()), cv::BORDER_WRAP)];
|
||||
}
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
#endif
|
||||
@@ -40,30 +40,35 @@
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef __OPENCV_VIDEOSTAB_STABILIZER_HPP__
|
||||
#define __OPENCV_VIDEOSTAB_STABILIZER_HPP__
|
||||
#ifndef OPENCV_VIDEOSTAB_STABILIZER_HPP
|
||||
#define OPENCV_VIDEOSTAB_STABILIZER_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core/core.hpp"
|
||||
#include "opencv2/imgproc/imgproc.hpp"
|
||||
#include <ctime>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/imgproc.hpp"
|
||||
#include "opencv2/videostab/global_motion.hpp"
|
||||
#include "opencv2/videostab/motion_stabilizing.hpp"
|
||||
#include "opencv2/videostab/frame_source.hpp"
|
||||
#include "opencv2/videostab/log.hpp"
|
||||
#include "opencv2/videostab/inpainting.hpp"
|
||||
#include "opencv2/videostab/deblurring.hpp"
|
||||
#include "opencv2/videostab/wobble_suppression.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS StabilizerBase
|
||||
{
|
||||
public:
|
||||
virtual ~StabilizerBase() {}
|
||||
|
||||
void setLog(Ptr<ILog> _log) { log_ = _log; }
|
||||
void setLog(Ptr<ILog> ilog) { log_ = ilog; }
|
||||
Ptr<ILog> log() const { return log_; }
|
||||
|
||||
void setRadius(int val) { radius_ = val; }
|
||||
@@ -72,8 +77,8 @@ public:
|
||||
void setFrameSource(Ptr<IFrameSource> val) { frameSource_ = val; }
|
||||
Ptr<IFrameSource> frameSource() const { return frameSource_; }
|
||||
|
||||
void setMotionEstimator(Ptr<IGlobalMotionEstimator> val) { motionEstimator_ = val; }
|
||||
Ptr<IGlobalMotionEstimator> motionEstimator() const { return motionEstimator_; }
|
||||
void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; }
|
||||
Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; }
|
||||
|
||||
void setDeblurer(Ptr<DeblurerBase> val) { deblurer_ = val; }
|
||||
Ptr<DeblurerBase> deblurrer() const { return deblurer_; }
|
||||
@@ -93,18 +98,19 @@ public:
|
||||
protected:
|
||||
StabilizerBase();
|
||||
|
||||
void setUp(int cacheSize, const Mat &frame);
|
||||
void reset();
|
||||
Mat nextStabilizedFrame();
|
||||
bool doOneIteration();
|
||||
void stabilizeFrame(const Mat &stabilizationMotion);
|
||||
|
||||
virtual void setUp(Mat &firstFrame) = 0;
|
||||
virtual void stabilizeFrame() = 0;
|
||||
virtual void estimateMotion() = 0;
|
||||
virtual void setUp(const Mat &firstFrame);
|
||||
virtual Mat estimateMotion() = 0;
|
||||
virtual Mat estimateStabilizationMotion() = 0;
|
||||
void stabilizeFrame();
|
||||
virtual Mat postProcessFrame(const Mat &frame);
|
||||
void logProcessingTime();
|
||||
|
||||
Ptr<ILog> log_;
|
||||
Ptr<IFrameSource> frameSource_;
|
||||
Ptr<IGlobalMotionEstimator> motionEstimator_;
|
||||
Ptr<ImageMotionEstimatorBase> motionEstimator_;
|
||||
Ptr<DeblurerBase> deblurer_;
|
||||
Ptr<InpainterBase> inpainter_;
|
||||
int radius_;
|
||||
@@ -120,12 +126,14 @@ protected:
|
||||
Mat preProcessedFrame_;
|
||||
bool doInpainting_;
|
||||
Mat inpaintingMask_;
|
||||
Mat finalFrame_;
|
||||
std::vector<Mat> frames_;
|
||||
std::vector<Mat> motions_; // motions_[i] is the motion from i-th to i+1-th frame
|
||||
std::vector<float> blurrinessRates_;
|
||||
std::vector<Mat> stabilizedFrames_;
|
||||
std::vector<Mat> stabilizedMasks_;
|
||||
std::vector<Mat> stabilizationMotions_;
|
||||
clock_t processingStartTime_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS OnePassStabilizer : public StabilizerBase, public IFrameSource
|
||||
@@ -136,15 +144,14 @@ public:
|
||||
void setMotionFilter(Ptr<MotionFilterBase> val) { motionFilter_ = val; }
|
||||
Ptr<MotionFilterBase> motionFilter() const { return motionFilter_; }
|
||||
|
||||
virtual void reset() { resetImpl(); }
|
||||
virtual void reset();
|
||||
virtual Mat nextFrame() { return nextStabilizedFrame(); }
|
||||
|
||||
private:
|
||||
void resetImpl();
|
||||
|
||||
virtual void setUp(Mat &firstFrame);
|
||||
virtual void estimateMotion();
|
||||
virtual void stabilizeFrame();
|
||||
protected:
|
||||
virtual void setUp(const Mat &firstFrame);
|
||||
virtual Mat estimateMotion();
|
||||
virtual Mat estimateStabilizationMotion();
|
||||
virtual Mat postProcessFrame(const Mat &frame);
|
||||
|
||||
Ptr<MotionFilterBase> motionFilter_;
|
||||
};
|
||||
@@ -157,30 +164,36 @@ public:
|
||||
void setMotionStabilizer(Ptr<IMotionStabilizer> val) { motionStabilizer_ = val; }
|
||||
Ptr<IMotionStabilizer> motionStabilizer() const { return motionStabilizer_; }
|
||||
|
||||
void setWobbleSuppressor(Ptr<WobbleSuppressorBase> val) { wobbleSuppressor_ = val; }
|
||||
Ptr<WobbleSuppressorBase> wobbleSuppressor() const { return wobbleSuppressor_; }
|
||||
|
||||
void setEstimateTrimRatio(bool val) { mustEstTrimRatio_ = val; }
|
||||
bool mustEstimateTrimaRatio() const { return mustEstTrimRatio_; }
|
||||
|
||||
virtual void reset() { resetImpl(); }
|
||||
virtual void reset();
|
||||
virtual Mat nextFrame();
|
||||
|
||||
// available after pre-pass, before it's empty
|
||||
std::vector<Mat> motions() const;
|
||||
|
||||
private:
|
||||
void resetImpl();
|
||||
protected:
|
||||
void runPrePassIfNecessary();
|
||||
|
||||
virtual void setUp(Mat &firstFrame);
|
||||
virtual void estimateMotion() { /* do nothing as motion was estimation in pre-pass */ }
|
||||
virtual void stabilizeFrame();
|
||||
virtual void setUp(const Mat &firstFrame);
|
||||
virtual Mat estimateMotion();
|
||||
virtual Mat estimateStabilizationMotion();
|
||||
virtual Mat postProcessFrame(const Mat &frame);
|
||||
|
||||
Ptr<IMotionStabilizer> motionStabilizer_;
|
||||
Ptr<WobbleSuppressorBase> wobbleSuppressor_;
|
||||
bool mustEstTrimRatio_;
|
||||
|
||||
int frameCount_;
|
||||
bool isPrePassDone_;
|
||||
bool doWobbleSuppression_;
|
||||
std::vector<Mat> motions2_;
|
||||
Mat suppressedFrame_;
|
||||
};
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
|
||||
@@ -0,0 +1,140 @@
|
||||
/*M///////////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
|
||||
//
|
||||
// By downloading, copying, installing or using the software you agree to this license.
|
||||
// If you do not agree to this license, do not download, install,
|
||||
// copy or use the software.
|
||||
//
|
||||
//
|
||||
// License Agreement
|
||||
// For Open Source Computer Vision Library
|
||||
//
|
||||
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
|
||||
// Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved.
|
||||
// Third party copyrights are property of their respective owners.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without modification,
|
||||
// are permitted provided that the following conditions are met:
|
||||
//
|
||||
// * Redistribution's of source code must retain the above copyright notice,
|
||||
// this list of conditions and the following disclaimer.
|
||||
//
|
||||
// * Redistribution's in binary form must reproduce the above copyright notice,
|
||||
// this list of conditions and the following disclaimer in the documentation
|
||||
// and/or other materials provided with the distribution.
|
||||
//
|
||||
// * The name of the copyright holders may not be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// This software is provided by the copyright holders and contributors "as is" and
|
||||
// any express or implied warranties, including, but not limited to, the implied
|
||||
// warranties of merchantability and fitness for a particular purpose are disclaimed.
|
||||
// In no event shall the Intel Corporation or contributors be liable for any direct,
|
||||
// indirect, incidental, special, exemplary, or consequential damages
|
||||
// (including, but not limited to, procurement of substitute goods or services;
|
||||
// loss of use, data, or profits; or business interruption) however caused
|
||||
// and on any theory of liability, whether in contract, strict liability,
|
||||
// or tort (including negligence or otherwise) arising in any way out of
|
||||
// the use of this software, even if advised of the possibility of such damage.
|
||||
//
|
||||
//M*/
|
||||
|
||||
#ifndef OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP
|
||||
#define OPENCV_VIDEOSTAB_WOBBLE_SUPPRESSION_HPP
|
||||
|
||||
#include <vector>
|
||||
#include "opencv2/core.hpp"
|
||||
#include "opencv2/core/cuda.hpp"
|
||||
#include "opencv2/videostab/global_motion.hpp"
|
||||
#include "opencv2/videostab/log.hpp"
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
//! @addtogroup videostab
|
||||
//! @{
|
||||
|
||||
class CV_EXPORTS WobbleSuppressorBase
|
||||
{
|
||||
public:
|
||||
WobbleSuppressorBase();
|
||||
|
||||
virtual ~WobbleSuppressorBase() {}
|
||||
|
||||
void setMotionEstimator(Ptr<ImageMotionEstimatorBase> val) { motionEstimator_ = val; }
|
||||
Ptr<ImageMotionEstimatorBase> motionEstimator() const { return motionEstimator_; }
|
||||
|
||||
virtual void suppress(int idx, const Mat &frame, Mat &result) = 0;
|
||||
|
||||
|
||||
// data from stabilizer
|
||||
|
||||
virtual void setFrameCount(int val) { frameCount_ = val; }
|
||||
virtual int frameCount() const { return frameCount_; }
|
||||
|
||||
virtual void setMotions(const std::vector<Mat> &val) { motions_ = &val; }
|
||||
virtual const std::vector<Mat>& motions() const { return *motions_; }
|
||||
|
||||
virtual void setMotions2(const std::vector<Mat> &val) { motions2_ = &val; }
|
||||
virtual const std::vector<Mat>& motions2() const { return *motions2_; }
|
||||
|
||||
virtual void setStabilizationMotions(const std::vector<Mat> &val) { stabilizationMotions_ = &val; }
|
||||
virtual const std::vector<Mat>& stabilizationMotions() const { return *stabilizationMotions_; }
|
||||
|
||||
protected:
|
||||
Ptr<ImageMotionEstimatorBase> motionEstimator_;
|
||||
int frameCount_;
|
||||
const std::vector<Mat> *motions_;
|
||||
const std::vector<Mat> *motions2_;
|
||||
const std::vector<Mat> *stabilizationMotions_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS NullWobbleSuppressor : public WobbleSuppressorBase
|
||||
{
|
||||
public:
|
||||
virtual void suppress(int idx, const Mat &frame, Mat &result);
|
||||
};
|
||||
|
||||
class CV_EXPORTS MoreAccurateMotionWobbleSuppressorBase : public WobbleSuppressorBase
|
||||
{
|
||||
public:
|
||||
virtual void setPeriod(int val) { period_ = val; }
|
||||
virtual int period() const { return period_; }
|
||||
|
||||
protected:
|
||||
MoreAccurateMotionWobbleSuppressorBase() { setPeriod(30); }
|
||||
|
||||
int period_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS MoreAccurateMotionWobbleSuppressor : public MoreAccurateMotionWobbleSuppressorBase
|
||||
{
|
||||
public:
|
||||
virtual void suppress(int idx, const Mat &frame, Mat &result);
|
||||
|
||||
private:
|
||||
Mat_<float> mapx_, mapy_;
|
||||
};
|
||||
|
||||
#if defined(HAVE_OPENCV_CUDAWARPING)
|
||||
class CV_EXPORTS MoreAccurateMotionWobbleSuppressorGpu : public MoreAccurateMotionWobbleSuppressorBase
|
||||
{
|
||||
public:
|
||||
void suppress(int idx, const cuda::GpuMat &frame, cuda::GpuMat &result);
|
||||
virtual void suppress(int idx, const Mat &frame, Mat &result);
|
||||
|
||||
private:
|
||||
cuda::GpuMat frameDevice_, resultDevice_;
|
||||
cuda::GpuMat mapx_, mapy_;
|
||||
};
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
} // namespace videostab
|
||||
} // namespace cv
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user