Connect Your Built-in Webcam to Ubuntu 20.04 on a VirtualBox

ubuntu_20_04_linux

If you’re using Ubuntu 20.04 on a VIrtual Box on a Windows PC, follow the instructions below to make sure your installation recognizes your built-in webcam.

Go to this page, and make sure you download and install the latest version of Virtual Box.


Once you have done that, go to this page, and download the Virtual Box Oracle VM VirtualBox Extension Pack.

1-virtual-box-extension-pack

Click on the Oracle VM VirtualBox Manager.

Go to File -> Preferences.

Select “Extensions” in the Preferences menu.

2-select-extensions

Click the “Add a New Package” icon on the right-hand side.

3-add-a-new-package

Select the Virtual Box Oracle VM VirtualBox Extension Pack you downloaded earlier.

4-virtualbox-extension-packJPG

Click Open.

Click Install at the prompt.

5-click-install

Scroll to the bottom of the VirtualBox License and click “I Agree”.

Click Yes to make changes to your system.

After it has installed, you should see this message.

6-extension-pack-installed

Click OK twice to go back to the main panel.

Close the Oracle VM VirtualBox Manager.

Go back to Windows.

Launch the Command Prompt. Press the Win + R keys, then, type ‘cmd’ and Enter.

Go to the VirtualBox folder.

cd c:\Program Files\Oracle\VirtualBox

Check the list of available cameras by typing this command.

VBoxManage list webcams
7-list-of-webcams

I have 1 webcam available.

Attach the webcam (or webcams) you want to use. The number at the end of the line indicates the camera.

VboxManage controlvm "Ubuntu 20.04" webcam attach .1
8-attach-webcamJPG

Open the Oracle VM VirtualBox Manager.

Launch Ubuntu.

In the top of the VirtualBox in the upper-left, there is a Devices dropdown menu. See the image below, towards the top (it is a bit tough to see in this photo, but it is there in faint text)

9-devices-menu

Click Devices -> Webcams. Enable your webcam(s). When you enable it, a check mark should appear next to it. You’ll have to do this step each time you launch Ubuntu.

Open up a new terminal window in Ubuntu. Copy the code from this post into a new Python program. That code uses the OpenCV library, a popular library for computer vision. You can save it to your Desktop in Ubuntu.

To run the code, type:

echo 'export OPENCV_LOG_LEVEL=ERROR' >> ~/.bashrc

You only need to type that command once. It keeps a bunch of error messages from popping up each time you run the program. You are adding a line to your .bashrc file.

Now type:

python3 object_tracker.py

*Replace object_tracker.py with whatever you named your program.

You should see yourself on the webcam. Don’t worry about all the error messages that pop up in the terminal. If you see yourself on the webcam, everything is working fine.

10-webcam-on-linuxJPG