更新时间:2023-02-16 21:40:13
我同意 Mark Serchell 的评论。我使用的方法是将变量设置为时间+ x秒
并检查。 OpenCV具有用于滑动帧的有用功能,例如 cam.grab()
。它只会从缓冲区中读取该帧,但不会对其执行任何操作。这样你就可以避免遭受缓冲。简单的代码是:
I agree with Mark Serchell's comment. The way I am using is to set variable to time + x seconds
and check. OpenCV have useful feature for skiping frames like cam.grab()
. It will just read that frame from buffer but will not do anything with it. In that way you can avoid "suffering from buffering". Simple code would be:
import cv2
import time
cam = cv2.VideoCapture(url)
ret,frame = cam.read()
timeCheck = time.time()
future = 10*60 # delay
while ret:
if time.time() >= timeCheck:
ret,frame = cam.read()
# Do your staff here
timeCheck = time.time()+future
else:
# Read from buffer, but skip it
ret = cam.grab() # note that grab() function returnt only status code,not the frame