卡尔曼滤波器实现实时视频稳定

时间:2018-08-28 11:56:08

标签: opencv video homography

我找到了此代码https://github.com/Lakshya-Kejriwal/Real-Time-Video-Stabilization。但是这段代码使用了仿射变换。

affine = estimateRigidTransform(goodFeatures1, goodFeatures2, false);

dx = affine.at<double>(0,2);
dy = affine.at<double>(1,2);
da = atan2(affine.at<double>(1,0), affine.at<double>(0,0));

smoothedMat.at<double>(0,0) = sx * cos(da);
smoothedMat.at<double>(0,1) = sx * -sin(da);
smoothedMat.at<double>(1,0) = sy * sin(da);
smoothedMat.at<double>(1,1) = sy * cos(da);

smoothedMat.at<double>(0,2) = dx;
smoothedMat.at<double>(1,2) = dy;

warpAffine(frame_1, smoothedFrame, smoothedMat, frame_2.size());

我需要用单应矩阵进行视频稳定。所以我需要做

warpPerspective(frame_1, smoothedFrame, smoothedMat, frame_2.size()); 

但是warpPerspective要求smoothedMat的尺寸为3 * 3。 我尝试这样做:

smoothedMat.at<double>(2,0) = 0;
smoothedMat.at<double>(2,1) = 0;
smoothedMat.at<double>(2,2) = 1;

但是我有一个错误:

error: (-215:Assertion failed) (M0.type() == 5 || M0.type() == 6) && M0.rows == 3 && M0.cols == 3 in function 'warpPerspective'.

我应该怎么做?

0 个答案:

没有答案