2015-06-16 74 views
3

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

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对象,以及如何将这个矩阵应用于框架以获得结果?

回答

0

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

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

对我来说,motion矩阵是64-bit double类型(从here检查你的)并将其复制到类型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大多数项结果使用此设置的代码会给出与作者的图片显示相同的错误值)。