mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 23:33:05 +04:00
Minor fixes and updates in videostab module and sample
This commit is contained in:
@@ -101,7 +101,7 @@ public:
|
||||
virtual void setMotionModel(MotionModel val) { motionModel_ = val; }
|
||||
virtual MotionModel motionModel() const { return motionModel_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1) = 0;
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0) = 0;
|
||||
|
||||
protected:
|
||||
MotionModel motionModel_;
|
||||
@@ -111,7 +111,7 @@ class CV_EXPORTS FromFileMotionReader : public GlobalMotionEstimatorBase
|
||||
{
|
||||
public:
|
||||
FromFileMotionReader(const std::string &path);
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1);
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
std::ifstream file_;
|
||||
@@ -121,7 +121,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);
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
std::ofstream file_;
|
||||
@@ -148,7 +148,7 @@ public:
|
||||
void setMinInlierRatio(float val) { minInlierRatio_ = val; }
|
||||
float minInlierRatio() const { return minInlierRatio_; }
|
||||
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1);
|
||||
virtual Mat estimate(const Mat &frame0, const Mat &frame1, bool *ok = 0);
|
||||
|
||||
private:
|
||||
Ptr<FeatureDetector> detector_;
|
||||
|
||||
@@ -295,12 +295,14 @@ FromFileMotionReader::FromFileMotionReader(const string &path)
|
||||
}
|
||||
|
||||
|
||||
Mat FromFileMotionReader::estimate(const Mat &/*frame0*/, const Mat &/*frame1*/)
|
||||
Mat FromFileMotionReader::estimate(const Mat &/*frame0*/, const Mat &/*frame1*/, bool *ok)
|
||||
{
|
||||
Mat_<float> M(3, 3);
|
||||
bool ok_;
|
||||
file_ >> M(0,0) >> M(0,1) >> M(0,2)
|
||||
>> M(1,0) >> M(1,1) >> M(1,2)
|
||||
>> M(2,0) >> M(2,1) >> M(2,2);
|
||||
>> M(2,0) >> M(2,1) >> M(2,2) >> ok_;
|
||||
if (ok) *ok = ok_;
|
||||
return M;
|
||||
}
|
||||
|
||||
@@ -313,12 +315,14 @@ ToFileMotionWriter::ToFileMotionWriter(const string &path, Ptr<GlobalMotionEstim
|
||||
}
|
||||
|
||||
|
||||
Mat ToFileMotionWriter::estimate(const Mat &frame0, const Mat &frame1)
|
||||
Mat ToFileMotionWriter::estimate(const Mat &frame0, const Mat &frame1, bool *ok)
|
||||
{
|
||||
Mat_<float> M = estimator_->estimate(frame0, frame1);
|
||||
bool ok_;
|
||||
Mat_<float> M = estimator_->estimate(frame0, frame1, &ok_);
|
||||
file_ << M(0,0) << " " << M(0,1) << " " << M(0,2) << " "
|
||||
<< M(1,0) << " " << M(1,1) << " " << M(1,2) << " "
|
||||
<< M(2,0) << " " << M(2,1) << " " << M(2,2) << endl;
|
||||
<< M(2,0) << " " << M(2,1) << " " << M(2,2) << " " << ok_ << endl;
|
||||
if (ok) *ok = ok_;
|
||||
return M;
|
||||
}
|
||||
|
||||
@@ -343,7 +347,7 @@ PyrLkRobustMotionEstimator::PyrLkRobustMotionEstimator(MotionModel model)
|
||||
}
|
||||
|
||||
|
||||
Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1)
|
||||
Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1, bool *ok)
|
||||
{
|
||||
detector_->detect(frame0, keypointsPrev_);
|
||||
|
||||
@@ -402,8 +406,12 @@ Mat PyrLkRobustMotionEstimator::estimate(const Mat &frame0, const Mat &frame1)
|
||||
rmse = sqrt(rmse / static_cast<float>(ninliers));
|
||||
}
|
||||
|
||||
if (ok) *ok = true;
|
||||
if (rmse > maxRmse_ || static_cast<float>(ninliers) / pointsGood_.size() < minInlierRatio_)
|
||||
{
|
||||
M = Mat::eye(3, 3, CV_32F);
|
||||
if (ok) *ok = false;
|
||||
}
|
||||
|
||||
return M;
|
||||
}
|
||||
|
||||
@@ -338,6 +338,7 @@ void TwoPassStabilizer::runPrePassIfNecessary()
|
||||
WobbleSuppressorBase *wobbleSuppressor = static_cast<WobbleSuppressorBase*>(wobbleSuppressor_);
|
||||
doWobbleSuppression_ = dynamic_cast<NullWobbleSuppressor*>(wobbleSuppressor) == 0;
|
||||
|
||||
bool okEst;
|
||||
while (!(frame = frameSource_->nextFrame()).empty())
|
||||
{
|
||||
if (frameCount_ > 0)
|
||||
@@ -345,8 +346,11 @@ void TwoPassStabilizer::runPrePassIfNecessary()
|
||||
motions_.push_back(motionEstimator_->estimate(prevFrame, frame));
|
||||
if (doWobbleSuppression_)
|
||||
{
|
||||
motions2_.push_back(
|
||||
wobbleSuppressor_->motionEstimator()->estimate(prevFrame, frame));
|
||||
Mat M = wobbleSuppressor_->motionEstimator()->estimate(prevFrame, frame, &okEst);
|
||||
if (okEst)
|
||||
motions2_.push_back(M);
|
||||
else
|
||||
motions2_.push_back(motions_.back());
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
Reference in New Issue
Block a user