mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Updated wobble suppression code in videostab module
This commit is contained in:
@@ -51,8 +51,7 @@ namespace cv
|
||||
namespace videostab
|
||||
{
|
||||
|
||||
WobbleSuppressorBase::WobbleSuppressorBase()
|
||||
: motions_(0), stabilizationMotions_(0)
|
||||
WobbleSuppressorBase::WobbleSuppressorBase() : motions_(0), stabilizationMotions_(0)
|
||||
{
|
||||
PyrLkRobustMotionEstimator *est = new PyrLkRobustMotionEstimator();
|
||||
est->setMotionModel(HOMOGRAPHY);
|
||||
@@ -67,14 +66,61 @@ void NullWobbleSuppressor::suppress(int /*idx*/, const Mat &frame, Mat &result)
|
||||
}
|
||||
|
||||
|
||||
MoreAccurateMotionWobbleSuppressor::MoreAccurateMotionWobbleSuppressor()
|
||||
{
|
||||
setPeriod(30);
|
||||
}
|
||||
|
||||
|
||||
void MoreAccurateMotionWobbleSuppressor::suppress(int idx, const Mat &frame, Mat &result)
|
||||
{
|
||||
CV_Assert(motions_ && stabilizationMotions_);
|
||||
|
||||
// TODO implement
|
||||
CV_Error(CV_StsNotImplemented, "MoreAccurateMotionWobbleSuppressor");
|
||||
if (idx % period_ == 0)
|
||||
{
|
||||
result = frame;
|
||||
return;
|
||||
}
|
||||
|
||||
result = frame;
|
||||
int k1 = idx / period_ * period_;
|
||||
int k2 = std::min(k1 + period_, frameCount_ - 1);
|
||||
|
||||
Mat S1 = (*stabilizationMotions_)[idx];
|
||||
|
||||
Mat_<float> ML = S1 * getMotion(k1, idx, *motions2_) * getMotion(k1, idx, *motions_).inv() * S1.inv();
|
||||
Mat_<float> MR = S1 * getMotion(idx, k2, *motions2_).inv() * getMotion(idx, k2, *motions_) * S1.inv();
|
||||
|
||||
mapx_.create(frame.size());
|
||||
mapy_.create(frame.size());
|
||||
|
||||
float xl, yl, zl, wl;
|
||||
float xr, yr, zr, wr;
|
||||
|
||||
for (int y = 0; y < frame.rows; ++y)
|
||||
{
|
||||
for (int x = 0; x < frame.cols; ++x)
|
||||
{
|
||||
xl = ML(0,0)*x + ML(0,1)*y + ML(0,2);
|
||||
yl = ML(1,0)*x + ML(1,1)*y + ML(1,2);
|
||||
zl = ML(2,0)*x + ML(2,1)*y + ML(2,2);
|
||||
xl /= zl; yl /= zl;
|
||||
wl = 1.f / (sqrt(sqr(x - xl) + sqr(y - yl)) + 1e-5f);
|
||||
|
||||
xr = MR(0,0)*x + MR(0,1)*y + MR(0,2);
|
||||
yr = MR(1,0)*x + MR(1,1)*y + MR(1,2);
|
||||
zr = MR(2,0)*x + MR(2,1)*y + MR(2,2);
|
||||
xr /= zr; yr /= zr;
|
||||
wr = 1.f / (sqrt(sqr(x - xr) + sqr(y - yr)) + 1e-5f);
|
||||
|
||||
mapx_(y,x) = (wl * xl + wr * xr) / (wl + wr);
|
||||
mapy_(y,x) = (wl * yl + wr * yr) / (wl + wr);
|
||||
}
|
||||
}
|
||||
|
||||
if (result.data == frame.data)
|
||||
result = Mat(frame.size(), frame.type());
|
||||
|
||||
remap(frame, result, mapx_, mapy_, INTER_LINEAR);
|
||||
}
|
||||
|
||||
} // namespace videostab
|
||||
|
||||
Reference in New Issue
Block a user