我正在做一个 C++ 视频稳定/防抖程序,它: - 在参考框架上获取兴趣点(使用 FAST、SURF、Shi-Matoshi 或 SIFT,可能会尝试更多) - 计算 Lucas-Kanade 光流使用 calcOpticalFlowPyrLK - 获取单应矩阵 - 使用 warPerspective 校正抖动图像(参见下面的代码)
//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 计算机上每帧大约 300 毫秒,所以 30 分钟的视频需要很长时间)我正在考虑使用 CUDA 来加快速度。我已经安装了它并开始工作,但是我不确定下一步如何进行。我已经做了一些测试,我知道最耗时的操作是分别使用 calcOpticalFlowPyrLK 和 warpPerspective 获得光流和帧校正。所以理想情况下,至少一开始,我只会使用这两个函数的 CUDA 版本,其余的保持不变。
这可能吗?还是我需要重写所有内容?
谢谢