Webcam doesn't read through OpenCV but does with guvcview

淺唱寂寞╮ 提交于 2021-01-27 07:38:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!