【问题标题】:OpenCV video stabilizationOpenCV 视频稳定
【发布时间】:2015-06-16 15:15:36
【问题描述】:

我正在尝试使用 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])会随着帧的变化而变化。我是否正确使用了 videotab 对象,如何在帧上应用此矩阵以获得结果?

【问题讨论】:

    标签: c++ opencv matrix


    【解决方案1】:

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

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

    对我来说,motion 矩阵是 64-bit double 类型(从 here 检查你的),并将其复制到 32-bit float 类型的 std::vector&lt;float&gt; 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(使用作者的代码和这个设置给出了相同的结果错误值作为作者的图片显示)。

    【讨论】:

      猜你喜欢
      • 2016-05-10
      • 1970-01-01
      • 1970-01-01
      • 2011-03-26
      • 2021-11-07
      • 1970-01-01
      • 1970-01-01
      • 2017-04-27
      • 1970-01-01
      相关资源
      最近更新 更多