Installing OpenCV on Ubuntu
by zkan on Sep.20, 2009, under How-To
Since I often reinstall Ubuntu as well as OpenCV, it would be better to note here. Thanks to Dr. Dailey for his tutorial on VGLWiki.
These are the main packages we need to install first.
- libcv1
- libcvaux1
- libcvaux-dev
- libcv-dev
- libhighgui1
- libhighgui-dev
- opencv-doc (optional)
If you want to use gstreamer, here are the steps:
- Install two additional packages: libgstreamer0.10-dev and libdc1394-13-dev.
- Download OpenCV from sourceforge and extract to a folder, let’s say “opencv”.
- Change directory to that folder and run this command:
./configure --prefix=${HOME}/opencv --without-xine --without-quicktime --with-gstreamer --with-1394libs --with-v4l makemake install- The last thing is to is to tell the dynamic linker where the DLLs are; so, add the line:
export LD_LIBRARY_PATH=${HOME}/opencv/lib
to ~/.bashrc and then relogin.To check if it is working, type:env | grep LD_LThen you should see the result like this:
LD_LIBRARY_PATH=/home/<your username>/opencv/lib
If you want to use ffmpeg, follow the steps (Thanks to Phong for his guidance):
- Install two additional packages: libswscale-dev and ffmpeg.
- create a folder /usr/include/ffmpeg.
- For Jaunty Jackalope (Ubuntu 9.04), we need to create some soft links under /usr/include/ffmpeg as follows:
- avcodec.h to ../libavcodec/avcodec.h
- avformat.h to ../libavformat/avformat.h
- avio.h to ../libavformat/avio.h
- avutil.h to ../libavutil/avutil.h
- swscale.h to ../libswscale/swscale.h
- Then run this:
./configure --prefix=${HOME}/opencv--with-ffmpeg --without-quicktime makemake install- And don’t forget to tell the dynamic linker:
export LD_LIBRARY_PATH=${HOME}/opencv/lib
For the system-wide installation, change --prefix=${HOME}/opencv to --prefix=/usr/. If you want to remove OpenCV, use the commands: make uninstall or make distclean
Here I also give an example of Makefile to compile with OpenCV (Thanks to Dr. Dailey again for his example).
#What needs to be built (TARG) from what source code (SRC)
SRC = opencv-test.c
TARG = opencv-test
#Tell make what compiler we use
CC = gcc
#Tell gcc about non-standard places to find include (.h) files
#For a system wide installation use -I /usr/include/opencv
INC = -I $(HOME)/opencv/include/opencv
#Also tell gcc to include debug symbols (-g), give all possible warnings
#(-Wall), but don't generate the annoying "unused function" warning
CFLAGS = -g -Wall -Wno-unused-function $(INC)
#Tell the linker where to look for libraries and what's needed for OpenCV
#For a system wide installation -L isn't necessary
LIB = -L $(HOME)/opencv/lib -lcxcore -lcv -lhighgui -lcvaux -lml
LDFLAGS = $(LIB)
#The object files we want are just the source files with .c -> .o
OBJ = $(SRC:.c=.o)
#What make should try to build by default
all: $(TARG)
#What object files the target executable depends on
$(TARG): $(OBJ)
#Clean up executables, object files, and temp files
clean: rm -f *~ *.o $(TARG)
That’s it. Enjoy OpenCV!
Related posts
5 Comments for this entry
3 Trackbacks / Pingbacks for this entry
-
OpenCV 2.0 released - Kan Ouivirach
October 6th, 2009 on 10:42 am[...] thing I mentioned in the previous blog was that, to install OpenCV with ffmpeg, the soft links need to be created under [...]
-
Why OpenCV Installation is so complicated? | Tanjir's IBlog
February 11th, 2010 on 9:01 am[...] OpenCV is not straight forward. I don’t know why such popular library is left like this. Here is one article which explains easy installation. However, I will add scripts for installing OpenCV [...]
-
OpenCV 2.0在Ubuntu 9.10平台搭建 - 西望瑶池,紫气东来
April 25th, 2010 on 1:27 am[...] 也Google过不少资料,包括这篇和这篇(这位同学奇特之处在于其他博文貌似都是某种中东文字写的),不得不说Google在搜索这组关键词(OpenCV 2.0 Ubuntu)上效果相当不好,让我走了不少弯路。 [...]

January 24th, 2010 on 6:37 am
Thanx for guide…
I want to do the re-installation for opencv (during previous installation i missed ffmpeg and gtk+ and few other things) I am having trouble removing the installed version of opencv on ubuntu 9.04.
i tried using $ apt-get remove opencv
which gave error E: Couldn’t find package opencv
I am able to locate the opencv-doc files but don’t know exactly how to remove it.
apt-cache search opencv gives:-
libcv-dev – development files for libcv
libcv1 – computer vision library
libcvaux-dev – development files for libcvaux
libcvaux1 – computer vision extension library
libhighgui-dev – development files for libhighgui
libhighgui1 – computer vision GUI library
opencv-doc – OpenCV documentation and examples
python-opencv – Python bindings for the computer vision library
hope you will help with this …tia, kl
January 24th, 2010 on 10:03 am
@klm: try “make distclean” under your opencv installation folder (the same folder you run “make”)
hope this helps
January 27th, 2010 on 11:46 pm
@zkan thanks for replying back…but problem persists.
I tried to find the opencv folder that contains *make* file but couldn’t.
I did fresh installation and it gave some linking error so I removed that using command u mentioned.
when i do $locate opencv i get following results:
/usr/bin/opencv-performance
/usr/include/opencv
/usr/lib/pkgconfig/opencv.pc
/usr/local/bin/opencv-createsamples
…
/usr/local/lib/pkgconfig/opencv.pc
/usr/local/lib/python2.6/site-packages/opencv
/usr/local/share/opencv
/usr/local/share/opencv/doc
/usr/local/share/opencv/haarcascades
….
/usr/local/share/opencv/samples/python/watershed.py
/usr/share/opencv
/usr/share/doc/opencv-doc
/usr/share/doc/opencv-doc/AUTHORS
/usr/share/doc/opencv-doc/README.Debian
/usr/share/doc/opencv-doc/examples/c/watershed.cpp
….
/usr/share/man/man1/opencv-createsamples.1.gz
/usr/share/man/man1/opencv-haartraining.1.gz
/usr/share/man/man1/opencv-performance.1.gz
/var/lib/dpkg/info/opencv-doc.list
/var/lib/dpkg/info/opencv-doc.md5sums
i tried autoremove libcv and other dependencies but couldn’t get rid of these files.
could you please suggest something in this regard ..or i think system reinstall would be the only way.
tia- kl
April 1st, 2010 on 11:50 am
I am using Ubuntu Linux,
And i am developing OpenCV application in Java using Eclipse editor.
How to set up OpenCV for Java development in Eclipse?
Can u help?
April 18th, 2010 on 5:35 pm
Hi, nice howto. Maybe it is a helpful tip to AMD Athlon XP (and below…) users to disable the default SSE2 support when compiling (./configure … –disable-sse), because the CPU does not support it and you will end up having segfaults else. Cheers.