简体   繁体   English

OpenCV的。 如何在VirtualBox中连接相机

[英]OpenCV. How to connect to camera in VirtualBox

I have a Ubuntu vm in Oracle VirtualBox (Host: Mac OS X) with installed python (miniconda), opencv and built-in web camera connected to vm with Devices > Webcams menu. 我在Oracle VirtualBox(主机:Mac OS X)中安装了Ubuntu vm,并已安装python(miniconda),opencv和通过“设备”>“ Webcams”菜单连接到vm的内置网络摄像头。 If I try to test my webcam in sites like this , it works good, but if I try to connect to camera with opencv from python in this way: 如果我尝试测试我的摄像头在像网站这样 ,它的作品不错,但如果我尝试使用OpenCV的蟒蛇连接到相机中这样说:

>>> import cv2
>>> cap = cv2.VideoCapture(0) # or 1 or -1, I tried all
>>> ref, frame = cap.read()
>>> frame.shape

I have an error "NoneType has not attribute shape". 我有一个错误“ NoneType没有属性形状”。 How can I solve this problem? 我怎么解决这个问题?

This is possible, but requires a few steps to get working properly: 这是可能的,但是需要一些步骤才能正常工作:

1.Make sure the virtual machine is not running and your webcam is not being used. 1.确保虚拟机未运行且未使用网络摄像头。

2.Bring up the main VBox window and in the details tab for your Win7 machine click USB. 2.打开主VBox窗口,在Win7计算机的详细信息选项卡中,单击USB。

3.Make sure "Enable USB Controller" is selected. 3.确保已选择“启用USB控制器”。 Also make sure that "Enable USB 2.0 (EHCI) Controller" is selected too. 还要确保也选择了“启用USB 2.0(EHCI)控制器”。

4.Click the "Add filter from device" button (the cable with the '+' icon). 4.单击“从设备添加过滤器”按钮(带有“ +”图标的电缆)。

5.Select your device from the list. 5.从列表中选择您的设备。

6.Now click OK and start your VM. 6.现在单击确定,然后启动您的VM。

  1. In terminal type VBoxManage list webcams . 在终端中,输入VBoxManage list webcams This will return the following output: 这将返回以下输出:

Video Input Devices: 1 视频输入设备:1

.1 "FaceTime HD Camera" .1“ FaceTime高清摄像机”

0x8020000005ac8514 0x8020000005ac8514

  1. In terminal type VboxManage controlvm "my_virtual_machine_name" webcam attach .1 . 在终端中,输入VboxManage controlvm "my_virtual_machine_name" webcam attach .1 where .1 is the designation of Virtualbox's Video Input Devices . 其中.1是Virtualbox的Video Input Devices

This will cause the device to show up as if it were plugged into the VM. 这将导致设备显示为好像已插入虚拟机。 From there, you should be able to use it or install drivers if necessary. 从那里,您应该能够使用它或在必要时安装驱动程序。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM