Я нашел этот код 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'.
Как мне это сделать?