Something More for Research

Explorer of Research #HEMBAD

OpenCV installation for Ubuntu 12.04

Posted by Hemprasad Y. Badgujar on June 23, 2014

The latest Long Term Support version of Ubuntu(12.04 LTS) is out and a new version of OpenCV was released as well. This means that now is a great opportunity to update my OpenCV installation guide to the latest versions, Ubuntu 12.04 LTS and OpenCV 2.4.9.

We are going to setup OpenCV to use the new Qt highgui interface, which is much better than the simple highgui interface. Also, we will install OpenCV with support for OpenGL, as well as reading and writing videos, access to a webcam, Python, C and C++ interfaces, and Intel Threading Building Blocks (TBB).

OK, so the first step is to make sure that everything in the system is updated and upgraded:

1 sudo apt-get update
2 sudo apt-get upgrade

Now, you need to install many dependencies, such as support for reading and writing image files, drawing on the screen, some needed tools, etc… This step is very easy, you only need to write the following command in the Terminal:

1  sudo apt-get install build-essential cmake pkg-configRemove any installed versions of ffmpeg and x264 by entering the following command:
sudo apt-get remove ffmpeg x264 libx264-dev

Following command will install required Image I/O libraries.

sudo apt-get install libjpeg62-dev libtiff4-dev libjasper-dev

Get all the dependencies for x264 and ffmpeg by entering the following commands:
sudo apt-get update
sudo apt-get install build-essential check
install 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 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 VLC
sudo apt-get install vlc vlc-dbg vlc-data libvlccore5 libvlc5 libvlccore-dev libvlc-dev tbb-examples libtbb-doc libtbb2 libtbb-dev libxine1-bin libxine1-ffmpeg libxine-dev 

Install required video libraries.

sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev
**sudo apt-get install x264 (Not needed since we installed x264 above)

Install MySQLC++Client
sudo apt-get install libmysqlcppconn-dev

Install gtk libraries for highgui

sudo apt-get install  libgtk2.0-dev

sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake python-dev python-numpy python-tk libtbb-dev libeigen2-dev yasm libfaac-dev libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev libxvidcore-dev libx264-dev libqt4-dev libqt4-opengl-dev sphinx-common texlive-latex-extra libv4l-dev libdc1394-22-dev libavcodec-dev libavformat-dev libswscale-dev

sudo apt-get install libqt4-core libqt4-dev libqt4-gui qt4-dev-tools

Download and install install x264. Recent stable snapshot of x264 from
cd ~/OpenCV
tar xjvf x264-snapshot-20121004-2245-stable.tar.bz2
cd x264-snapshot-20121004-2245-stable
./configure –enable-static –enable-pic –enable-shared
sudo make install

Download and install install ffmpeg. Latest from
cd ~/OpenCV
tar xzvf ffmpeg-1.0.tar.gz
cd ffmpeg-1.0
./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 –enable-pic –enable-shared
sudo make install

Download and install gtk libjpeg by entering the following command:
sudo apt-get install libgtk2.0-0 libgtk2.0-dev libjpeg62 libjpeg62-dev

Download and install install v4l (video for linux). Download v4l-utils-#.#.#.tar.bz2 from
cd ~/OpenCV
tar xjvf v4l-utils-0.9.1.tar.bz2
cd v4l-utils-0.9.1
sudo make install

Time to get the OpenCV 2.4.1 source code:

1 cd ~
3 tar -xvf OpenCV-2.4.9.tar.bz2
4 cd OpenCV-2.4.1

Now we have to generate the Makefile by using cmake. In here we can define which parts of OpenCV we want to compile. Since we want to use Python, TBB, OpenGL, Qt, work with videos, etc, here is where we need to set that. Just execute the following line at the terminal to create the appropriate Makefile. Note that there are two dots at the end of the line, it is an argument for the cmake program and it means the parent directory (because we are inside the build directory, and we want to refer to the OpenCV directory, which is its parent).

1 mkdir build
2 cd build

Check that the above command produces no error and that in particular it reports FFMPEG as YES. If this is not the case you will not be able to read or write videos. Also, check that Python, TBB, OpenGL, V4L, OpenGL and Qt are detected.

If anything is wrong, go back, correct the errors by maybe installing extra packages and then run cmake again. You should see something similar to this:

Now, you are ready to compile and install OpenCV 2.4.9:

1 make
2 sudo make install

Now you have to configure OpenCV. First, open the opencv.conf file with the following code:

1 sudo gedit /etc/

Add the following line at the end of the file(it may be an empty file, that is ok) and then save it:

1 /usr/local/lib

Run the following code to configure the library:

1 sudo ldconfig

Now you have to open another file:

1 sudo gedit /etc/bash.bashrc

Add this to ~/.bashrc
export LD_LIBRARY_PATH=/usr/local/lib:/home/LOCAL_USER_NAME/OpenCV/OpenCV-2.4.2/build/lib:$LD_LIBRARY_PATH
export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH
export CLASSPATH=/usr/share/java/mysql.jar:/usr/include/mysql++:$CLASSPATH

Add these two lines at the end of the file and save it:

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

Finally, close the console and open a new one, restart the computer or logout and then login again. OpenCV will not work correctly until you do this.

Now you have OpenCV 2.4.9 installed in your computer with Python, TBB, OpenGL, video, and Qt support.

Check out the cool Qt interface which provides image viewing capabilities with zoom, as well as the ability to save the current image with just one click.

If you zoom in enough, you can see the RGB (or intensity) values for each pixel.

Now let’s build some samples included in OpenCV:

1 cd ~/OpenCV-2.4.9/samples/c
2 chmod +x
3 ./

Now we are ready to run the examples:

1 ./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"--scale=1.5 lena.jpg

1 ./facedetect --cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_frontalface_alt.xml"--nested-cascade="/usr/local/share/OpenCV/haarcascades/haarcascade_eye.xml" --scale=1.5 lena.jpg

1 ~/OpenCV-2.4.9/build/bin/grabcut ~/OpenCV-2.4.9/samples/cpp/lena.jpg

1 ~/OpenCV-2.4.9/build/bin/calibration_artificial

1 python ~/OpenCV-2.4.9/samples/python2/


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Extracts from a Personal Diary

dedicated to the life of a silent girl who eventually learnt to open up

Num3ri v 2.0

I miei numeri - seconda versione


Just another site

Algunos Intereses de Abraham Zamudio Chauca

Matematica, Linux , Programacion Serial , Programacion Paralela (CPU - GPU) , Cluster de Computadores , Software Cientifico




A great site

Travel tips

Travel tips

Experience the real life.....!!!

Shurwaat achi honi chahiye ...

Ronzii's Blog

Just your average geek's blog

Karan Jitendra Thakkar

Everything I think. Everything I do. Right here.


News About Tech, Money and Innovation

Chetan Solanki

Helpful to u, if u need it.....


Explorer of Research #HEMBAD


Explorer of Research #HEMBAD


A great site


This is My Space so Dont Mess With IT !!

%d bloggers like this: