本文介绍了视频稳定与OpenCV的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用移动相机拍摄并包含移动物体的视频Feed。我想稳定视频,以便所有固定对象将在视频馈送中保持静止。我该如何使用 OpenCV ?
I have a video feed which is taken with a moving camera and contains moving objects. I would like to stabilize the video, so that all stationary objects will remain stationary in the video feed. How can I do this with OpenCV?
例如,如果我有两个图像prev_frame和next_frame,如何转换 next_frame ,以使摄像机看起来稳定?
i.e. For example, if I have two images prev_frame and next_frame, how do I transform next_frame so the video camera appears stationary?
推荐答案
我可以建议以下解决方案之一:
I can suggest one of the following solutions:
- 使用本地高级功能:OpenCV包括SURF,每帧,提取SURF特征。然后构建特征Kd-Tree(也在OpenCV中),然后匹配每两个连续的帧以找到对应的特征对。将这些对进入cvFindHomography计算这些帧之间的单应性。经编框根据(组合)单应性来稳定。根据我的知识,这是一个非常健壮和复杂的方法,但是SURF提取和匹配可能很慢。
- 你可以尝试用较不强健的功能,仅期望两个帧之间的微小移动,例如使用哈里斯角点检测,并建立两个帧中最接近的角点对,馈送到cvFindHomography然后如上。
- 如果您限制移动到翻译,您可以用更简单的方法替换cvFindHomography,以获取特征对之间的翻译(例如平均)
- 使用相位相关(ref。),如果你期望只有两个帧之间的翻译。 OpenCV包括DFT / FFT和IFFT,请参阅关于公式和解释的链接的维基百科文章。
- Using local high level features: OpenCV includes SURF, so: for each frame, extract SURF features. Then build feature Kd-Tree (also in OpenCV), then match each two consecutive frames to find pairs of corresponding features. Feed those pairs into cvFindHomography to compute the homography between those frames. Warp frames according to (combined..) homographies to stabilize. This is, to my knowledge, a very robust and sophisticated approach, however SURF extraction and matching can be quite slow
- You can try to do the above with "less robust" features, if you expect only minor movement between two frames, e.g. use Harris corner detection and build pairs of corners closest to each other in both frames, feed to cvFindHomography then as above. Probably faster but less robust.
- If you restrict movement to translation, you might be able to replace cvFindHomography with something more...simple, to just get the translation between feature-pairs (e.g. average)
- Use phase-correlation (ref. http://en.wikipedia.org/wiki/Phase_correlation), if you expect only translation between two frames. OpenCV includes DFT/FFT and IFFT, see the linked wikipedia article on formulas and explanation.
EDIT
三个注释我应该更好地提及,以防万一:
EDITThree remarks I should better mention explicitly, just in case:
- 基于单应性的方法可能非常准确,保持静止。然而,单应性包括透视失真和缩放以及所以结果可能看起来有点...普通(或甚至失真的一些快速运动)。虽然确切,这可能不那么视觉上愉悦;所以使用这个而不是进一步处理,或者像法医一样。
- 据我所知,至少有几个免费的视频稳定工具使用相位相关。如果你只是想摇晃相机,这可能是更好的。
- 这个领域有很多研究。在一些论文中你会发现一些更复杂的方法(尽管它们可能不仅仅是OpenCV)。
这篇关于视频稳定与OpenCV的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!