实时视频稳定化 OpenCV

5

我在OpenCV中搜索了一个函数(cv::videostab),希望能够实现实时视频稳定。但是据我所知,在OpenCV中还没有这个功能。因此,TwoPassStabilizer(OnePassStabilizer)需要一次性处理整个视频,而不是两个连续的帧。

Ptr<VideoFileSource> source = makePtr<VideoFileSource>(inputPath); //it's whole video
TwoPassStabilizer *twopassStabilizer = new TwoPassStabilizer();
twoPassStabilizer->setFrameSource(source); 

那么我必须在没有OpenCV视频稳定类的情况下完成这个任务。这是正确的吗?

2个回答

4

OpenCV库并未提供实时视频稳定的专用代码/模块。

话虽如此,如果您使用Python代码,则可以使用我强大且多线程的VidGear视频处理Python库。此库现在提供具有极小延迟和几乎不需要额外计算能力的实时视频稳定,使用Stabilizer Class即可实现。以下是一个基本的用法示例,以方便您使用:

# 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

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

0

虽然这理论上回答了问题,但最好在此处包含答案的基本部分,并提供参考链接。 - Anton Menshov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接