繁体   English   中英

OpenCV视频稳定

[英]OpenCV video stabilization

我正在尝试使用OpenCV videostab模块实现视频稳定。 我需要在流中进行,所以我试图在两帧之间进行运动。 学习文档后,我决定这样做:

estimator = new cv::videostab::MotionEstimatorRansacL2(cv::videostab::MM_TRANSLATION);
keypointEstimator = new cv::videostab::KeypointBasedMotionEstimator(estimator);

bool res;
auto motion = keypointEstimator->estimate(this->firstFrame, thisFrame, &res);
std::vector<float> matrix(motion.data, motion.data + (motion.rows*motion.cols));

其中firstFramethisFrame是完全初始化的帧。 问题是, estimate方法总是返回矩阵:

一只忙碌的猫

在该矩阵中,只有最后一个值( matrix[8] )在帧与帧之间变化。 我是否正确使用了videostab对象,如何在帧上应用此矩阵以获得结果?

我是OpenCV的新手,但这是我如何解决这个问题。 问题在于:

std::vector<float> matrix(motion.data, motion.data + (motion.rows*motion.cols));

对我来说, motion矩阵是64-bit double std::vector<float> matrix型(从这里检查)并将其复制到32-bit float类型的std::vector<float> matrix中。 要解决此问题,请尝试将以上行替换为:

std::vector<float> matrix;
for (auto row = 0; row < motion.rows; row++) {
    for (auto col = 0; col < motion.cols; col++) {
            matrix.push_back(motion.at<float>(row, col));
    }
}

我在重复的点集上运行estimator测试了它,它给出了预期的结果,大多数条目接近0.0matrix[0], matrix[4] and matrix[8]1.0 (使用此设置的作者代码给出与作者的图片显示的错误值相同)。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM