[英]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));
其中firstFrame
和thisFrame
是完全初始化的幀。 問題是, 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.0
, matrix[0], matrix[4] and matrix[8]
為1.0
(使用此設置的作者代碼給出與作者的圖片顯示的錯誤值相同)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.