Installing OpenCV on Ubuntu

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:

  1. Install two additional packages: libgstreamer0.10-dev and libdc1394-13-dev.
  2. Download OpenCV from sourceforge and extract to a folder, let's say "opencv".
  3. Change directory to that folder and run this command:
    ./configure --prefix=${HOME}/opencv --without-xine --without-quicktime --with-gstreamer --with-1394libs --with-v4l
  4. make
  5. make install
  6. 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):

  1. Install two additional packages: libswscale-dev and ffmpeg.
  2. create a folder /usr/include/ffmpeg.
  3. 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
  4. Then run this: ./configure --prefix=${HOME}/opencv --with-ffmpeg --without-quicktime
  5. make
  6. make install
  7. 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!

How to Move a SVN Repository

It never hurts us if we have backup in our hand!

This blog reminds me about how to move a svn repository to another server. I always google it when I want to do this; so, making a note here is helpful for me. Just follow these step below:

Step 1:

Create a svn dump file with this backup script:

svnadmin dump /path/to/repository > repo_name.svn_dump

It'll contain all of the revisions you made; so, its size is probably quite large.

Step 2:

Transfer the file to another server and then create a new empty repository in that server by:

svnadmin create /path/to/repository

Step 3:

Import the dump file into this new one:

svnadmin load /path/to/repository < repo_name.svn_dump

That's all we need to do!

What if someone's committing a new version on the old server? We can easily solve this by creating an incremental dump file for the particular revision and import it using this command:

svnadmin dump --incremental -r <# of revision> /path/to/repository > rev<# of revision>.svn_dump

Then import into the new server using this command:

svnadmin load /path/to/repository < rev<# of revision>.svn_dump

By the way, if you have many users using the same svn repository, don't forget to tell them that you've already changed the location. To change the working directory, we can use this command:

svn switch --relocate <old working directory> <new working directory>

Hope this helps! 🙂