问题
I have a webcam of sorts that is quite old. I've been attempting to get it to work. I started out with guvcview which works, however it only gives me the first frame captured then stops. That's fine for now.
I'm trying to recreate this behaviour using OpenCV. I'm on linux and using python. It is my understanding that my best bet here is to have OpenCV use v4l2 which is what guvcview is using.
My long term idea is to get the first frame only, but do this in a loop to sort of get "video" but at a low frame rate.
However, with my very simple program below, I get the following errors:
import cv2
cap = cv2.VideoCapture(0)
ret, frame = cap.read()
if frame:
cv2.imshow("frame", frame)
I execute this code in a loop till it shows me something. The errors I get:
select timeout
VIDIOC_DQBUF: Resource temporarily unavailable
VIDIOC_QBUF: Invalid argument
I will sometimes get the same errors with guvcview, but a simple relaunch of the program will fix it. Note that guvcview does not work while my program is running (even if no image is shown). Also note that the read() function takes a few seconds to return.
来源:https://stackoverflow.com/questions/56177039/webcam-doesnt-read-through-opencv-but-does-with-guvcview