我正在做一个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