2015-06-16 71 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大多數項結果使用此設置的代碼會給出與作者的圖片顯示相同的錯誤值)。