'Raspberry Pi 3 - Video error: select timeout() (Ubuntu)
We are trying to run an object detection program in a Raspberry Pi 3B+ with Ubuntu Server. We are connecting the following devices to the USB ports:
- USB Camera
- Microphone
- Arduino
This is the Python code that we use to ensure that the USB camera is found:
import cv2, glob
for camera in glob.glob("/dev/video?"):
print(camera)
c = cv2.VideoCapture(camera,cv2.CAP_V4L2)
if(c.read()[0]):
print("Working index")
print(c.get(cv2.CAP_PROP_FRAME_WIDTH),c.get(cv2.CAP_PROP_FRAME_HEIGHT))
If this code succeeds, the rest of the program proceeds with the object detection.
This works well for the first few runs of the program (~ 6-10). Eventually, we get the following error:
[ WARN:0] global ../modules/videoio/src/cap_v4l.cpp (1004) tryIoctl VIDEOIO(V4L2:/dev/video0): select() timeout.
After getting this error, all the USB ports get disabled and the program doesn't run again until we reboot the Raspberry Pi.
Occasionally, we also get the following message:
uvcvideo: Failed to resubmit video URB (-1)
To solve this, we have tried removing the uvcvideo drivers and reapplying them again, as suggested here and on many other sites. However, we have not been successful.
We have also tried:
- Using different power supplies.
- Disabling ethernet and connecting through wifi to save bandwidth.
- Disabling bluetooth.
- Disconnecting every other peripheral except the camera to save more bandwidth.
- Lowering the resolution of the camera.
Does anybody know how to solve this issue?
Alternatively, if we can't get rid of these errors, is the only solution to reboot the Pi? Or is there a workaround to get it working again?
Solution 1:[1]
It's a bandwidth problem
I've been encountering a similar problem with a ras-pi 4B and after some digging it appeared to be a bandwidth problem where the v4linux drivers in OpenCV back-end tend to choose YUYV format which causes the bandwidth problem.
if your specify a different format for video capturing like MJPEG it would run smoothly.
cap = cv2.VideoCapture(0)
cap.set(cv2.CAP_PROP_FOURCC,cv2.VideoWriter_fourcc('M','J','P','G'))
this is highly dependandt on your cameras, if you have a camera that offers only MJPEG format then this would probably never happen unless you're running 4 cameras at once.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | karimkohel |