I'm trying to read frames from a webcam and analyze them in realtime, but since my function AnalyzeFrame()
is faster than the framerate, it ends up pulling the same frame 1-4 times in a row, messing up my data. Here's basically what I'm running.
import imageio
cam = imageio.get_reader('<video0>', fps=30)
while not cam.closed:
print(AnalyzeFrame(cam.get_next_data()))
A few notes: My webcam should be able to handle 30fps, but I'm averaging 12-14 fps. I've timed each individual process and there's very little regularity to the framerate. Some frames only get analyzed once, because they're in the buffer for 20 or so milliseconds. Others get analyzed 4 times over a span of 100+ ms. Is there something in my code that's causing this framerate problem?