What is OpenCV?

OpenCV (Open Source Computer Vision Library) is an Open Source Library for computer vision, machine learning and image processing. You can use OpenCV with multiple programming languages like Python, Java, C++. OpenCV can be used to process the images, identify objects, face detection, real-time traffic monitoring, lane detection for automation cars, text detection and many more AI and AR use cases.

Install OpenCV in CentOS
Opencv can be install in CentOS in two ways:

1) Install from available yum repository.
But till the time of writing this post opencv-2.0.0 repository are available. If you need latest version of opencv then go for 2. option.
2) Opencv installation from source.

1) Install opencv from yum repo
Before installation of opencv-python from yum repository we have to install require library numpy.

$ sudo yum install python-devel python-nose python-setuptools gcc gcc-gfortran gcc-c++ blas-devel lapack-devel atlas-devel
$ sudo easy_install pip
$ sudo pip install numpy==1.6.1

If you haven’t installed opencv rpm then you can download from here and install it first . After installation of rpm now opencv will be available for installation.

$ yum install opencv

2) Installing Opencv from Source:
To install opencv from we need to install require and optional dependencies.

  • CMake : For configure the opencv installation.
  • Python-devel and Numpy : For Creating python extension.
  • GCC: For compilation.
$ yum install cmake
$ yum install python-devel numpy
$ yum install gcc gcc-c++

Install GTK To support GUI features, Camera support (libdc1394, libv4l), Media Support (ffmpeg, gstreamer) etc.

$ yum install gtk2-devel
$ yum install libdc1394-devel
$ yum install libv4l-devel
$ yum install ffmpeg-devel
$ yum install gstreamer-plugins-base-devel

Optional Dependencies:
Install below pakcages if you need latest libraries of PNG, JPEG, JPEG2000, TIFF, WebP.

$ yum install libpng-devel libjpeg-turbo-devel jasper-devel openexr-devel libtiff-devel libwebp-devel

Now we have finish the first step of opencv installation. In next step download the opencv source from git repository.

$ yum install git
$ mkdir opencv-build
$ cd opencv-build
$ git clone https://github.com/Itseez/opencv.git
$ cd opencv
$ git checkout tags/2.4.8.2

Create a new directory build to compile opencv from source.

$ mkdir build
$ cd build
$ cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..
$ make
$ sudo make install

Above installation will install package in /usr/local/lib . To use this we need to copy site-packages from /usr/local/lib to /usr/lib.
Move opencv module from in defult python path:

$ cp /usr/local/lib/python2.7/site-packages/cv2.so /usr/lib/python2.7/site-packages

Verify Installation:

$ python
>>> import cv2
>>> print cv2.__version__

That’s it 🙂

(Visited 1,019 times, 32 visits today)