Installing OpenCV from CVS on Ubuntu Edgy

These are my notes concerning the installation of OpenCV from CVS on Ubuntu Edgy. While I’ll try to be helpful if you have problems, I’m not responsible for blowing up your system.

The charade:
Check out the OpenCV code from cvs:

cvs login
cvs -z3 co -P opencv

Then make sure pkg-config and g++ are installed:

sudo apt-get install g++ pkg-config

At this point, you should be able to configure and install opencv, but it probably won’t find some of the libraries it needs to work with video and certain image formats. To get all the functionality of OpenCV, I installed the following packages (Some of these are in the multiverse repositories. Go here to find out how to add more repositories):

sudo apt-get install libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev

Now you can run:

cd opencv && ./configure

Check to make sure all of the fancy features you want show up as enabled. The packages we installed earlier make my configuration show up something like so:

General configuration =============================================
Compiler:                 g++
CXXFLAGS:                 -Wall -fno-rtti -pipe -O3 -g -march=i686 -ffast-math -fomit-frame-pointer
Install path:             /usr/local

HighGUI configuration =============================================

Windowing system --------------
Use Carbon / Mac OS X:    no
Use gtk+ 2.x:             yes
Use gthread:              yes

Image I/O ---------------------
Use libjpeg:              yes
Use zlib:                 yes
Use libpng:               yes
Use libtiff:              yes
Use libjasper:            no
Use libIlmImf:            no

Video I/O ---------------------
Use QuickTime / Mac OS X: no
Use xine:                 no
Use ffmpeg:               yes
Use dc1394 & raw1394:     yes
Use v4l:                  yes
Use v4l2:                 yes

Wrappers for other languages =========================================
Python                    no

Additional build settings ============================================
Build demo apps           yes

Now run make ...

If everything looks good, we can now compile and install OpenCV:

make && sudo make install && sudo ldconfig

You may need to run the following command if /usr/local isn’t in your library search path (make sure you trust users who have write access to /usr/local/lib):

sudo sh -c 'echo "/usr/local/lib" >> /etc/ && ldconfig'

Instead, some guides may instruct you to change the LD_LIBRARY_PATH environment variable, but this is not the best way to get your programs to work. Modifying this variable is generally used as a hack to get things working in the moment, but it should not be used as a permanent solution, as it poses security problems. This means that you shouldn’t try setting this variable in any startup scripts… See this page about shared libraries.

Now you can start writing programs which employ the functionality of OpenCV. The best way learn how to do this is by looking at the sample applications. You can compile the sample applications by doing the following:

cd samples/c
chmod u+x

Now you can run the sample apps just like any other executable:

./ProgramName --ProgramOptions

Please comment if you find problems or have suggestions.

If you get an error like the following one after running your application, then you didn’t correctly add /usr/local/lib to the library search path. Go back and do it correctly…

./ProgramName: error while loading shared libraries: cannot open shared object file: No such file or directory

The wiki for a class using OpenCV. There are examples, tutorials, problems, and students’ solutions all open to the public.
The official OpenCV wiki.

Published by


A robot taste tester in Computer Science at Iowa State University.

Leave a Reply

Your email address will not be published. Required fields are marked *