Install OpenCV in Ubuntu 10.10

If you want to install OpenCV 2.1 you can just use apt-get to do the work:

sudo apt-get install libcv-dev libcv2.1 libcvaux-dev libcvaux2.1 libhighgui-dev libhighgui2.1 opencv-doc python-opencv

To install the latest stable version, which now is 2.3.1a, it’s necessary to compile the source code. We will need to install first some libraries and programs to be able to compile OpenCV:

sudo apt-get install cmake cmake-data cmake-curses-gui emacsen-common libxmlrpc-core-c3 g++ libv4l-dev libdc1394-22-dev libraw1394-dev libswscale-dev libavutil-dev libavformat-dev libavcodec-dev libjasper-dev libgstreamer0.10-dev libgstreamer-plugins-base0.10-dev libgtk2.0-dev libtiff4-dev libopenexr-dev libunicap2-dev libeigen2-dev python-dev python-numpy libucil2 libucil2-dev

Now we download OpenCV 2.3.1a source code somewhere in our computer. I usually have a “compilations” directory in my home folder so everything is in place.

wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.3.1/OpenCV-2.3.1a.tar.bz2

You could also download the from the SVN repository, but it may not be 2.3.1a compatible version. The stable version:

svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/trunk

And the latest tested version:

svn co https://opencvlibrary.svn.sourceforge.net/svnroot/opencvlibrary/tags/latest_tested_snapshot

After downloading the source code and extracting it we cd to the folder and execute:

mkdir build
cd build
cmake ..
make
sudo make install

This would configure and compile OpenCV with standard options, but we can change them by CMAKE parameters. For example to use the TBB (Threaring Building Blocks) it would be necessary to install them and activate that library when we execute cmake:

sudo apt-get install libtbb-dev libtbb2
cmake -D WITH_TBB=ON ..

OpenCV is configured by default to use CUDA (to use the GPU for some operations), but if we don’t have it installed you will see an error when configuring with cmake.

CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing:  CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version "4.0")

To prevent this error (although it will compile without problems) just configure CUDA as OFF on cmake:

cmake -D WITH_CUDA=OFF ..

As you can se many options can be configured before compiling OpenCV. Look at this example and try to figure out what each one configures:

cmake -D CMAKE_BUILD_TYPE=DEBUG -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D WITH_UNICAP=ON ..

There is also a more visual way to configure all this options using ccmake (that why we installed cmake-curses-gui). If you run “ccmake ..” instead of “cmake ..” you will be presented with a ncurses user interface with many other options. If you want to see them all toggle to expert mode by pressing letter “t“. When you are ready with your options press “c” to configure (and see if there is any error or warning) and finish pressing “g” to generate the CMAKE files. Then you will be able to compile using “make” as ussual.

If you want to uninstall OpenCV go to your “build” folder and execute:

sudo make uninstall

If you get an error like this when running any OpenCV program:

error while loading shared libraries: libopencv_core.so.2.1: cannot open shared object file: No such file or directory

You should create a file called “/etc/ld.so.conf.d/opencv.conf” and put inside the location of the folder with the OpenCV libraries, which should be /usr/local/lib/ (this is an option that can be changed during configuration with CMAKE_INSTALL_PREFIX option). Then reload the library configurations running this command:

sudo ldconfig /etc/ld.so.conf

If you are using OpenCV 2.1 and have messages about “mmap invalid argument” running OpenCV programs, you will need to compile the source code but changing before the file “/src/highgui/cvcap_libv4l.cpp” on line 785 from:

mmap (NULL /* start anywhere */,

to:

v4l2_mmap (NULL /* start anywhere */,

This bug is solved in SVN repository.

You might also like

Install OpenCV 2.3.1 in Ubuntu 12.04
OpenCV 2.3.1 is now the last version in repositories so you just need to run:sudo apt-get install...

Install OpenCV 2.3.1 in Ubuntu 12.04
OpenCV 2.3.1 is now the last version in repositories so you just need to run:sudo apt-get install...

Install OpenCV 2.3.1a in Ubuntu 11.10
If you want to install OpenCV 2.1 you can just use apt-get to do the work: sudo apt-get install libcv-dev...

Install OpenCV 2.3.1a in Ubuntu 11.10
If you want to install OpenCV 2.1 you can just use apt-get to do the work: sudo apt-get install libcv-dev...

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.