Reputation: 24966
In OpenCV 2.3.1 (built from source) on Ubuntu 10.04, the C++ fragment
cvNamedWindow("Camera", 1);
CvCapture* capture = cvCaptureFromCAM(CV_CAP_ANY);
while (1) {
IplImage* frame = cvQueryFrame(capture);
cvShowImage("Camera", frame);
key = cvWaitKey(10);
...
will open up a window and show video from my ThinkPad camera, but
import cv2.cv as cv
# or import cv
cv.NamedWindow("Camera", 1)
capture = cv.CaptureFromCAM(-1)
while True:
frame = cv.QueryFrame(capture)
cv.ShowImage("Camera", frame)
key = cv.WaitKey(10)
...
fails (the window is gray), because cv.QueryFrame
returns None
(and the light on the laptop camera doesn't come on.)
Any idea what may be going on here (and how I might remedy it)? cv.QueryFrame
works when displaying .jpg
, so this seems to be a camera issue.
Upvotes: 1
Views: 715
Reputation: 24966
Found a workaround, via opencv+python+linux+webcam = cannot capture frames, which I'll leave here for posterity.
Install lib4vl
(apt-get install libv4l-dev
) and in the cmake
step of building OpenCV
, pass -D WITH_4VL=ON
. (I'd been building with that OFF.)
Why C++ works without lib4vl
but the Python bindings require it to work with a webcam is a puzzle, which perhaps some OpenCV-knowledgable person can explain. I'd love to hear an explanation.
Upvotes: 3