June 8, 2010

How do I install OpenCV on a Fox Board G20?

Posted by : Sander
Spoiler: there’s a download link for the libraries at the end of this article.

Today, I decided I want to install OpenCV (Open Source Computer Vision) on my Fox Board G20 to prepare for a possible project that I might be doing in the near future. Already having an OpenCV demo on a regular PC, I thought it would be worth the effort to try and get that demo running on my G20 as a true embedded application. I like to share my results with you, dear reader, in case you’d like to create an embedded OpenCV-based vision solution as well.

If you want to install OpenCV on your Fox Board G20, make sure you read this post first: How can I add memory to my Fox Board G20?

The default OpenCV library that you get when you apt-get install libcv-dev is version 1.0. That’s a bit old, wouldn’t you agree? For a demo project, we are using OpenCV 2.1.0, which is what I want to install [1].

Before I continue, first a little warning: this is a rather lengthy process. Not that you have to be at your PC at all times, but you’d better be prepared that you can’t use your Fox Board G20 for quite some hours. :)

Well, let’s get started and download OpenCV:

debarm:~# wget http://sourceforge.net/projects/opencvlibrary/files/opencv-unix/2.1/OpenCV-2.1.0.tar.bz2/download

In case you haven’t installed a GNU compiler, I suggest you do so now:

debarm:~# apt-get install gcc g++

There are some tools that you need to install and some that you may want to install. I suggest to install them all:

debarm:~# apt-get install bzip2 pkg-config

Now, you can unpack OpenCV:

debarm:~# tar jxvf OpenCV-2.1.0.tar.bz2

After unpacking OpenCV, enter the directory OpenCV-2.1.0 that was just created, create a build directory called ‘release‘ and enter it:

debarm:~# cd OpenCV-2.1.0
debarm:~/OpenCV-2.1.0# mkdir release
debarm:~/OpenCV-2.1.0# cd release

One of the tools that you will need to build OpenCV is cmake. You can simply install it using apt-get:

debarm:~/OpenCV-2.1.0/release# apt-get install cmake

Now, we can start building the OpenCV build environment:

debarm:~/OpenCV-2.1.0/release# cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local ..

This cmake command will create a Makefile for the release target, which means you are ready for installing OpenCV:

debarm:~/OpenCV-2.1.0/release# make

You will see many lines similar to this one:

[ 1%] Building C object 3rdparty/lapack/CMakeFiles/opencv_lapack.dir/dcopy.o

and you’ll have plenty of time drink coffee, read a book or do some actual work. So make sure you have a full pot of coffee available (in any of these cases). Uhm, perhaps I should have mentioned this earlier… Still, you’ll have more than enough time to make a pot of coffee, drink it and make another pot of coffee. :-)

Better still, you can start your build in the evening and have a good night’s sleep while your Fox G20 is doing all the hard work!

When, finally, your build has finished, you can install the libraries, include files and documentation:

debarm:~/OpenCV-2.1.0/release# make install

There you go! You’ve successfully installed OpenCV 2.1.0 on your Fox Board G20! You are now ready for taking it for a spin.

If you’ve installed pkg-config, you can easily find the include files and libraries for OpenCV:

debarm:~/OpenCV-2.1.0/release# pkg-config opencv --cflags
debarm:~/OpenCV-2.1.0/release# pkg-config opencv --libs

which you can also incorporate in your Makefile. But I’ll leave this as an excercise for the reader.

After having gone through this myself, I thought perhaps I should spare you this ordeal (did you see the spoiler at the beginning of my article?). That’s why I created a package for you to download and install in case you want to play around with OpenCV right away. Please beware that the package only contains the include files and libraries. Here it is:

http://www.asksander.com/download/opencv-2.1.0.tar.bz2

Just download the file onto your Fox G20 and install using tar (from within the root of your file system):

debarm:/# wget http://www.asksander.com/download/opencv-2.1.0.tar.bz2
debarm:/# tar jxvf opencv-2.1.0.tar.bz2

It will install the include files in /usr/local/include/opencv and the libraries in /usr/local/lib.

Have fun playing around with OpenCV! If at some point in the future you’ve created a cool feature with OpenCV on your Fox G20, let me know! I’d be very interested to hear about it!

Kudos

[1] OpenCV Installation Guide


No Comments

(required)
(will not be published) (required)
(opitional)