VIDIOC_QBUF error causing webcam image tearing
Hello everyone!
I am trying to have a webcam stream video using OpenCV. I'm using the basic camera.py python code to access it.
The image is generally very good, but there is frequently a frame in which there is image tearing. At the same time, I get an error in terminal: "VIDIOC_QBUF: Invalid argument". Additionally, on initial startup, I get about 5-15 errors stating: "VIDIOC_QUERYMENU: Invalid argument"
The strangest part about this is that I may occasionally get an "Input/Output Error" in terminal. Once this occurs, the video streams perfectly with no more tearing.
I am using the Logitech C270 Webcam on the Raspberry Pi. Using different resolutions does not help the problem.
Code:
import cv2.cv as cv
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(-1)
cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_WIDTH, 320)
cv.SetCaptureProperty(capture,cv.CV_CAP_PROP_FRAME_HEIGHT, 240)
while True:
img = cv.QueryFrame(capture)
cv.ShowImage("camera", img)
if cv.WaitKey(30) == 27:
break
I believe the "VIDIOC_QUERYMENU" error messages are coming from v4l - video 4 linux - driver. I've personally never been able to resolve them, but aside from those error messages on start up the image capturing works fine.