OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real time computer vision, developed by Intel and now supported by Willow Garage. This post describes the procedure to successfully install OpenCV 2.3.1 in your Ubuntu operating system,
We are not going to use any special IDE(like eclipse or visual studio), we will use our terminal and default compilers (gcc and g++), for the compilation of our code..
If you have earlier tried to install it and haven't got any success, I recommend you to use a fresh copy of Ubuntu, and then follow the below given procedure..
We are not going to use any special IDE(like eclipse or visual studio), we will use our terminal and default compilers (gcc and g++), for the compilation of our code..
If you have earlier tried to install it and haven't got any success, I recommend you to use a fresh copy of Ubuntu, and then follow the below given procedure..
To install and configure OpenCV 2.3.1 with its dependencies, complete the following steps.
- Remove any installed versions of ffmpeg and x264 by entering the following command:
sudo apt-get remove ffmpeg x264 libx264-dev
- Get all the dependencies for x264 and ffmpeg by entering the following commands:
sudo apt-get update
sudo apt-get install build-essential checkinstall git cmake libfaac-dev libjack-jackd2-dev libmp3lame-dev libopencore-amrnb-dev libopencore-amrwb-dev libsdl1.2-dev libtheora-dev libva-dev libvdpau-dev libvorbis-dev libx11-dev libxfixes-dev libxvidcore-dev texi2html yasm zlib1g-dev
- Download and install gstreamer, a pipeline-based multimedia framework written in the C programming language, which allows a programmer to create a variety of media-handling components, including simple audio playback, audio and video playback, recording, streaming and editing. The pipeline design serves as a base to create many types of multimedia applications such as video editors, streaming media broadcasters, and media players, by entering the following command:
sudo apt-get install libgstreamer0.10-0 libgstreamer0.10-dev gstreamer0.10-tools gstreamer0.10-plugins-base libgstreamer-plugins-base0.10-dev gstreamer0.10-plugins-good gstreamer0.10-plugins-ugly gstreamer0.10-plugins-bad gstreamer0.10-ffmpeg
- Download and install x264, a free software library for encoding video streams into the H.264/MPEG-4 AVC format.
- Download a recent stable snapshot of x264 from ftp://ftp.videolan.org/pub/videolan/x264/snapshots/. The exact version does not seem to matter. To write this guide, I used version x264-snapshot-20110808-2245-stable.tar.bz2, but I have used previous versions too.
- Configure and build the x264 libraries by entering the following commands:
./configure --enable-static
make
sudo make install
- Download and install install ffmpeg, a free software project that produces libraries and programs for handling multimedia data.
- Download ffmpeg version 0.8.x from http://ffmpeg.org/download.html. Note: Versions of OpenCV prior to 2.3.1 require ffmpeg 0.7.x.
- Configure and build ffmpeg by entering the following commands in a terminal:
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-nonfree --enable-postproc --enable-version3 --enable-x11grab
make
sudo make install
- Download and install gtk, a cross-platform widget toolkit for creating graphical user interfaces, by entering the following command:
sudo apt-get install libgtk2.0-0 libgtk2.0-dev
- Download and install libjpeg, a library written entirely in C which contains a widely-used implementation of a JPEG decoder, JPEG encoder and other JPEG utilities, by entering the following command:
sudo apt-get install libjpeg62 libjpeg62-dev
- Download and install install v4l (video for linux), a video capture (from webcams, TV tuners etc.) application programming interface for Linux.
- Download v4l-utils-0.8.5.tar.bz2 from http://www.linuxtv.org/downloads/v4l-utils/
- Build v4l by entering the following commands in a terminal:
make
sudo make install
- Download and install install OpenCV.
- Download OpenCV version 2.3.1 from http://sourceforge.net/projects/opencvlibrary/files/
- Use the following command to untar the source files
tar xvf OpenCV-2.3.1.tar.bz2
cd OpenCV-2.3.1/
mkdir build
cd build
cmake ..
- Check that the output of cmake includes the following text:
- found gstreamer-base-0.10
- GTK+ 2.x: YES
- FFMPEG: YES
- GStreamer: YES
- V4L/V4L2: Using libv4l
- Run
make
- Run
sudo make install
- Configure Linux.
- Tell linux where the shared libraries for OpenCV are located by entering the following shell command:
export LD_LIBRARY_PATH=/usr/local/lib
Add the command to your .bashrc file so that you don’t have to enter every time your start a new terminal.Alternatively, you can configure the system wide library search path. Using your favorite editor, add a single line containing the text/usr/local/lib
to the end of a file named/etc/ld.so.conf.d/opencv.conf
.
- Using your favorite editor, add the following two lines to the end of /etc/bash.bashrc:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH - Reboot.
After completing the previous steps, your system should be ready to compile code that uses the OpenCV libraries. The following example shows one way to compile code for OpenCV:
g++ `pkg-config opencv --cflags` `pkg-config opencv --libs` my_code.cpp -o my_code