Installing OpenCV 2.4.9 in Linux

This post is intended to aid linux enthusiasts to install the latest OpenCV version 2.4.9 on their computer. The method is tested in Ubuntu 12.04 desktop and can also be applied to Mint and Debian users. Eventhough the method mentioned below will overwrite any existing OpenCV installation on your system, it is advised to remove any previous installation.

OpenCV in Beagleboard, Embedded Linux

Open a terminal and type the following to update the source list. And install some packages required.

sudo apt-get update
sudo apt-get upgrade
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 libeigen3-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 default-jdk ant libvtk5-qt4-dev

For downloading the source use the following command

cd ~
git clone https://github.com/Itseez/opencv.git
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.4.9/opencv-2.4.9.zip

Decompress the file obtained above using the below command.

unzip opencv-2.4.9.zip

Now all we need is to build the OpenCV for your system. For this use the following commands

cd opencv-2.4.9
mkdir build && cd build

Configure with additional options

cmake -D WITH_TBB=ON -D BUILD_NEW_PYTHON_SUPPORT=ON -D WITH_V4L=ON -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D WITH_IPP=OFF -D CMAKE_INSTALL_PREFIX=/usr ..

Note: Above command should not return any error. If returned with error try disabling some options eg: BUILD_EXAMPLES=OFF

make

Finally install the build files to your system.

sudo make install

For testing the installation try to compile and run a program as in our previous post.

2 thoughts on “Installing OpenCV 2.4.9 in Linux

  1. Hi. I followed the instructions given here for installing opencv in my LinuxMint17 machine. But I got into a problem when running the make command. I received following error message:
    /usr/bin/ld: /usr/local/lib/libavcodec.a(avpacket.o): relocation R_X86_64_32 against `.rodata.str1.1′ can not be used when making a shared object; recompile with -fPIC
    /usr/local/lib/libavcodec.a: error adding symbols: Bad value
    collect2: error: ld returned 1 exit status
    make[2]: *** [lib/libopencv_highgui.so.2.4.9] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    Could you tell me what might be problem?

Leave a comment