简体   繁体   English

opencv视频稳定算法

[英]opencv video stabilization algorithm

I am writing video stabilizer using opencv.我正在使用 opencv 编写视频稳定器。 The algorithm is as follows:算法如下:

while there are more frames in the video:虽然视频中有更多帧:

  1. take new frame from the video从视频中获取新帧
  2. detect keypoints in the new frame检测新帧中的关键点
  3. compute descriptor for new keypoints计算新关键点的描述符
  4. match descriptors of the new and the previous frame匹配新帧和前一帧的描述符
  5. filter matches to get good matches过滤匹配以获得好的匹配
  6. find homography between previous and new frame找到前一帧和新帧之间的单应性
  7. apply homography (warpPerspective) to the new frame and thus create "adjusted new frame"将单应性(warpPerspective)应用于新框架,从而创建“调整后的新框架”
  8. set previous frame to be equal to "adjusted new frame" (descriptors, keypoints)将前一帧设置为等于“调整后的新帧”(描述符、关键点)

I have a few questions.我有几个问题。 Am I on the right track?我在正确的轨道上吗? How to do the actual stabilization (using Gaussian filter or something else)?如何进行实际的稳定(使用高斯滤波器或其他东西)?

Here is possible sequence of steps:以下是可能的步骤顺序:

Step 1. Read Frames from a Movie File步骤 1。 从电影文件中读取帧

Step 2. Collect Salient Points from Each Frame步骤 2. 从每一帧收集显着点

Step 3. Select Correspondences Between Points步骤 3. 选择点之间的对应关系

Step 4. Estimating Transform from Noisy Correspondences步骤 4. 从嘈杂的对应关系估计变换

Step 5. Transform Approximation and Smoothing步骤 5. 变换近似和平滑

Step 6. Run on the Full Video步骤 6. 在完整视频上运行

More details on each step you can find here:您可以在此处找到有关每个步骤的更多详细信息:

http://www.mathworks.com/help/vision/examples/video-stabilization-using-point-feature-matching.html http://www.mathworks.com/help/vision/examples/video-stabilization-using-point-feature-matching.html

I think you can follow the same steps in OpenCV.我认为您可以在 OpenCV 中遵循相同的步骤。

If you're using python code then you can use my powerful & threaded VidGear Video Processing python library that now provides real-time Video Stabilization with minimalistic latency and at the expense of little to no additional computational power requirement with Stabilizer Class .如果您使用的是 python 代码,那么您可以使用我强大的线程VidGear视频处理 python 库,该库现在提供具有最小延迟的实时视频稳定,并且Stabilizer Class几乎不需要额外的计算能力要求。 Here's a basic usage example for your convenience:为了您的方便,这是一个基本的使用示例:

# import libraries
from vidgear.gears import VideoGear
from vidgear.gears import WriteGear
import cv2

stream = VideoGear(source=0, stabilize = True).start() # To open any valid video stream(for e.g device at 0 index)

# infinite loop
while True:

    frame = stream.read()
    # read stabilized frames

    # check if frame is None
    if frame is None:
        #if True break the infinite loop
        break

    # do something with stabilized frame here

    cv2.imshow("Stabilized Frame", frame)
    # Show output window

    key = cv2.waitKey(1) & 0xFF
    # check for 'q' key-press
    if key == ord("q"):
        #if 'q' key-pressed break out
        break

cv2.destroyAllWindows()
# close output window

stream.stop()
# safely close video stream

More advanced usage can be found here: https://github.com/abhiTronix/vidgear/wiki/Real-time-Video-Stabilization#real-time-video-stabilization-with-vidgear更高级的用法可以在这里找到: https : //github.com/abhiTronix/vidgear/wiki/Real-time-Video-Stabilization#real-time-video-stabilization-with-vidgear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM