OpenCV installation on Raspberry Pi 2

The Open Source Computer Vision Library (OpenCV) is a comprehensive computer vision library and machine learning (over 2500 functions) written in C and C++ with additional Python and Java interfaces. It officially supports Linux, Mac OS, Windows, Android and iOS. Now we are here to deploy OpenCV on Raspberry Pi 2 to make it as portable image processing device.Here I have a quick view that how I installed OpenCV on Raspberry Pi 2.

 

Pi2ModB1GB_-comp

Prerequisites

Run the following commands to install required packages: Nearly it takes around 15 mins to install the packages, again it depends on your internet speed ­čÖé

sudo apt-get update

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

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 libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev python-numpy libpython2.6 python-dev python2.6-dev libgtk2.0-dev pkg-config 

Source File:

Enter the following command in the terminal.

sudo wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2

Once you had finished downloading the file, extract the zip file with the help of following command.

sudo tar -xvjpf OpenCV-2.3.1a.tar.bz2

Change the directory to the OpenCV  cd OpenCV-2.3.1/

Create a directory named build under the OpenCV directory.

mkdir build

Again change the directory to build.

cd build

Next we have to configure the build using cmake command. If you are not sure about the configuration go ahead with the default configuration.

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ..

Now we are in the stage to build the files with the help of make and make install command. (It takes nearly 4 or 5 hours to finish the following task)

sudo make

sudo make install

Now we have to make few configurations with Opencv.conf file. Enter the following command to open the configuration file.

sudo nano /etc/ld.so.conf.d/opencv.conf

Add the following lines to the configuration file even though the configuration file is empty.

/usr/local/lib

Then we have to edit the system-wide bashrc file:

sudo nano /etc/bash.bashrc

Add the following lines to the end of the file.

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig export PKG_CONFIG_PATH

Finally everything is installed and configured properly then we have to move for  demos which are readily available.

C and Python demos are available here:

cd ~/ OpenCV-2.3.1/build/bin

sudo ./drawing

sudo ./facedetect

You can run a python demo like this.

sudo python ./minarea.py

 

 

For more queries:

info@adhiratech.com

080-23240875

Posted in Dev Boards, development boards, image processing and tagged , , .