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
make
make 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_L
Then 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
make
make 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!