5 Simple and Easy steps for Installation of OPENCV

Ankit Gupta
Analytics Vidhya
Published in
3 min readAug 23, 2018
Lets …………………OpenCV

Introduction

Setting up the system can sometimes seem a little complicated. For the same reason I decided to share a small tutorial on Installation of OpenCV. In this tutorial we will learn to setup OpenCV-Python in Ubuntu System. Below steps are tested for Ubuntu 16.04 (64-bit) and Ubuntu 14.04 (32-bit). Let’s get started!

OpenCV — Python can be installed in Ubuntu in two ways:

1.Compile from the source.

2.Install from pre-built binaries available in Ubuntu repositories.

1. Building OpenCV From Source

Required build Dependencies

First of all we need CMake to configure the installation, GCC for compilation, Python-devel and Numpy for building Python bindings etc. Here are the commands you need to run.

1. sudo apt-get install cmake2. sudo apt-get install python-devel numpy3. sudo apt-get install gcc gcc-c++

Next we need GTK support for GUI features, Camera support (libv4l), Media Support (ffmpeg, gstreamer) etc.

1.sudo apt-get install gtk2-devel2. sudo apt-get install libv4l-devel3. sudo apt-get install ffmpeg-devel4. sudo apt-get install gstreamer-plugins-base-devel

2. Optional Dependencies

Above dependencies are sufficient to install OpenCV in your Ubuntu machine. But depending upon your requirements, you may need some extra dependencies. A list of such optional dependencies are given below. You can either leave it or install it, your call :)

OpenCV comes with supporting files for image formats like PNG, JPEG, JPEG2000, TIFF, WebP etc. But it may be a little old. If you want to get latest libraries, you can install development files for system libraries of these formats.

1. sudo apt-get install libpng-devel2. sudo apt-get install libjpeg-turbo-devel3. sudo apt-get install jasper-devel4. sudo apt-get install openexr-devel5. sudo apt-get install libtiff-devel6. sudo apt-get install libwebp-devel

3. Downloading OpenCV

To download the latest source from OpenCV’s GitHub Repository.

1. sudo apt-get install git2. git clone https://github.com/opencv/opencv.git

It will create a folder “opencv” in current directory.

After then Now open a terminal window and navigate to the downloaded “opencv” folder. Create a new “build” folder and navigate to it.

1. cd ~/opencv2. mkdir build3. cd build

4. Configuring and Installing

Now we have all the required dependencies, let’s install OpenCV.

1. cmake ../

You should see these lines in your CMake output (they mean that Python is properly found):

— Python 2:— Interpreter: /usr/bin/python2.7 (ver 2.7.6)— Libraries: /usr/lib/x86_64-linux-gnu/libpython2.7.so (ver 2.7.6)— numpy: /usr/lib/python2.7/dist-packages/numpy/core/include (ver 1.8.2)— packages path: lib/python2.7/dist-packages— Python 3:— Interpreter: /usr/bin/python3.4 (ver 3.4.3)— Libraries: /usr/lib/x86_64-linux-gnu/libpython3.4m.so (ver 3.4.3)— numpy: /usr/lib/python3/dist-packages/numpy/core/include (ver 1.8.2)— packages path: lib/python3.4/dist-packages

Now you build the files using “make” command and install it using “make install” command.

1. make2. sudo make install

5. Installation is over

All files are installed in “/usr/local/” folder. Open a terminal and try import “cv2”.

1. import cv2 as cv2. print(cv.__version__)

Thank you for reading. Please Clap and Follow for More, Easy and Interesting Articles.

--

--