Install latest OpenCV on Ubuntu
OpenCV maintains latest OpenCV source code on github. Stable code is available on the main branch. To install latest OpenCV on Ubuntu 16, clone the OpenCV git project and build it locally using cmake. In this tutorial, we shall present a step by step process to install OpenCV on your Ubuntu 16 machine. The process should hold true for Ubunut 14 or other latest Ubuntu varients.
Steps to install OpenCV on Ubuntu
Following is the step by step process.
Step 1: Update Ubuntu packages.
$ sudo apt-get update
Step 2: Install packages and tools required for building OpenCV.
$ sudo apt-get install libopencv-dev build-essential checkinstall cmake pkg-config yasm libtiff4-dev libtiff5-dev libjpeg-dev libjasper-dev libavcodec-dev libavformat-dev libswscale-dev libdc1394-22-dev libxine2-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libv4l-dev python-dev python-numpy libtbb-dev libqt4-dev libgtk2.0-dev libfaac-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev x264 v4l-utils ffmpeg
Note: If you are installing on Ubuntu 16, you may get error for libtiff4-dev package. Please ignore. This package is for Ubuntu 14.
Step 3: Clone OpenCV Git repository for source code.
$ mkdir OpenCV
$ cd OpenCV
$ git clone https://github.com/opencv/opencv.git
The first two commands are for creating a new directory for OpenCV and navigating to the directory.
Cloning into 'opencv'...
remote: Counting objects: 224315, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 224315 (delta 0), reused 0 (delta 0), pack-reused 224311
Receiving objects: 100% (224315/224315), 439.82 MiB | 1.33 MiB/s, done.
Resolving deltas: 100% (155909/155909), done.
Checking connectivity... done.
Checking out files: 100% (5770/5770), done.
A folder named opencv is created inside OpenCV.
Step 4: Build OpenCV from Source.
Create a directory called release, for compiled files to go into.
$ cd opencv
$ mkdir release
$ cd release
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -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 ..
You may get lot of debug lines, but at the end, you may notice following :
-- Configuring done
-- Generating done
-- Build files have been written to: /media/arjun/0AB650F1B650DF2F/softs/OpenCV/opencv/release
Step 5: Make and Install the build.
$ make
$ sudo make install