OpenCV视频稳定化

3

我正在尝试使用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方法总是返回像这样的矩阵:

a busy cat

在这个矩阵中,只有最后一个值(matrix[8])从一帧到另一帧会发生变化。我是否正确地使用了videostab对象,以及如何将此矩阵应用于帧以获得结果?

1个回答

0

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

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

对我来说,motion 矩阵的类型是 64 位双精度浮点数(可以从 这里 检查你的类型),将其复制到类型为 32 位浮点数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.0,而matrix[0]、matrix[4]和matrix[8]则为1.0(使用作者的代码进行此设置时,与作者图片显示的相同错误值)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接