USB 2.0 camera error on Virtual Machine (Virtual Box, VMWare) in Open CV

How to use Open CV inside virtual machine

As who loves embedded system development and Image processing all together, I decided to run my Open CV programs on an embedded Linux systems. For my private experiments I decided to develop Linux embedded on a virtual machine Linux environment. Here is the procedures I have experimented during the setup time of the development environment.

Linux embedded development on virtual Linux system and the issue of webcam driver when using USB camera on Guest Ubuntu OS

For development I decided to use Linux virtual machine inside my windows PC and using virtual machine to run Ubuntu OS. As virtual box is a powerful free virtual machine, at first I chose it because it is totally free. After installation and communicating with the embedded board everything went good such as COM port virtual box ( communicating with the device connected to the actual PC COM port) and etc but when I captured from the USB camera the following error occurred:

libv4l2: error turning on stream: Input/output error
VIDIOC_STREAMON: Input/output error

I didn't find the source of the error but I think that was because of webcam driver for the USB camera on Linux virtual machine software. I have searched a lot about Linux virtual machines and problem with USB cameras and I found out that other have had trouble with connecting the USB camera to virtual box specially when the PC has USB 3.0 ports (as mine).

I had two cameras: Realteck USB Camera and the Silicon Motion SMI camera. Both were detected by the application as a capturing device but after reading the frame from the device that error occurred.

As I did not find the right solution for the Virtual Box,  I tried my existed alternative option that was Setting up the Linux inside best virtual machine I have ever used, VMWare. Its free for non commercial use VMWare Player 6 was enough for my experiments ( so no need for VM Ware workstation)

Installing Linux on a physical partition (to ensure always having a Linux machine at hand)

As I had experienced difficulties for communicating with devices from inside of a virtual machine, I decided to install a Linux Machine on a physical drive (so I'm sure I have a working machine that can communicate with devices) then I tried to find how to make virtual machine from physical machine.  I have loaded that inside a VM by adding the physical Partition *root* as a hard disk for the VM machine and convert by VMWare Linux physical to virtual.

The procedure is as following:

  • Make a New Virtual Machine and with a default virtual hard disk and choose I will install the OS later.
  • Before starting the VM Click the "VM" menu at the top of the virtual machine window and click "Settings."
  • Select the virtual HDD just created and remove it.
  • Click "Add" to add a new HDD.
  • Click "Hard Disk" in the "Hardware Type" window and click "Next."
  • Virtual Machine from Physical Partition-Add Hardware Wizard to add HDD
  • Click "IDE" in the "Select a Disk Type" window and click "Next".
  • Select IDE - Add hardware wizard - Virtual machine from physical partition
  • Click "Use a Physical Disk (For Advanced Users)" and click "Next."
  • VM ware Virtual Machine from a Physical Partition-Add Hardware Wizard- select a disk
  • Click the "Device" box and click the physical drive's name in the list and in the "Usage" section choose "Use entire disk" if you have a separate HDD for the Linux or choose "Use Individual Partitions" if you have installed the Linux on another partition on the same HDD that your current OS is.
  • VM ware Virtual Machine from a Physical Partition-Add Hardware Wizard - select a physical disk
  • If you have chosen "Use Individual Partitions", then now you should point to the partition name that contains the Linux Root file system.
  • VM ware Virtual Machine from a Physical Partition-Add Hardware Wizard - Select root partition
  • After that choose a name for the file that stores the configuration you have made and click "Next".
  • VM ware Virtual Machine from a Physical Partition-Add Hardware Wizard - File to store configurations
  • Click "Finish."
  • Start the VMware virtual machine by double-clicking it in the VMware window.

Installing Open CV on the Linux machine and running the project

I have done opencv download on ubuntu and after installing open cv ,  I ran the project but the following error occurs:

libraries: cannot open shared object file: No such file or directory

  • I added a file in : /etc/ 
  • And named it : opencv.conf
  • And I also added the path of file in that file (without "").  
  • Finally I ran :sudo ldconfig -v and problem resolved .


After running the application the program has this error:

select timeout

and the screen of image is black for Realteck USB Camera. The other Silicon Motion SMI camera has a frame that was not stabilized at all.

I also opened Cheese Webcam Boost app and the screen was black for first camera and not stabilized for the next camera at all.

for resolving this problem

  • I have change the usb setting in VM ware settings and make it to support USB 3.0.
  • On the other hand I attached the camera to a USB 2.0 port and that works both of them works fine.
USB Controller Settings - VM Ware


Connecting the board using RS 232 serial port on VM ware

After installing the Linux and checking the capturing device and successful frame gathering, I have noticed that I cannot access the device using the rs 232 serial port. I have checked the VM com port and I didn't find anything to change for com port vmware player. It seems that com ports of physical computer to virtual machine are correctly forwarded. 

I finally tried to connect to the device on another serial port on Linux, I mean ttyS1 instead of ttyS0. I have tried ttyS0 and everything goes fine.