[英]Python QueryFrame returns None, but C++ bindings work
In OpenCV 2.3.1 (built from source) on Ubuntu 10.04, the C++ fragment 在Ubuntu 10.04上的OpenCV 2.3.1(从源代码构建)中,C ++片段
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 将打开一个窗口并显示ThinkPad相机的视频,但是
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.) 失败(窗口是灰色的),因为
cv.QueryFrame
返回None
(并且笔记本电脑相机上的指示灯不亮。)
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. cv.QueryFrame
在显示.jpg
,所以这似乎是一个相机问题。
Found a workaround, via opencv+python+linux+webcam = cannot capture frames , which I'll leave here for posterity. 找到一个解决方法,通过opencv + python + linux + webcam =无法捕获帧 ,我将留下这些后代。
Install lib4vl
( apt-get install libv4l-dev
) and in the cmake
step of building OpenCV
, pass -D WITH_4VL=ON
. 安装
lib4vl
( apt-get install libv4l-dev
)并在构建OpenCV
的cmake
步骤中,传递-D WITH_4VL=ON
。 (I'd been building with that OFF.) (我一直在建造那个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. 为什么C ++在没有
lib4vl
的情况下lib4vl
但Python绑定要求它与网络摄像头一起工作是一个难题,也许一些OpenCV知识渊博的人可以解释。 I'd love to hear an explanation. 我很乐意听到解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.