OpenCV on Ubuntu Linux

hello

This page contains a "step-by-step" guide to getting opencv installed on an Ubuntu system. Information here came from several sources, including the helpful members of the OpenCV yahoogroup mailing list.

These have been tested with the Kubuntu variant of Ubuntu


These pages have been updated in June 2007 with instructions for Ubuntu Dapper, in September 2007 for Ubuntu Feisty and July 2008 for Ubuntu Hardy

If you are running Ubuntu 6.06 (Dapper) please see the updated instructions here

If you are running Ubuntu 7.04 (Feisty) please see the updated instructions here

If you are running Ubuntu 8.04 (Hardy) please see the updated instructions here

Warning Because of the changing nature of open source software, some of these instructions are likely to be obsolete. In particular, be aware that ffmpeg has gone through a number of versions some of which do not work with OpenCV/Ubuntu. Fortunately, as from Ubuntu 7.10 it is not necessary to install ffmpeg from source but rather just libraries such as libavcodec, ...

Therefore, these pages are more a historical record of installations on different versions of Ubuntu with the latest one being the one we are more confident it works!


Installing OpenCV for Ubuntu 8.04 (Hardy)

We have tried the officially supported version of this, i.e. runnning KDE 3.x instead of 4.x

Note that installation on version 7.10 follows the same procedure, but I never got round documenting it

Things seem to be getting easier!

Thanks to Leeds University for their guide on using OpenCV

  1. sudo apt-get install build-essential to get compiler, ld, make, ....
  2. Install the other necessary packages: sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev
  3. Now download and untar version 1.0.0 of OpenCV from http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
  4. Now do
  5. sudo vi /etc/bash.bashrc and add the lines:
  6. So far so good? Now try running some sample programs. Donwload and untar this. Then:

Installing OpenCV for Ubuntu 7.04 (Feisty)

You might want to use this distribution because it has corrected bugs from previous ones, supports your hardware better, etc.

Thanks to Leeds University for their guide on using OpenCV

  1. Install subversion and all the basic compilation packages such as g++ and gcc etc.
  2. Download ffmpeg with: svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg and then
  3. Important: Modify file /opt/ffmpeg/include/ffmpeg/avformat.h by adding the following lines to it (otherwise you will get a compilation error when compiling OpenCV (see here for more details):
    #define INT64_C
    #define __STDC_CONSTANT_MACROS
    #include <stdint.h>
  4. Install the other necessary packages: sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev
  5. Now download and untar version 1.0.0 of OpenCV from http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
  6. Now do
  7. Edit (as root) /etc/bash.bashrc and add the lines:
  8. So far so good? Now try running some sample programs. Donwload and untar this. Then:

Installing OpenCV for Ubuntu 6.06 (Dapper) UPDATED

You might want to use this distribution because it has longer support, some packages seem to be more stable than later ones and for me at least it runs faster than 7.04!

Note that there is an older section (struck out), which I have kept as we recently had a case where it was necessary to install the older version of ffmpeg!

  1. Install subversion and all the basic compilation packages such as g++ and gcc etc.
  2. Download ffmpeg with: svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg and then
  3. Important: Modify file /opt/ffmpeg/include/ffmpeg/avformat.h by adding the following lines to it (otherwise you will get a compilation error when compiling OpenCV (see here for more details):
    #define INT64_C
    #define __STDC_CONSTANT_MACROS
    #include <stdint.h>
  4. Install the other necessary packages: sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev
  5. Now download and untar version 1.0.0 of OpenCV from http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
  6. Now do
  7. Edit (as root) /etc/bash.bashrc and add the lines:
  8. So far so good? Now try running some sample programs. Donwload and untar this. Then:
  1. First download an older version of ffmpeg from here (I found that newer versions generate all sort of errors when compiling OpenCV)
    • ./configure --enable-shared
    • make
    • sudo make install (note: this will compile with gcc 4)
    The above will install ffmpeg in /usr/local/lib. Add /usr/local/lib to /etc/ld.so.conf
  2. Install the other necessary packages as explained above e.g. libgtk2.0-dev, libavcodec-dev, libavformat-dev, libjpeg62-dev and libtiff4-dev
  3. Now download and untar version 1.0.0 of OpenCV from http://sourceforge.net/project/showfiles.php?group_id=22870&package_id=16948
  4. Important! Replace the file configure with this one (after downloading it change its name to "configure" and make it executable)
  5. Now do ./configure -n and make sure that ffmpeg is shown as "yes" (it should be, the doctored configure file bypasses checks that would otherwise fail).
  6. Now do
    • sudo mkdir /opt/opencv (this is a quirk of mine, I like adding software where I can easily check/remove it later)
    • ./configure --prefix=/opt/opencv
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install
    • Edit (as root) /etc/ld.so.conf adding the line /opt/opencv/lib
    • sudo ldconfig
  7. Edit (as root) /etc/bash.bashrc and add the lines:
      PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/opencv/lib/pkgconfig
      export PKG_CONFIG_PATH

      (this setting will be activated if you launch a new console/terminal or if you re-login)
  8. So far so good? Now try running some sample programs. Donwload and untar this. Then:
      ./build-all.sh
      edge fruits.jpg (it shows that you can open and display a jpg file)
      cvplayer-v2 SEQ-003-C5_X4.mpg (it shows you can open and display an mpg video file, with ffmpeg)

Installing OpenCV from the cvs version for Ubuntu 5

First, there are a few dependencies to sort out. You will need to install the following packages - using Synaptic.

Second, you can't install OpenCV or FFmpeg from Synaptic (well you can, but they won't deal with video files properly) so uninstall them.

Then...

  1. Obtain FFmpeg from the FFmpeg CVS repository:
  2. Build FFmpeg as a shared library
  3. Get hold of OpenCV
  4. Install OpenCV
Sergio A Velastin (with thanks to Alberto Colombo for guiding me on what was at times a painful process!)