我正在做一個C++視頻穩定/防抖程序,其中: - 獲取參考幀上的興趣點(使用FAST,SURF,Shi- Matoshi或SIFT,不妨多試幾個) - 計算與calcOpticalFlowPyrLK 盧卡斯 - Kanade光流 - 獲取單應矩陣 - 更正使用warPerspective晃動的圖像(見下面的代碼)從視頻穩定程序將C/++ OpenCV程序更改爲CUDA
//Calculate the Lucas Kanade optical flow
calcOpticalFlowPyrLK(original, distorted, refFeatures, currFeatures, featuresFound, err);
//Find the homography between the current frame's features and the reference ones's
if(homographyRansac){
homography = findHomography(currFeatures, refFeatures, CV_RANSAC); /*CV_RANSAC: Random sample consensus (RANSAC) is an iterative method to
estimate parameters of a mathematical model from a set of observed data which contains outliers */
}else{
homography = findHomography(currFeatures, refFeatures, 0);
}
//We use warpPerspective once on the distorted image to get the resulting fixed image
if(multiChannel){
//Spliting into channels
vector <Mat> rgbChannels(channels), fixedChannels;
split(distortedCopy, rgbChannels);
recovered = Mat(reSized, CV_8UC3);
//We apply the transformation to each channel
for(int i = 0; i < channels; i ++){
Mat tmp;
warpPerspective(rgbChannels[i], tmp, homography, reSized);
fixedChannels.push_back(tmp);
}
//Merge the result to obtain a 3 channel corrected image
merge(fixedChannels, recovered);
}else{
warpPerspective(distorted, recovered, homography, reSized);
}
如果你有我的穩定解決方案的任何替代品,隨時可以這樣說,但這不是這個話題的主題。由於所有這些都需要大量的時間(我的i5電腦每幀大約需要300ms,因此30分鐘的視頻需要很長的時間),所以我正在考慮使用CUDA來加快速度。我已經安裝並開始工作,但我不確定接下來要做什麼。我已經做了一些測試,我知道最耗時的操作是使用calcOpticalFlowPyrLK和warpPerspective分別獲得光流和幀校正。所以理想情況下,至少在一開始,我只會使用這兩個函數的CUDA版本,而其餘部分不變。
這可能嗎?或者我需要重寫所有內容?
感謝
爲什麼不在OpenCV 3.0中使用內置的CUDA加速視頻穩定器?創建一個「OnePassStabilizer」類的對象,並將其運動估計器設置爲「KeypointBasedMotionEstimatorGpu」。只需在代碼中包含'opencv2/videostab.hpp'。 – sgarizvi 2014-11-25 10:24:19
我會試一試並回復給你,謝謝! – user1965728 2014-11-25 12:21:25
您能否幫我解釋一下,恐怕我不知道如何繼續 – user1965728 2014-11-25 12:47:24