Problems using webcam in python + openCV

I am using the following code to access a webcam using openCV + python ...

import cv

cv.NamedWindow('webcam_feed', cv.CV_WINDOW_AUTOSIZE)

cam = cv.CaptureFromCAM(-1)

Then I get the following error in the console ...

VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument
VIDIOC_QUERYMENU: Invalid argument

I originally used

cv.CaptureFromCAM(0)

to access the same and have the same problem and use -1, because it is assumed that it picks up any webcam.

I also tested if Ubuntu recognizes a webcam, and it does. I am using v4l2 for webcam.

{EDIT}

I am using the following code to display a video stream, it seems to display only one image captured by a webcam, instead of a continuous video stream ...

import cv
cv.NamedWindow('webcam_feed', cv.CV_WINDOW_AUTOSIZE)
cam = cv.CaptureFromCAM(-1)
feed = cv.QueryFrame(cam)
cv.ShowImage("webcam_feed", feed)
cv.WaitKey(-1)
+5
source share
3 answers

WOW, 15 , . , , - -...

cv.WaitKey(-1)

. 10...

cv.WaitKey(10)

. 100, . , 1000. 1, , .

-

import cv

cv.NamedWindow("webcam", 1)

cam = cv.CaptureFromCAM(-1)

While True:
feed = cv.QueryFrame(cam)
cv.ShowImage("webcam", feed)
cv.WaitKey(1)
+1

,

frame = cv.QueryFrame(cam)
cv.ShowImage("Webcam Feed", frame)

, . cv.QueryFrame , .

, cv.WaitKey .

0

root

xhost +

, , .

.

0

All Articles