The image processing library

In the previous section, you understood about image processing and its applications. To develop your image processing algorithms, you require some infrastructure/library or you would end up doing everything from scratch by yourself. In this book, we will use the OpenCV library for writing/developing image processing algorithms. OpenCV stands for open source computer vision. It has played a role in the growth of computer vision by enabling thousands of people to do more productive work in vision. With its focus on real-time vision, OpenCV helps students and professionals efficiently implement projects and jump-start research by providing them with a computer vision and machine learning infrastructure that was previously available only in a few mature research labs.

Introduction to OpenCV

OpenCV is the world's most popular open source computer vision library, which contains over 500 functions that span many areas in vision as well as robotics. The library is written in C and C++ and it runs under all three major platforms, that is, Linux, Windows, and Mac OS X. It was designed for computational efficiency and with a strong focus on real-time applications. Today, whenever you talk about computer vision, machine learning will come into play some or the other way and vice versa. Because of the same reason, OpenCV contains a full, general purpose Machine Learning Library (MLL).

Note

Machine learning is an area of computer science that deals with the construction and study of algorithms that can be learned from data.

OpenCV is broadly structured into five main components that are mentioned in the following table:

Component Name

Capabilities

CV

Image processing and higher-level computer vision algorithms

MLL

Machine Learning Library contains many statistical classifiers and clustering tools

HighGUI

GUI, Image, and Video I/O

CXCORE

Basic structures and algorithms, XML support, and drawing functions

CvAux

Background-foreground segmentation, Eigen objects, and Stereovision

Although the preceding table explained the core components of OpenCV, researchers and scientists who extensively use OpenCV talk in the language of OpenCV modules. The following table contains a brief description of important modules:

Module

Feature

Core

This is a compact module defining basic data structures, including the dense multidimensional array, Mat, and the basic functions used by all other modules

Imgproc

This is an image processing module that includes linear and nonlinear image filtering, geometrical image transformations (resizing, affine and perspective warping, and generic table-based remapping), color space conversion, histograms, and so on

Video

This is a video analysis module that includes motion estimation, background subtraction, and object tracking algorithms

Calib3d

This consists of basic multiple-view geometry algorithms, single and stereo camera calibration, object pose estimation, stereo correspondence algorithms, and elements of 3D reconstruction

Features2d

This consists of salient feature detectors, descriptors, and descriptor matchers

Objdetect

The features include detection of objects and instances of the predefined classes; for example, faces, eyes, mugs, people, and cars

Highgui

This is an easy-to-use interface for video capturing, image and video codecs as well as simple UI capabilities

GPU

The features of GPU include GPU-accelerated algorithms from different OpenCV modules

OpenCV is distributed with a BSD license, which means that you can make a commercial application without revealing your source code. However, there are a few algorithms, despite being provided with complete source code inside OpenCV, which are patented.

Installation

This section will cover the installation procedure for Raspbian OS. As Raspbian OS is built on top of the Linux kernel, you will be able to install OpenCV on Raspberry Pi. Newer versions of the OpenCV library are released periodically. For the purpose of this book, the 2.4.1 (the first approach) and 2.4.10 (the second approach) versions have been the reference.

The first approach

If you are not interested in installing the latest version of OpenCV, you can install it from the software repositories by running the following command in the terminal:

sudo apt-get update
sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools python-pip
sudo apt-get install libopencv-dev
sudo apt-get update

Check the OpenCV version:

pkg-config --modversion opencv

The second approach

Use this approach if you want the latest/specific version of OpenCV. In this approach, OpenCV will be built from the source and you will have to install the dependencies prior to this:

sudo apt-get -y install build-essential cmake cmake-curses-gui pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools libeigen3-dev

sudo apt-get -y install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs ffmpeg libavcodec-dev libavcodec53 libavformat53 libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev libxine1-ffmpeg libxine-dev libxine1-bin libunicap2 libunicap2-dev swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev

Don't worry if you don't understand what these lines mean. Once you have installed the dependencies, download the latest version of OpenCV from http://opencv.org/downloads.html (download OpenCV for Linux). Copy the opencv-2.4.10.zip to /home/pi directory and run the following commands:

unzip opencv-2.4.10.zip
cd opencv-2.4.10
mkdir release
cd release
ccmake ../

Press g to generate a file. And finally, you need to build the OpenCV library and run the following command:

make
sudo make install

Please note that this build usually takes more time (around 10 hours) on Raspberry Pi. That's it. OpenCV is now installed on Raspberry Pi.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.55.42