Linux · 2012-06-17

Install OpenCV 2.4 on Ubuntu 12.04

If you’re going to process live streams from cameras or videos, the most important library needed for OpenCV is ffmpeg. You can find a good tutorial on how to compile and install ffmpeg on Ubuntu here. You need to follow those steps, the only difference necessary is to add

--enable-shared --enable-pic

to all configurations. For example this is the configuration needed for ffmpeg:

./configure --enable-gpl --enable-libfaac --enable-libmp3lame --enable-libopencore-amrnb 
    --enable-libopencore-amrwb --enable-libtheora --enable-libvorbis --enable-libvpx 
    --enable-nonfree --enable-version3 --enable-x11grab --enable-shared --enable-pic

If you forget to do so it’s likely you get this error when compiling ffmpeg:

undefined reference to `x264_encoder_open_124'

Once ffmpeg is installed you’re ready to compile OpenCV. There is a short introduction in the official documentation on how to compile and install OpenCV.

Installation in Linux

These steps have been tested for Ubuntu 10.04 but should work with other distros.

Required packages

  • GCC 4.4.x or later. This can be installed with
    sudo apt-get install build-essential
  • CMake 2.6 or higher
  • Subversion (SVN) client
  • GTK+2.x or higher, including headers (libgtk2.0-dev)
  • pkgconfig
  • Python 2.6 or later and Numpy 1.5 or later with developer packages (python-dev, python-numpy)
  • ffmpeg or libav development packages: libavcodec-dev, libavformat-dev, libswscale-dev
  • [optional] libdc1394 2.x
  • [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev.
All the libraries above can be installed via Terminal or by using Synaptic Manager