Added LP based global motion estimation (videostab)
This commit is contained in:
@@ -57,6 +57,8 @@
|
||||
#include "opencv2/gpu/gpu.hpp"
|
||||
#endif
|
||||
|
||||
// TODO remove code duplications (in cpp too)
|
||||
|
||||
namespace cv
|
||||
{
|
||||
namespace videostab
|
||||
@@ -91,6 +93,7 @@ class CV_EXPORTS FromFileMotionReader : public GlobalMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
FromFileMotionReader(const std::string &path);
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
@@ -101,6 +104,7 @@ class CV_EXPORTS ToFileMotionWriter : public GlobalMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
ToFileMotionWriter(const std::string &path, Ptr<GlobalMotionEstimatorBase> estimator);
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
@@ -108,30 +112,10 @@ private:
|
||||
Ptr<GlobalMotionEstimatorBase> estimator_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS PyrLkRobustMotionEstimatorBase : public GlobalMotionEstimatorBase
|
||||
class CV_EXPORTS RansacMotionEstimator : public GlobalMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
virtual void setRansacParams(const RansacParams &val) { ransacParams_ = val; }
|
||||
virtual RansacParams ransacParams() const { return ransacParams_; }
|
||||
|
||||
virtual void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; }
|
||||
virtual Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; }
|
||||
|
||||
virtual void setMinInlierRatio(float val) { minInlierRatio_ = val; }
|
||||
virtual float minInlierRatio() const { return minInlierRatio_; }
|
||||
|
||||
protected:
|
||||
PyrLkRobustMotionEstimatorBase(MotionModel model);
|
||||
|
||||
RansacParams ransacParams_;
|
||||
Ptr<IOutlierRejector> outlierRejector_;
|
||||
float minInlierRatio_;
|
||||
};
|
||||
|
||||
class CV_EXPORTS PyrLkRobustMotionEstimator : public PyrLkRobustMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
PyrLkRobustMotionEstimator(MotionModel model = MM_AFFINE);
|
||||
RansacMotionEstimator(MotionModel model = MM_AFFINE);
|
||||
|
||||
void setDetector(Ptr<FeatureDetector> val) { detector_ = val; }
|
||||
Ptr<FeatureDetector> detector() const { return detector_; }
|
||||
@@ -142,12 +126,24 @@ public:
|
||||
void setGridSize(Size val) { gridSize_ = val; }
|
||||
Size gridSize() const { return gridSize_; }
|
||||
|
||||
void setRansacParams(const RansacParams &val) { ransacParams_ = val; }
|
||||
RansacParams ransacParams() const { return ransacParams_; }
|
||||
|
||||
void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; }
|
||||
Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; }
|
||||
|
||||
void setMinInlierRatio(float val) { minInlierRatio_ = val; }
|
||||
float minInlierRatio() const { return minInlierRatio_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
Ptr<FeatureDetector> detector_;
|
||||
Ptr<ISparseOptFlowEstimator> optFlowEstimator_;
|
||||
Size gridSize_;
|
||||
RansacParams ransacParams_;
|
||||
Ptr<IOutlierRejector> outlierRejector_;
|
||||
float minInlierRatio_;
|
||||
|
||||
std::vector<uchar> status_;
|
||||
std::vector<KeyPoint> keypointsPrev_;
|
||||
@@ -156,10 +152,19 @@ private:
|
||||
};
|
||||
|
||||
#if HAVE_OPENCV_GPU
|
||||
class CV_EXPORTS PyrLkRobustMotionEstimatorGpu : public PyrLkRobustMotionEstimatorBase
|
||||
class CV_EXPORTS RansacMotionEstimatorGpu : public GlobalMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
PyrLkRobustMotionEstimatorGpu(MotionModel model = MM_AFFINE);
|
||||
RansacMotionEstimatorGpu(MotionModel model = MM_AFFINE);
|
||||
|
||||
void setRansacParams(const RansacParams &val) { ransacParams_ = val; }
|
||||
RansacParams ransacParams() const { return ransacParams_; }
|
||||
|
||||
void setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; }
|
||||
Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; }
|
||||
|
||||
void setMinInlierRatio(float val) { minInlierRatio_ = val; }
|
||||
float minInlierRatio() const { return minInlierRatio_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
Mat estimate(const gpu::GpuMat &frame0, const gpu::GpuMat &frame1, bool *ok = 0);
|
||||
@@ -167,6 +172,9 @@ public:
|
||||
private:
|
||||
gpu::GoodFeaturesToTrackDetector_GPU detector_;
|
||||
SparsePyrLkOptFlowEstimatorGpu optFlowEstimator_;
|
||||
RansacParams ransacParams_;
|
||||
Ptr<IOutlierRejector> outlierRejector_;
|
||||
float minInlierRatio_;
|
||||
|
||||
gpu::GpuMat frame0_, grayFrame0_, frame1_;
|
||||
gpu::GpuMat pointsPrev_, points_;
|
||||
@@ -178,6 +186,44 @@ private:
|
||||
};
|
||||
#endif
|
||||
|
||||
class CV_EXPORTS LpBasedMotionEstimator : public GlobalMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
LpBasedMotionEstimator(MotionModel model = MM_AFFINE);
|
||||
|
||||
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 setOutlierRejector(Ptr<IOutlierRejector> val) { outlierRejector_ = val; }
|
||||
Ptr<IOutlierRejector> outlierRejector() const { return outlierRejector_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok);
|
||||
|
||||
private:
|
||||
Ptr<FeatureDetector> detector_;
|
||||
Ptr<ISparseOptFlowEstimator> optFlowEstimator_;
|
||||
Ptr<IOutlierRejector> outlierRejector_;
|
||||
|
||||
std::vector<uchar> status_;
|
||||
std::vector<KeyPoint> keypointsPrev_;
|
||||
std::vector<Point2f> pointsPrev_, points_;
|
||||
std::vector<Point2f> pointsPrevGood_, pointsGood_;
|
||||
|
||||
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 getMotion(int from, int to, const std::vector<Mat> &motions);
|
||||
|
||||
} // namespace videostab
|
||||
|
Reference in New Issue
Block a user