Skip to content


Installing OpenCV 3.2.0 with contrib modules in Ubuntu 16.04 LTS

OpenCV 3.2.0 has been out for a while and contains many improvements and exciting new features, so it’s time to update this guide using the latest Ubuntu 16.04LTS.

A big change in OpenCV 3.2.0 is that now many of the newest algorithms now reside separately in the contrib repository.

Some of these modules include Face Recognition, RGB-Depth processing, Image Registration, Saliency, Structure From Motion, Tracking, and much more.

So let’s install OpenCV 3.2.0 with the contrib modules and other good stuff by executing the following code on the command line:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff5-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen3-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev default-jdk ant libvtk5-qt4-dev
cd ~
mkdir opencv
cd opencv
wget https://github.com/opencv/opencv/archive/3.2.0.tar.gz
tar -xvzf 3.2.0.tar.gz
wget https://github.com/opencv/opencv_contrib/archive/3.2.0.zip
unzip 3.2.0.zip
cd opencv-3.2.0
mkdir build
cd build
cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D WITH_VTK=ON .. -DCMAKE_BUILD_TYPE=RELEASE -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-3.2.0/modules ..
make
sudo make install
echo '/usr/local/lib' | sudo tee --append /etc/ld.so.conf.d/opencv.conf
sudo ldconfig
echo 'PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig' | sudo tee --append ~/.bashrc
echo 'export PKG_CONFIG_PATH' | sudo tee --append ~/.bashrc
source ~/.bashrc

Now you should be able to compile with the OpenCV libraries, including the contrib repositories.

For example, let’s compute some Fine-Grained Saliency, which is available in the saliency module of the contrib repository:

cd ~
mkdir saliency
cd saliency
cp ../opencv/opencv_contrib-3.2.0/modules/saliency/samples/computeSaliency.cpp .
cp ../opencv/opencv-3.2.0/samples/data/Megamind.avi .
g++ -o computeSaliency `pkg-config opencv --cflags` computeSaliency.cpp `pkg-config opencv --libs`
./computeSaliency FINE_GRAINED Megamind.avi 23

Original Image:

Computed Saliency:

Posted in Image Processing, Open Source, Programming.


4 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. xs.yan says

    After installing opencv I run the python samples code:

    cd /samples/python/
    python asift.py

    and I get the following error:

    Traceback (most recent call last):
    File “asift.py”, line 26, in
    import cv2
    ImportError: /usr/local/lib/libopencv_freetype.so.3.2: undefined symbol: hb_shape

    Running other python samples will get the same error. I haven’t found the answer in google. How do I fix it?

Continuing the Discussion

  1. Installing OpenCV 2.4.9 in Ubuntu 14.04 LTS – Sebastian Montabone linked to this post on June 4, 2017

    […] UPDATE: You can also install OpenCV 3.2.0 in Ubuntu 16.04LTS. […]

  2. Installing OpenCV 2.1 in Ubuntu – Sebastian Montabone linked to this post on June 4, 2017

    […] UPDATE: You can also install OpenCV 3.2.0 in Ubuntu 16.04LTS. […]

  3. Installing OpenCV 2.2 in Ubuntu 11.04 – Sebastian Montabone linked to this post on June 4, 2017

    […] UPDATE: You can also install OpenCV 3.2.0 in Ubuntu 16.04LTS. […]



Some HTML is OK

or, reply to this post via trackback.