Reputation: 31
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. 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:
>>> 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". How can I solve this problem?
Upvotes: 2
Views: 6192
Reputation: 17358
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.
2.Bring up the main VBox window and in the details tab for your Win7 machine click USB.
3.Make sure "Enable USB Controller" is selected. Also make sure that "Enable USB 2.0 (EHCI) Controller" is selected too.
4.Click the "Add filter from device" button (the cable with the '+' icon).
5.Select your device from the list.
6.Now click OK and start your VM.
VBoxManage list webcams
. This will return the following output:Video Input Devices: 1
.1 "FaceTime HD Camera"
0x8020000005ac8514
VboxManage controlvm "my_virtual_machine_name" webcam attach .1
. where .1
is the designation of Virtualbox's 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.
Upvotes: 3