Run the following commands
- Installing required packages (last command is optional, run only if you want to test python version)
$ sudo apt-get install build-essential
$ sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
$ sudo apt-get install python-dev python-numpy libtbb2 libtbb-dev libjpeg-dev libpng-dev libtiff-dev libjasper-dev libdc1394-22-dev
- Downloading cmake
$ sudo add-apt-repository ppa:george-edison55/cmake-3.x
$ sudo apt-get update
$ sudo apt-get install cmake
$ cd ~
- Downloading opencv and contrib module
$ wget https://github.com/Itseez/opencv/archive/3.1.0.zip
$ wget -O opencv_contrib.zip https://github.com/Itseez/opencv_contrib/archive/3.1.0.zip
- Install nunpy also -
$ (sudo) pip install numpy
- Building OpenCV
$ unzip opencv.zip
$ unzip opencv_contrib.zip
$ cd opencv-3.1.0
$ mkdir release
$ cd release
$ cmake -D ENABLE_PRECOMPILED_HEADERS=OFF -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=OFF -D INSTALL_PYTHON_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib-3.1.0/modules -D BUILD_EXAMPLES=ON -D PYTHON_EXECUTABLE=/usr/bin/python3.5 ..
$ make
$ sudo make install
$ sudo ldconfig
In cmake command, update /usr/local/python3.5
according to your python version.