簡體   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