python opencv:没有图像
我正在尝试从 Sony Handicam DCR-HC38 进行捕获,运行下面的代码,并将 [-1 .. 3] 传递给 CaptureFromCAM 函数。代码运行,但我没有得到图像。我需要以某种方式“包裹”相机吗? Skype 可以识别摄像头,但 python/opencv 不会。我正在运行 Windows Vista(如果有帮助的话)。
import cv
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(-1)
while True:
img = cv.QueryFrame(capture)
cv.ShowImage("camera", img)
if cv.WaitKey(10) == 27:
break
I am trying to capture from a Sony Handicam DCR-HC38, running the code below, and passing [-1 .. 3] to the CaptureFromCAM function. The code runs, but I get no image. Do I need to "wrap" the camera somehow? Skype recognizes the camera, but python/opencv won't. I'm running Windows Vista if that helps any.
import cv
cv.NamedWindow("camera", 1)
capture = cv.CaptureFromCAM(-1)
while True:
img = cv.QueryFrame(capture)
cv.ShowImage("camera", img)
if cv.WaitKey(10) == 27:
break
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试增加 cv.WaitKey 的延迟
try increasing the delay on the cv.WaitKey
不确定你是否修复了它。但我想出的解决方案是检查 OpenCv 正在尝试访问哪个驱动程序...我有 v4l1 和 v4l2,但是我只能通过使用 gstreamer 编解码器和我的 lenovo x200 上的 v4l2 驱动程序来访问设备 /dev/video0 (内部)网络摄像头)使用 ubuntu 10.10。所以我必须从源代码重新编译Opencv,首先应用在以下位置找到的补丁:
Opencv-2.0.0.link.v4l2.patch
将补丁解压到 opencv 根目录:然后打开终端并 cd 到 opencv 根目录,然后执行以下操作:
然后:
现在您的 opencv 库应该访问 v4l2 驱动程序,希望这对某人有帮助
not sure if you fixed it or not. But the solution I figured out is by checking which driver OpenCv is trying to access... I have both v4l1 and v4l2, however I can only access device /dev/video0 by using gstreamer codec and the v4l2 driver on my lenovo x200 (internal webcam) using ubuntu 10.10. So I had to recompile Opencv from source, by firstly applying the patch found at:
Opencv-2.0.0.link.v4l2.patch
extract the patch to your opencv root directory: then open terminal and cd to the opencv root directory, and do the following:
then:
Now your opencv libraries should access the v4l2 driver instead, hope this helps someone