Installing OpenCV 3.3.0 on Ubuntu 16.04 LTS

  1. Get Ubuntu update.

First of starting this we need to make sure and update Ubuntu before doing any thing else, which is:

$ sudo apt-get update && sudo apt-get upgrade && sudo apt-get autoremove

2. Install all the recommended packages.

Compilers

$ sudo apt-get install build-essential

Required:

$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev

And recommended optional package:

$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
$ sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
$ sudo apt-get install libxvidcore-dev libx264-dev
$ sudo apt-get install libgtk-3-dev
$ sudo apt-get install libatlas-base-dev gfortran
$ sudo apt-get install python2.7-dev python3.5-dev

3. Setup you enviroment

We are going to install pip and virtual environment manager packages in python:

$ sudo apt-get install python-pip && pip install --upgrade pip

We install virtualenv and virtualenwrapper :

Then wee need to add some line to .bashr file:

add the following lines to the bottom of the content of the file:

Then save the file, go back to terminal. Run this line:

This line is to activate/apply what we have done to the .bashrcfile, which finalizes the installation of virtualenv and virtualenvwrapper.

Next, we need to create a virtual enviroment for OpenCV, that we are going to call it cv:

If you restart or accidentally close the terminal, type the command below:

the last package to install is numpy.

4. Download OpenCV source

We need to clone the latest release of OpenCV.

5. Configuring and compiling

We need to build using cmake:

Then we need to compile OpenCV while you are in the build folder:

  • where jx where x are the number of process you want to dedicate to this operation.

Finally we need to install openCV:

6. Finishing OpenCV installation

There are some work remaining so everything is done. Lets look at the ouput of our work so far:

At the output you will see a file that start with the name of cv2.cpython. We need to move it back to site-packages and rename it to cv2.so:

To have OpenCV working in our virtual environment, we create a sym-link of the file to our site-package folder in the virtual environment.

Finally we need to download

Last updated

Was this helpful?