我开发了一个简单的稳定器,我对图像的移动有困难.示例 - 我有两个图像(A和B)相对于彼此移动几个像素.我使用相位相关计算偏移量.下一步我需要通过图像的偏移来移动第二个图像.图像上显示了一个示例.我该如何解决这个问题?
有预览图像的链接:

我正在创建一个程序来稳定视频流.目前,我的程序基于相位相关算法工作.我正在计算两个图像之间的偏移 - 基础和当前.接下来,我根据新坐标校正当前图像.这个程序有效,但效果不理想.相关链接您可能会发现处理后的视频显得不受欢迎,并且整个视频的抖动变得更糟.
Orininal video
Unshaked video
我目前的认识是:
计算图像之间的偏移量:
Point2d calculate_offset_phase_optimized(Mat one, Mat& two) {
if(two.type() != CV_64F) {
cvtColor(two, two, CV_BGR2GRAY);
two.convertTo(two, CV_64F);
}
cvtColor(one, one, CV_BGR2GRAY);
one.convertTo(one, CV_64F);
return phaseCorrelate(one, two);
}
Run Code Online (Sandbox Code Playgroud)
根据此坐标移动图像:
void move_image_roi_alt(Mat& img, Mat& trans, const Point2d& offset) {
trans = Mat::zeros(img.size(), img.type());
img(
Rect(
_0(static_cast<int>(offset.x)),
_0(static_cast<int>(offset.y)),
img.cols-abs(static_cast<int>(offset.x)),
img.rows-abs(static_cast<int>(offset.y))
)
).copyTo(trans(
Rect(
_0ia(static_cast<int>(offset.x)),
_0ia(static_cast<int>(offset.y)),
img.cols-abs(static_cast<int>(offset.x)),
img.rows-abs(static_cast<int>(offset.y))
)
));
}
int _0(const int x) {
return x < 0 ? 0 : x;
}
int _0ia(const …Run Code Online (Sandbox Code Playgroud)