Force Framerate for VideoStream(src=0)?
jperraud opened this issue · comments
jperraud commented
Hi! I try to program a webcam stream with a fixed delay (see code below). I observe very high framerates (up to 250), which makes me believe that I have frames duplicated. However, fluctuating values in framerate between recording without showing the frames and displaying the frames with openCV lead to a very unpredictable delay. Is there a way to control the framerate to have predictable behavior and fixed delay? Cheers, Jonny
import time
from imutils.video import VideoStream
import cv2
vs = VideoStream(src=0).start()
delay = 5
frames = []
time.sleep(5)
start_time = time.time()
while True:
frame = vs.read()
frames.append(frame)
if time.time()-start_time > delay:
cv2.imshow('', frames.pop(0))
key = cv2.waitKey(25)
if key == ord('q'):
break
vs.stop()
`