OpenCV on a MacBookPro (using an Ubuntu virtual machine)

When I started my research project on computer vision I didn’t expect the bunch of things that need to be done in order to write programs with OpenCV on a mac computer.

Because the final objective of this project is to have some CV programs running on a tiny Linux computer, the development has to be done also on a Linux environment to ensure the code is compatible all the time.

Before starting, I advise I’m not an expert in any of the processes involved in this explanation. This is intended to be a summary of the steps and tutorials I followed to set up my research and development environment for my research project.


Step 1: Create a virtual machine.

For creating the virtual machine we will use VirtualBox. It is open source software with lots of documentation available and relatively easy to use and understand.

Download the latest version of VirtualBox for OS X hosts from its site and install it.

Download Ubuntu Desktop 14.04 LTS from its site. Downloading LTS (long time support) ensures it will be regularly updated for a long time (several years).

Launch VirtualBox and click on “New“. A step by step popup will prompt you some basic configurations for the new virtual machine.

  1. Type a name and select «Type: Linux» and «Version: Ubuntu (64 bit)».Captura de pantalla 2014-07-14 a la(s) 15.35.51

  2. Select memory size (this can be changed later on), around 1000 MB will do the work for the moment.Captura de pantalla 2014-07-14 a la(s) 15.41.02

  3. Create a virtual hard disk.

    Leave all the option by default until you get to the following screen. It is important that your virtual disk is big enough for storing all the programs and data you are going to generate when using the VM. Changing the virtual disk size once created is not an easy procedure (this threat discuses some methods for doing that)Captura de pantalla 2014-07-14 a la(s) 15.44.57

  4. Install the Ubuntu OS.

    Once you clic on create your virtual machine will be created, with no operating system installed on it yet. Double click on the icon of the new VM and it will start and prompt you for a virtual optical disk drive to boot from. Click on the folder icon and browse to the Ubuntu image you downloaded before.Captura de pantalla 2014-07-14 a la(s) 15.53.25

  5. Follow the Ubuntu installation process, which is pretty straightforward.


Once you are finished installing Ubuntu you may notice some trouble with the resolution. To solve this and get some other features (like shared clipboard) you will need to install the guest additions.

  1. Turn on the virtual machine if it is not.

  2. Insert guest additions’ virtual installation CD.

    On the menu bar (mac) go to devices/”Insert Guest Additions CD Image” or press cmd+D.

  3. Install guest additions.

    A CD icon will appear on the applications bar on Ubuntu and a message should appear prompting you to automatically run some program. Clic on “Dismiss”. And follow the instructions from the VirtualBox manual (section 4.2.2.1.1).

  4. Restart.

    After the installation has completed you will need to restart the machine. Once restarted Ubuntu should adapt its resolution to your screen’s resolution.Virtual machine correct resolution

Now you have your virtual machine up and running and you are ready to install OpenCV.


Step 2: Install OpenCV.

Now we will work entirely on the virtual machine.

I followed this excellent guide to install OpenCV 2.4.9 on Ubuntu 14.04.

The make command can take several hours, depending on the computer


Step 3: Install Eclipse IDE.

Download Eclipse for C/C++ developers for Linux (64 bit).

In order to run Eclipse you will need to install Java (extracted from ENQLU):

On a Terminal window paste:

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer

When the Java installation is complete you can then go to the Eclipse folder and double click on the executable to launch it.


Step 4: Tell Eclipse where the OpenCV libraries are.

For this step I followed the instructions from the OpenCV site and they worked without problems.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s