Wednesday, February 3, 2010

OpenCv 2.0 with Ubuntu 9.04

Recently I have started working on my final year project, and I got stuck with a pretty nice idea of documenting it on my blog.
I am working on 3-D Modeling using Videos. As usual the first steps of doing a project is to get the development environment settled up, and doing the feasibility study. In our case we had decided to use OpenCV for video manipulation, because of two reason :
1.) It's faster than any other library present out there for the same purpose.
2.) Its pretty advanced(read as a lot of inbuilt functionality) and optimized.

I am just documenting the method which worked for me, there were other easier one's which didn't worked for me :(.

First of all one needs the ffmpeg (for video support) and GTK 2.0 for OpenCv to work properly. Sadly, one needs to check out ffmpeg from trunk and compile it for his own platform, no binaries in Ubuntu repositories.

1.) Check out ffmpeg from their svn repo:
cd ~
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg


2.) Then for sure one needs to compile ffmpeg and install it:
./configure --enable-shared
make
sudo make install


This thing takes its own sweet time, So you can go and get some coffee for yourself.

3.) Then you need to get GTK Development libraries:
sudo apt-get install libgtk2.0-dev


4.) Finally one needs to download code for OpenCV 2.0 and Compile and install it :
cd ~
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.0/OpenCV-2.0.0.tar.bz2
tar -xvf OpenCV-2.0.0.tar.bz2
cd OpenCV-2.0.0
./configure --with-ffmpeg --with-gtk --with-quicktime=false
make
sudo make install


This is again a thing which will give you ample of time to take a break and make some calls to your fiends.

After you are done installing OpenCv, then comes the issue of how to use it. I was using openCV with C++ and tried some sample examples of O'Rielly book.
After a little searching I figured out that to include the OpenCv files while compiling my C++ files I need to use :
g++ `pkg-config --cflags opencv` `pkg-config --libs opencv` filename.cpp -o test


Now, this is neither easy to remember nor easy to type every time I compile some code. So, I found this nice little hack of adding aliases.

There exists a .bashrc file in your home folder. It is basically a config file for your login profile. One can add aliases for terminal commands in this file and then use them :
alias gcv="g++ `pkg-config --cflags opencv` `pkg-config --libs opencv`"


Now whenever, I type gcv in my terminal , it is interpreted as g++ blah blah blah.

I will keep adding the progress of my project to this blog, so stay tuned.

1 comment:

Deepank Gupta said...

Nice post very informative... continue sharing your research on this blog.