Install OpenCV 2.4.* in Ubuntu

Install OpenCV 2.4.0
Install OpenCV 2.4.1
Install OpenCV 2.4.2
Install OpenCV 2.4.3
Install OpenCV 2.4.4
Install OpenCV 2.4.5

Remove any installed versions of ffmpeg and x264.

sudo apt-get remove remove ffmpeg x264 libx264-dev

Install all the dependencies.

sudo apt-get install libopencv-dev
sudo apt-get install build-essential checkinstall cmake pkg-config yasm
sudo apt-get install libtiff4-dev libjpeg-dev libjasper-dev
sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev 
sudo apt-get install libdc1394-22-dev libxine-dev
sudo apt-get install libgstreamer0.10-dev 
sudo apt-get install libgstreamer-plugins-base0.10-dev 
sudo apt-get install libv4l-dev
sudo apt-get install python-dev python-numpy
sudo apt-get install libtbb-dev
sudo apt-get install libqt4-dev libgtk2.0-dev

Download the latest version ox x264 from x264 snapshots

tar -xvf x264-snapshot-version.tar.bz2
cd x264-snapshot-version/

If you are using 32 bit Linux

./configure --enable-static

If you’re using 64 bit Linux

./configure --enable-shared --enable-pic

Install it

sudo make install

Download the latest version of ffmpeg from ffmpeg Download.

tar -xvf ffmpeg-version.tar.bz2
cd ffmpeg-version/

If you’re using 32 bit Linux

./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

If you’re using 64 bit Linux or ARM

./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-shared

Install it

sudo make install

Download the latest image of v4l from v4l-utils

tar -xvf v4l-version.tar.bz2
cd v4l-version
sudo make install

Download OpenCV 2.4.0
Download OpenCV 2.4.1
Download OpenCV 2.4.2
Download OpenCV 2.4.3

After downloading OpenCV 2.4.* package, untar it and make.

tar -xvf OpenCV-version.tar.bz2
cd OpenCV-version/
mkdir build
cd build

Verify that the output of cmake includes the following text:

  • found gstreamer-base-0.10
  • GTK+ 2.x: YES
  • GStreamer: YES
  • V4L/V4L2: Using libv4l

Build and Install OpenCV

sudo make install

OpenCV 2.4.* is now installed. Just make sure that all the libraries are linked properly.
Go to samples directory in OpenCV package.
Change directory to C or C++.
You’ll find a script there named
Execute the script. It will make all the files. select any output file and run it. If it works then you are good to go.

sudo echo "/usr/local/lib" >> /etc/
sudo ldconfig

Your OpenCV 2.4.* is installed and libraries are properly linked. If you don’t have much experience with OpenCV, I would suggest you to go through this post. It shows how to make a script so that you don’t need to add everything while compiling opencv codes.

P.S. My Python port of George Nebehay’s OpenTLD Version is almost ready.

45 thoughts on “Install OpenCV 2.4.* in Ubuntu

    • Hi. The installation went fine, thanks to your great step-by-step instructions. I use my install script mainly for setting up a newly installed machine quickly.

      • That’s so great. I think I should start using it since every time I try to upgrade my Ubuntu, I do something foolish and everything goes nuts and I have to re-install the new OS every time.

  1. Pingback: Get data from Mat / cv::Mat in OpenCV « Paranoid Android

  2. Pingback: ATutz, Linux Server Tutorials | Trouble compiling OpenCV for Linux on an Optimus laptop using bumblebee - ATutz, Linux Server Tutorials

  3. Your step-by-step tutorial works great. Now I can work with OpenCV in Ubuntu. Btw, how can you find all the dependencies to install? I mean, are there any hints to know which dependencies are necessary?

    • Hey,
      Thanks. Glad to hear that it helped. So, basically there’s a list of dependencies on OpenCV website and you could always find all the dependencies on blogs like this.

  4. Pingback: Cài đặt OPENCV trên Ubuntu Linux, ai biết xin chỉ giáo

  5. hey jay,
    can you explain me about how to remove/uninstall all installed opencv in ubuntu 12.04?
    i used to install opencv 2.1, opencv 2.4.1, and opencv 2.4.2 and now i want to remove/uninstall all of their traces because i find it difficult to find its packages..

    • Hey,
      If you have installed using package manager, check /usr/lib directory and remove all the opencv files or just remove it using package manager (that would be better). If you have built and installed it from the source, you need to manually remove it. check /usr/local/lib and remove all the opencv files. Also, check /usr/local/lib/python2.7/dist-packages/ and remove and

      I think this should be sufficient.

  6. Pingback: opencv 4 android (Ubuntu 12.04, 32 bit) » Trigger

  7. ./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

    ERROR: libfaac not found…

    Could you help me?

  8. Well… my last problem was resolved. But the error still pops out as

    Looking for ffmpeg/avformat.h
    — Looking for ffmpeg/avformat.h – not found
    — checking for module ‘libdc1394-2’
    — found libdc1394-2, version 2.2.0
    — Looking for alloca.h
    — Looking for alloca.h – found
    — Looking for alloca
    — Looking for alloca – not found
    — Looking for unistd.h
    — Looking for unistd.h – found
    — Looking for pthread.h
    — Looking for pthread.h – found
    — checking for module ‘libxine’
    — found libxine, version 1.1.20
    — checking for module ‘libv4l1’
    — found libv4l1, version 0.8.9
    — Looking for linux/videodev.h
    — Looking for linux/videodev.h – not found
    — Looking for linux/videodev2.h
    — Looking for linux/videodev2.h – found
    — Found PythonInterp: /usr/bin/python (found suitable version “2.7.3”, required is “2.0”)
    — Found PythonLibs: /usr/lib/ (Required is at least version “2.7.3”)
    — Found Sphinx 1.1.3: /usr/bin/sphinx-build
    — Looking for Q_WS_X11
    — Looking for Q_WS_X11 – found
    — Looking for Q_WS_WIN
    — Looking for Q_WS_WIN – not found.
    — Looking for Q_WS_QWS
    — Looking for Q_WS_QWS – not found.
    — Looking for Q_WS_MAC
    — Looking for Q_WS_MAC – not found.

    Thanks for helping!

  9. Thank you for the 2.4.3 install script for 12.04. I have been banging my head against the wall for three days. Everything was working with OpenCV 2.4.3 except video from my webcam. I ran your script, it fixed the problem. Great work.

  10. Pingback: xbox 360

  11. Pingback: Tutorials - Setup OpenCV for Android, iOS, Linux, and Windows

  12. Hello.

    Thanks for the script. I followed it and I’m stuck at this point: When I type:
    tar -xvf OpenCV-version.tar.bz2
    cd OpenCV-version/
    mkdir build
    cd build

    I get:
    CMake Error: The source directory “/home/uni/src/OpenCV-2.4.5” does not appear to contain CMakeLists.txt.

    I’m using Ubuntu 12.10 and my architecture is x86_64.
    Any suggestions?


  13. Thanks for the reply. I did re-install and everything works fine. Up until when I find “”.

    Since I am a beginner, could you tell me how to execute it so that I can run sample files?

  14. “tar -xvf v4l-version.tar.bz2
    cd v4l-version
    sudo make install”

    i’ve downloaded v4l-utils-0.9.4.tar.bz2
    but when i try make there is some thing like that :
    “zeeshan@ubuntu:~/Desktop/opencv_build/OpenCV$ ls
    ffmpeg-0.11.1 OpenCV-2.4.2.tar.bz2 v4l-utils-0.9.4 x264-snapshot-20120528-2245-stable
    ffmpeg-0.11.1.tar.bz2 v4l-utils-0.8.8 v4l-utils-0.9.4.tar.bz2 x264-snapshot-20120528-2245-stable.tar.bz2
    OpenCV-2.4.2 v4l-utils-0.8.8.tar.bz2 v4l-utils-0.9.5
    zeeshan@ubuntu:~/Desktop/opencv_build/OpenCV$ cd v4l-utils-0.9.4
    zeeshan@ubuntu:~/Desktop/opencv_build/OpenCV/v4l-utils-0.9.4$ make
    make: *** No targets specified and no makefile found. Stop.

  15. plz tell me how can I configure OpenCV 2.4.5 for Eclipse in Ubuntu 12.04?

    I installed OpenCV 2.4.5 with your code in

  16. Hello,
    I have a problem.
    cmake -D CMAKE_BUILD_TYPE=RELEASE .. works fine. But when I command make some files build and results in error.

    i got this error :
    Linking CXX shared library ../../lib/
    /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: could not read symbols: Bad value
    collect2: error: ld returned 1 exit status
    make[2]: *** [lib/] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    What should I do?? Please Help..

  17. tar -xvf v4l-version.tar.bz2
    cd v4l-version
    sudo make install

    This is missing the ./configure after the changing of the folder , should be

    tar -xvf v4l-version.tar.bz2
    cd v4l-version
    sudo make install

  18. Hey,

    i am currently trying to install Opencv on UB 12.04 LTS and had trouble while make at the step to install x264. it was saying Minimum Version yasm 1.2.0 and since i have UB precise i have yasm 1.1.something. can you please help me with it?

    Also i am then trying to install with following link:

    However, with this link again i am facing error while installing v4l-utils video for Opencv.

    Please provide some guidance.


  19. Pingback: Instalasi OpenCV 2.3.1a dan ffmpeg 0.8.15 di Ubuntu 12.04 dengan Kompilasi Manual | RESTAVA

  20. Hello, Jay. Thank you so much for this article. The pingback from restava above was from my blog. I have installed OpenCV + ffmpeg successfully on Ubuntu based on your tutorial. Thank you again.

    #ubuntu-indonesia @ freenode

  21. Pingback: Ubuntu:Does the version of Opencv shipped with 12.04 support v4l2? – Ubuntu Linux Questions

  22. Pingback: Unix/Linux:Unable to install open CV in Ubuntu 12.04 – Unix Questions

Leave a Reply

Please log in using one of these methods to post your comment: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s