TLDR: USB Camera stops returning images with continued usage.
I am running a continuous application using Raspberry Pi4, Ubuntu, OpenCV where I am capturing an image once every 5 seconds and sending that to an API. I'm having an issue where I am getting None
frames after some time and the camera becomes unresponsive.
I've tried using V4L2 and fswebcam directly in the command line as tests, but I keep getting the same issue of the camera either being completely unresponsive or taking several minutes to capture an image.
Simplified Code
import cv2
import time
cam=cv2.VideoCapture(0)
time.sleep(2)
cam.set(3,1280)
cam.set(4,720)
cam.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc('M','J','P','G'))
while True:
time.sleep(5)
ret , frame = cam.read()
This runs fine at first, but the images start coming in slower and slower over time. Eventually, it returns None
frame and becomes unresponsive. Subsequent attempts to release and select the camera result in camera select timeout errors.
VIDEOIO(V4L2:/dev/video0): select() timeout
Any idea what would cause the camera to start taking longer and longer to capture the images and why the camera becomes unresponsive?