首页 > 解决方案 > 在特定 FPS 下使用 opencv 从网络摄像头抓取图像

问题描述

是否有允许我以特定帧速率抓取静止图像的 OpenCV 功能。就像我可以告诉这个函数以 10fps 的速度抓取 5 张图像一样,它会以 0.1 秒的精确间隔拍摄 5 张图像。

如果不是什么是实现这一目标的好方法?我目前的尝试是不断抓取图像,并且仅在上一帧后 0.1 秒但不准确的 10fps 时才保存

afterNextFrame = False
while x < 20:
        now = time.monotonic()

        if now >= nextFrame:
            afterNextFrame = True




        if afterNextFrame == True:
            cameraCap.grab()
            print("\nNow: ", now, "\n")
            _, frame = cameraCap.retrieve()
            # save frame here

            nextFrame += 0.1 # wait 0.1 second for 10 fps
            afterNextFrame = False

标签: opencv

解决方案


推荐阅读