Wednesday, May 30, 2012

How to install OpenCV 2.4 on Ubuntu 11.10

In the Internet one can find a lot of manuals about how to install/build OpenCV 2.3 under Linux, but most of them are incomplete. So here I would like to write a manual that I would like to see, a manual that helps to build OpenCV without any problems.

So let's start.

First we need to install compiler, linker, make, cmake...
 sudo apt-get install build-essential cmake cmake-qt-gui

Now let's install all the necessary packages:
 sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev  
   
 sudo apt-get install libdc1394-22-dev libjasper-dev libgstreamer0.10-dev libgstreamermm-0.10-dev  
   
 sudo apt-get install libswscale-dev libv4l-dev libxine-dev libunicap-dev  
   
 sudo apt-get install checkinstall git 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  
   
 sudo apt-get install libgstreamer0.10-0 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  
 

Now let's build and install x264:
 git clone git://git.videolan.org/x264
 ./configure --enable-static 
 make  
 sudo make install  
 cd ..  


Now let's install libs that are necessary for ffmpeg installation:

 sudo apt-get install libopencore-amrnb-dev libopencore-amrwb-dev libtheora-dev libvorbis-dev

Now let's download and install ffmpeg:

 git clone --depth 1 git://git.videolan.org/ffmpeg  
 cd ffmpeg  
./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb \
--enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libx264 \
--enable-postproc --enable-version3 --enable-x11grab --enable-shared --enable-nonfree
 make  
 sudo make install  
 cd ..  

Now let's install gtk:
 sudo apt-get install libgtk2.0-0 libgtk2.0-dev  

Now let's install :
 sudo apt-get install libjpeg62 libjpeg62-dev  

If you need Python bindings you should also install required Python libraries:
 sudo apt-get install python-numpy python-sphinx python-dev  

Now we are ready to build OpenCV:

 wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.0/OpenCV-2.4.0.tar.bz2  
tar -xvf OpenCV-2.4.0.tar.bz2  
cd OpenCV-2.4.0  
mkdir Build  
cd Build  
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_EXAMPLES=ON -D BUILD_NEW_PYTHON_SUPPORT=ON ..  
make  
sudo make install

Key BUILD_NEW_PYTHON_SUPPORT=ON is used to build and install python bindings.

Now add the following lines to your .bashrc file:
export LD_LIBRARY_PATH=/usr/local/lib 

And add the following lines to your /etc/bash.bashrc:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig  
export PKG_CONFIG_PATH

Reboot your computer.

Now we can check if OpenCV is working. First we need to build examples:
cd ../samples/c
chmod a+x build_all.sh

Now we can run one of the examples:
./facedetect

You should see an example of an application that displays a video captured from a web-camera and detects a face on it.


Or you can check one of Python examples:
 cd ../samples/python2/  
 python hist.py  

Now you should see an app that uses OpenCV library.

If you need Java binding for OpenCV use JavaCV library. To install it just follow the instructions on the website.

That's all.
Good luck.

2 comments:

  1. To install OpenCV using the terminal on Ubuntu:
    $ su -
    # apt-get update
    # apt-get install build-essential
    # apt-get install libavformat-dev
    # apt-get install x264 v4l-utils ffmpeg
    # apt-get install libcv2.3 libcvaux2.3 libhighgui2.3 python-opencv opencv-doc libcv-dev libcvaux-dev libhighgui-dev

    http://namhuy.net/1205/how-to-install-opencv-on-ubuntu.html

    ReplyDelete