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.
Click on the Oracle VM VirtualBox Manager.
Go to File -> Preferences.
Select “Extensions” in the Preferences menu.
Click the “Add a New Package” icon on the right-hand side.
Select the Virtual Box Oracle VM VirtualBox Extension Pack you downloaded earlier.
Click Install at the prompt.
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.
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
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
Open the Oracle VM VirtualBox Manager.
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)
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.
*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.