Friday, February 25, 2011

OpenCV 2.2 on Ubuntu 10.10


*Update: For OpenCV 2.4 on Ubuntu 12.04 see my latest post.

OpenCV (Open Source Computer Vision) is a library of programming functions for real time computer vision. It is released under a BSD license, it is free for both academic and commercial use. It has C++, C, Python and soon Java interfaces running on Windows, Linux, Android and Mac.

This is how to build and install OpenCV 2.2 on Ubuntu 10.10.

First, install the dependencies from the repositories:
sudo apt-get install build-essential libgtk2.0-dev libavcodec-dev libavformat-dev libjpeg62-dev libtiff4-dev cmake libswscale-dev libjasper-dev
Download the source code:
wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.2/OpenCV-2.2.0.tar.bz2
Extract, create the build directory:
tar xfv OpenCV-2.2.0.tar.bz2
rm OpenCV-2.2.0.tar.bz2
cd OpenCV-2.2.0
mkdir opencv.build
cd opencv.build
Configure, make and install:
cmake ..
make
sudo make install
To configure the library, edit the following file (might be empty):
sudo gedit /etc/ld.so.conf.d/opencv.conf
and add the line
/usr/local/lib
Then run:
sudo ldconfig
Finally, edit the file:
sudo gedit /etc/bash.bashrc
and add the following lines at the end:
PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH
Most of the above was find here.

Older versions? Take a look at the following links:

OpenCV 2.1 on Ubuntu 10.04 (pretty much the same as above, but with TBB)
OpenCV 2.0 on Ubuntu 9.10

For OpenCV 2.3.1 see this post.

17 comments:

  1. Hi,
    I find your post extremely helpful. Thank you.
    I want to ask another question. I want to implement an improves version of connected component analysis. I want to implement it in header file while accessing it via cpp file. could you help me figure out how to do that ?
    Thanks.
    Ankit.

    ReplyDelete
  2. I'm glad you found the post helpful. I'm not sure how I can help you with your task. If your problem is writing C++ using header and implementation files then this might help you:
    Organizing Code Files in C and C++

    ReplyDelete
  3. yes i was looking for this kind of implementation. The only thing is I need to use 'make' so that i can build all my dependencies. Do you think you can help me with that ?
    Thanks a lot for your help.

    ReplyDelete
  4. I'm not sure how I can help you with that. Could you be more specific?

    ReplyDelete
  5. make
    when i write make command errors occurs
    Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_ffmpeg.o
    /home/shakir/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp: In member function ‘virtual bool CvCapture_FFMPEG::open(const char*)’:
    /home/shakir/OpenCV-2.2.0/modules/highgui/src/cap_ffmpeg.cpp:469: error: ‘CODEC_TYPE_VIDEO’ was not declared in this scope
    can u help me

    ReplyDelete
  6. This is caused by the the file /usr/local/libavcodec/avcodec.h installed by ffmpeg is different from the file in /OpenCV2.2_source/3rdparty/include/ffmpeg_/libavcodec/avcodec.h.
    So I did the steps to slove the problem
    1) uninstall ffmpeg first by typing "sudo make uninstall" in ffmpeg source directory. This will remove ffmpeg files in /usr/local/...
    2) Kill configured OpenCV files and reconfigure it by CMake with "With FFMPEG" selected.
    3) then "make".
    OpenCV will use the /3rdparty/...ffmpeg_ instead and it is OK on my system.

    ReplyDelete
  7. The point is, you have to use ffmpeg carried by OpenCV 2.2 instead of the lastest ffmpeg you downloaded. It is because that the declaration of "CODEC_TYPE_VIDEO" and others are removed in lastest ffmpeg.

    ReplyDelete
  8. Thank you for clearing that up.

    ReplyDelete
  9. After it reached 56% it gives me this error..

    Building CXX object modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_v4l.o
    /home/joep/Downloads/OpenCV-2.2.0/modules/highgui/src/cap_v4l.cpp:217:28: fatal error: linux/videodev.h: No such file or directory
    compilation terminated.
    make[2]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/src/cap_v4l.o] Error 1
    make[1]: *** [modules/highgui/CMakeFiles/opencv_highgui.dir/all] Error 2
    make: *** [all] Error 2

    Does someone know what i should do to reach it all to the 100%? And get it worked? Or is it maybe possible that somebody can give me the builded folder?

    Joep

    ReplyDelete
  10. Getting a built version will probably not work on your system. Try:
    sudo apt-get install libv4l-dev
    and try again. Hope it works.

    ReplyDelete
  11. I tried it, honestly i don't know what it did!
    But it worked, and after a while it gives another error.. (80%)..
    thanks anyway!

    ReplyDelete
  12. Those errors are usually missing libraries. Try to search online to figure out which Ubuntu package includes the files you are missing and then sudo apt-get install them.

    ReplyDelete
  13. Did you solve a problem on 80%?

    ReplyDelete
  14. I had the same problems then Joep and it's was solved.
    some made some changes in the source code. visit https://code.ros.org/trac/opencv/changeset/5206

    ReplyDelete
  15. Replies
    1. nice! very useful. Help me install it easy and successfully.

      Delete
  16. Muchas Gracias por el tutorial, he instalado y sin problemas, al final cabe resaltar que par correr los ejemplos dirigirse a jevg@jevg-lenovo:~/OpenCV-2.2.0/samples/c$ teclear sh build_all.sh y luego ./facedetect.

    ReplyDelete