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

make
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

make
sudo make install

Download the latest image of v4l from v4l-utils

tar -xvf v4l-version.tar.bz2
cd v4l-version
make
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
cmake -D CMAKE_BUILD_TYPE=RELEASE ..

Verify 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

Build and Install OpenCV

make
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 build_all.sh.
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/ld.so.conf
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. http://jayrambhia.wordpress.com/2012/05/08/beginning-opencv/. 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.

About these ads

24 thoughts on “Install OpenCV 2.4.* in Ubuntu

      • 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?
    Thanks

  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 cv.py and cv2.so.

      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/libpython2.7.so (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

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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