Building OpenCV 2.3.1 on Ubuntu 11.04

Getting OpenCV 2.3.1 to compile on Ubuntu can be interesting.  The first issue is tracking down all of the dependencies you need to get the different parts of it to work properly.  There is more information on dependencies needed at the OpenCV wiki here and here.  I found this page on a blog as well which will help to get a lot of the dependencies down.

For me specifically, I had a couple of problems on 11.04.  Make sure you have the following packages installed to enable gstreamer and unicap support:


The second major problem is that OpenCV 2.3.1 doesn’t fully track the latest releases of ffmpeg.  This patch helps, but bear in mind that it’s for OpenCV 2.3.0 and there have been changes between versions.  You’ll have to install the patch by hand to take care of some of the differences.

Once this is done, you should be ready to build.  On my system I ran cmake as:


If you have all of the extra media repositories on Ubuntu enabled, I’d highly recommend NOT disabling shared libraries when building OpenCV.  You’ll avoid some linking errors due to concurrent versions of some of the multimedia libraries that might be installed.

After that, when you compile make sure you add in something like -I/usr/local/include and -L/usr/local/lib to your makefile to make sure you’re pulling in the version you just compiled instead of the default and you should be good to go.

2 thoughts on “Building OpenCV 2.3.1 on Ubuntu 11.04

  1. Hello,

    I am on Ubuntu 11.04 and I installed OpenCv2.3.1 and its dependencies as recommended on the opencv’s wiki. I was able to compile and run most of the example but I uncounter problems to capture video stream from a webcam (USB or integreted as /dev/video0). The program compiles but can’t open of find any device open apparently.

    Here is the example code i found and im trying :
    #include “cv.h”
    #include “highgui.h”

    int main( int argc, char **argv )
    CvCapture *capture = 0;
    IplImage *frame = 0;
    int key = 0;

    /* initialize camera */
    capture = cvCaptureFromCAM( 0 );

    /* always check */
    if ( !capture ) {
    fprintf( stderr, “Cannot open initialize webcam!\n” );
    return 1;

    /* create a window for the video */
    cvNamedWindow( “result”, CV_WINDOW_AUTOSIZE );

    while( key != ‘q’ ) {
    /* get a frame */
    frame = cvQueryFrame( capture );

    /* always check */
    if( !frame ) break;

    /* display current frame */
    cvShowImage( “result”, frame );

    /* exit if user press ‘q’ */
    key = cvWaitKey( 1 );

    /* free memory */
    cvDestroyWindow( “result” );
    cvReleaseCapture( &capture );

    return 0;

    If instead of capturing from a camera i try with a AVI file it works perfectly. and my webcams work perfectly with other programs (xawtv -c /dev/video0)

    Have you seen any problem like this one. Im thinking of downgrading OpenCv to 2.1 but im not sure that will fix my problem.

  2. Might try something like:
    cvNamedWindow( “Source”, 1 );

    /* Turn on and capture video from the first available camera
    Found in the system */
    CvCapture *capture = cvCreateCameraCapture(0);

Comments are closed.