OpenCV on Ubuntu Linux

hello

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


These pages have been updated in March 2007 with instructions for Ubuntu Dapper, in September 2007 for Ubuntu Feisty, July 2008 for Ubuntu Hardy, June 2010 for Linux Mint 9 Isadora (based on Ubuntu 10.4) and OpenCV 2.x, November 2011 for Linux Mint 11 (Katya), December 2011 for Linux Mint 12 (Lisa), March 2013 for Linux Mint 13 (Maya, in principle same binaries as Ubuntu 12.04), April 2014 for Linux Mint 13 and OpenCV 2.4 and April 2016/2017 for Linux Mint 17 and OpenCV 2.4 and OpenCV 3.2

If you are running Mint 17 (Rebecca or Rosa) please see the updated instructions here

All the following have been kept mostly for historical reasons:

If you are running Mint 15 (Olivia) please see the updated instructions here

If you are running Mint 13 (Maya) please see the updated instructions here

If you are running Mint 12 (Lisa) please see the updated instructions here

If you are running Mint 11 (Katya) please see the updated instructions here

If you are running Mint 9.0 (Isadora) please see the updated instructions here

If you are running Ubuntu 8.04 (Hardy) 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 6.06 (Dapper) please see the updated instructions here

Warning Because of the changing nature of open source software, most 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 Linux Mint 17 (Rebecca or Rosa)

For OpenCV 2.4.x please follow the instructions as per Maya

For OpenCV 3.2:

  1. Make sure your system is up to date by doing sudo apt-get update and sudo apt-get upgrade
  2. sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake cmake-qt-gui python-dev python-numpy python-tk libtbb-dev libeigen2-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 to get compiler, ld, make, cmake and all other necessaty packages ....
  3. Download version 3.2 of OpenCV from sourceforge and untar to, say, ~/OpenCV-3.2
  4. cd ~/OpenCV-3.2
  5. mkdir release;cd release
  6. cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_EXAMPLES=ON -D BUILD_PHYTHON_SUPPORT=ON -D WITH_EIGEN=OFF -D CMAKE_INSTALL_PREFIX=/opt/opencv3.2 ..
  7. Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
  8. make (if you have tried making other configurations you could also do a make clean before make)
  9. sudo make install (you will after see a bunch of files in /opt/opencv3.2)
  10. sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/opencv3.2/lib. Then sudo ldconfig
  11. sudo vi /opt/opencv3.1/lib/pkgconfig/opencv.pc and delete "-lippicv"
  12. sudo vi /etc/bash.bashrc and add the lines:
  13. So far so good? Now try running some sample programs. Donwload and untar this into, say, directory ~/simple-examples. Then:

Installing OpenCV for Linux Mint 13 (Maya)

For instructions for OpenCV 2.1, please follow the steps listed for Lisa

These instructions are for OpenCV 2.4.x

  1. Make sure your system is up to date by doing sudo apt-get update and sudo apt-get upgrade
  2. sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake cmake-qt-gui python-dev python-numpy python-tk libtbb-dev libeigen2-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 to get compiler, ld, make, cmake and all other necessaty packages ....
  3. Download version 2.4.8 of OpenCV from sourceforge and untar to, say, ~/OpenCV-2.4
  4. cd ~/OpenCV-2.4
  5. mkdir release;cd release
  6. cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_EXAMPLES=ON -D BUILD_PHYTHON_SUPPORT=ON -D CMAKE_INSTALL_PREFIX=/opt/opencv2.4 ..
  7. Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
  8. make (if you have tried making other configurations you could also do a make clean before make)
  9. sudo make install (you will after see a bunch of files in /opt/opencv2.4)
  10. sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/opencv2.4/lib. Then sudo ldconfig
  11. sudo vi /etc/bash.bashrc and add the lines:
  12. So far so good? Now try running some sample programs. Donwload and untar this. Then:

These instructions are for OpenCV 2.1

  1. Make sure your system is up to date by doing sudo apt-get update and sudo apt-get upgrade
  2. sudo apt-get install build-essential libgtk2.0-dev libjpeg-dev libtiff4-dev libjasper-dev libopenexr-dev cmake cmake-qt-gui python-dev python-numpy python-tk libtbb-dev libeigen2-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 to get compiler, ld, make, cmake and all other necessaty packages ....
  3. Download version 2.1 of OpenCV from sourceforge and untar to, say, ~/OpenCV-2.1 (2.4 is latest at the time of writing, but we needed 2.1 for a particular project! and the API of 2.4 is too different and no one seems to be using 2.2)
  4. cd ~/OpenCV-2.1
  5. Modify CMakeLists.txt line 741 in section if(CMAKE_COMPILER_IS_GNUCXX) so that instead of set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall") it has set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall -D __STDC_CONSTANT_MACROS")
  6. Make sure you carry out the changes described here (if you do not, you will get an error related to Video for Linux). Here you will find the corrected version of the files that need changing: cvconfig.h.cmake (needs renaming), src/highgui/cvcap.cpp and src/highgui/cvcap_libv4l.cpp (I know that it would have been neater to provide diff files that you could use to patch the original. Maybe I will do that when I grow up!. In any case because OpenCV 2.1 does not change (one hopes), it is fine to provide corrected versions).
  7. To avoid problems with ffmpeg, make sure you carry out the modifications described in here and here. Be really careful as I am not sure what version of the ffmpeg libraries they were using. So it is easier to just replace /src/highgui/cvcap_ffmpeg.cpp
  8. Now modify /src/highgui/cvcap_ffmpeg.cpp so that after line 104 you add #include <libavutil/mathematics.h>
  9. Modify files include/opencv/cxcore.hpp, include/opencv/cxoperations.hpp and include/opencv/cxmat.hpp by changing all occurrences of ptrdiff_t to std::ptrdiff_t
  10. sudo vi /etc/bash.bashrc and add the lines:
  11. So far so good? Now try running some sample programs. Donwload and untar this. Then:
From here on, these instructions are mainly of hitoric interest

Installing OpenCV for Linux Mint 15 (Olivia)

If we follow the instructions as per Linux Mint 12 (Lisa) we get the following error when doing cmake (so, this does not work with this distribution)

CMake Error: The following variables are used in this project, but they are set to NOTFOUND.
Please set them or make sure they are set and tested correctly in the CMake files:
JASPER_LIBRARY_RELEASE (ADVANCED)
linked by target "highgui" in directory /home/sergio/OpenCV-2.1/src/highgui

-- Configuring incomplete, errors occurred!

Installing OpenCV for Linux Mint 12 (Lisa)

These instructions are for OpenCV 2.1 and libavformat-dev, libavcodec-dev versions 4:0.7.2-1ubuntu1 (oneiric). This is where OpenCV 2.1 is broken with respect to those libraries (more below)

  1. sudo apt-get install build-essential cmake cmake-qt-gui to get compiler, ld, make, cmake ....
  2. Install the other necessary packages: sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev
  3. And sudo apt-get install libdc1394-22-dev libjasper-dev libgstreamer0.10-dev libgstreamermm-0.10-dev
  4. And sudo apt-get install libswscale-dev libv4l-dev libxine-dev libunicap-dev
  5. Now download version 2.1 of OpenCV from sourceforge and untar to, say, ~/OpenCV-2.1 (2.3 is latest at the time of writing, but we needed 2.1 for a particular project! and the API of 2.3 is too different and no one seems to be using 2.2)
  6. cd ~/OpenCV-2.1
  7. Make sure you carry out the changes described here (if you do not, you will get an error related to Video for Linux). Here you will find the corrected version of the files that need changing: cvconfig.h.cmake (needs renaming), src/highgui/cvcap.cpp and src/highgui/cvcap_libv4l.cpp (I know that it would have been neater to provide diff files that you could use to patch the original. Maybe I will do that when I grow up!. In any case because OpenCV 2.1 does not change (one hopes), it is fine to provide corrected versions).
  8. Modify CMakeLists.txt line 741 in section if(CMAKE_COMPILER_IS_GNUCXX) so that instead of set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall") it has set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall -D __STDC_CONSTANT_MACROS")
  9. To avoid problems with ffmpeg, make sure you carry out the modifications described in here and here. Be really careful as I am not sure what version of the ffmpeg libraries they were using. So it is easier to just replace /src/highgui/cvcap_ffmpeg.cpp
  10. Now modify /src/highgui/cvcap_ffmpeg.cpp so that after line 104 you add #include <libavutil/mathematics.h>
  11. Stop Press: Today (17.Feb.2012) I was testing these instructions on a newly installed Mint 12 64-bit, fully upgraded, and found there are compilation errors. These occur for files include/opencv/cxcore.hpp, include/opencv/cxoperations.hpp and include/opencv/cxmat.hpp. To solve this, edit those files and change all occurrences of ptrdiff_t to std::ptrdiff_t
  12. mkdir release;cd release
    • cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_EXAMPLES=ON -D BUILD_PHYTHON_SUPPORT=ON -D CMAKE_INSTALL_PREFIX=/opt/opencv2.1 ..
    • Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install (you will after see a bunch of files in /opt/opencv2.1)
    • sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/opencv2.1/lib. Then sudo ldconfig
  13. sudo vi /etc/bash.bashrc and add the lines:
      PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/opencv2.1/lib/pkgconfig
      export PKG_CONFIG_PATH
      export OpenCV_DIR=/opt/opencv2.1/share/opencv

      (this setting will be activated if you launch a new console/terminal or if you re-login)
  14. 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 for Linux Mint 11 (Katya)

  1. sudo apt-get install build-essential cmake cmake-qt-gui to get compiler, ld, make, cmake ....
  2. Install the other necessary packages: sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev
  3. And sudo apt-get install libdc1394-22-dev libjasper-dev libgstreamer0.10-dev libgstreamermm-0.10-dev
  4. And sudo apt-get install libswscale-dev libv4l-dev libxine-dev libunicap-dev
  5. Now download version 2.x of OpenCV from sourceforge and untar to, say, ~/OpenCV-2.0.0 (2.3 is latest at the time of writing, but we needed 2.0 for a particular project!)
  6. Make sure you carry out the changes described here (if you do not, you will get an error related to Video for Linux). The files that need changing are cvconfig.h.cmake, src/highgui/cvcap.cpp, src/highgui/cvcap_libv4l.cpp and samples/c/image.cpp (it needs an #include !)
  7. cd ~/OpenCV-2.0.0
    • mkdir release;cd release
    • Modify ../CMakeLists.txt section if(CMAKE_COMPILER_IS_GNUCXX) so that set(EXTRA_C_FLAGS "${EXTRA_C_FLAGS} -Wall -D __STDC_CONSTANT_MACROS")
    • cmake -D CMAKE_BUILD_TYPE=RELEASE -D BUILD_EXAMPLES=ON -D BUILD_PHYTHON_SUPPORT=ON -D CMAKE_INSTALL_PREFIX=/opt/opencv ..
    • Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install (you will after see a bunch of files in /opt/opencv)
    • sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/opencv/lib. Then sudo ldconfig
  8. sudo vi /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)
  9. 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 for Linux Mint 9.0 (Isadora)

  1. sudo apt-get install build-essential cmake cmake-qt-gui to get compiler, ld, make, cmake ....
  2. Install the other necessary packages: sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev
  3. And sudo apt-get install libdc1394-22-dev libjasper-dev libgstreamer0.10-dev libgstreamermm-0.10-dev
  4. And sudo apt-get install libswscale-dev libv4l-dev libxine-dev libunicap-dev
  5. Now download version 2.x of OpenCV from sourceforge and untar to, say, ~/OpenCV-2.1.0
  6. Now do
    • cmake -D BUILD_EXAMPLES=ON -D CMAKE_INSTALL_PREFIX=/opt ~/OpenCV-2.1.0
    • Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
    • cd ~/OpenCV-2.1.0
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install
    • sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/lib. Then sudo ldconfig
  7. sudo vi /etc/bash.bashrc and add the lines:
      PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/opt/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 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
    • ./configure --prefix=/opt/opencv --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing
    • Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install
    • sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/opencv/lib. Then sudo ldconfig
  5. sudo vi /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)
  6. 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 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
    • ./configure --enable-shared --prefix=/opt/ffmpeg (the prefix bit is optional but I prefer to store special development packages like this one on their own directory so it is simpler to locate, configure, remove)
    • make
    • sudo make install
    • The above will install ffmpeg in /opt/ffmpeg. Now sudo vi /etc/ld.so.conf.d/ffmpeg.conf and add the line /opt/ffmpeg/lib to it. Then do sudo ldconfig
  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
    • ./configure --prefix=/opt/opencv --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing CFLAGS=-I/opt/ffmpeg/include CPPFLAGS=-I/opt/ffmpeg/include LDFLAGS=-L/opt/ffmpeg/lib
    • Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install
    • sudo vi /etc/ld.so.conf.d/opencv.conf and add the line /opt/opencv/lib. Then 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 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
    • ./configure --enable-shared --prefix=/opt/ffmpeg (the prefix bit is optional but I prefer to store special development packages like this one on their own directory so it is simpler to locate, configure, remove)
    • make
    • sudo make install
    • The above will install ffmpeg in /opt/ffmpeg. Now sudo vi /etc/ld.so.conf and add the line /opt/ffmpeg/lib to it. Then do sudo ldconfig
  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
    • ./configure --prefix=/opt/opencv --enable-apps --enable-shared --with-ffmpeg --with-gnu-ld --with-x --without-quicktime CXXFLAGS=-fno-strict-aliasing CFLAGS=-I/opt/ffmpeg/include CPPFLAGS=-I/opt/ffmpeg/include LDFLAGS=-L/opt/ffmpeg/lib
    • Check that the above produces no error and that in particular it reports ffmpeg as yes. If this is not the case there is no point in continuing!
    • make (if you have tried making other configurations you could also do a make clean before make)
    • sudo make install
    • sudo vi /etc/ld.so.conf and add the line /opt/opencv/lib. Then 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)
  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:
    • http://ffmpeg.sourceforge.net/ is the FFmpeg homepage.
    • Note: This is no longer available, try: svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

    • The current release version of FFmpeg (0.4.9-pre1) does not work with GCC4, so the options are to either revert to an older and less strict compiler, or follow these instructions and get it working with the new shiny compiler.
    • The command to get the code out of CVS is
      cvs -z9 -d:pserver:anonymous@mplayerhq.hu:/cvsroot/ffmpeg co ffmpeg
  2. Build FFmpeg as a shared library
    • In the FFmpeg directory, do:
    • ./configure --enable-shared
      If you get any error messages here, check the dependencies (see above)
    • make
    • sudo make install
  3. Get hold of OpenCV
    • Get hold of OpenCV from CVS
      cvs -z9 -d:pserver:anonymous@cvs.sourceforge.net:/cvsroot/opencvlibrary co opencv
  4. Install OpenCV
    • ./configure
      At the end of the configure process, a list of options will be displayed with either "no" or "yes" next to them. Check that FFmpeg is OK here - if it isn't, try
      • Checking that you've not installed the libraries via synaptic: do a search for ffmpeg and check that livavformat-dev hasn't been installed
      • Check that when you installed FFmpeg from source you used the --enable-shared switch
      Don't bother proceeding with the installation unless configure tells you that ffmeg is OK (unless, of course, you don't mind working with static images rather than video, in which case you might as well use the synaptic installer)
    • Run make by typing make
    • Check there are no error messages
    • sudo make install
    • Add the line /usr/local/lib to the file /etc/ld.so.conf, as these libraries have been installed there rather than in /usr/lib.
    • Finally, run ldconfig
Sergio A Velastin (with thanks to Alberto Colombo for guiding me on what was at times a painful process!)