OpenCV 2.1.0 with Python bindings on Maemo (n900)

Howdy How!

Lately I’ve been really busy with my job at the university. However, I decided to give a short moment of my time to share some fruits of my work. I have been always interested in playing with the Augmented Reality stuff. So I decided to challenge myself a little bit and get some tools to work on n900. I found a version from the repository (2.0.something), which was missing the Python bindings. Now that I have lately worked with python (and still am), I really want those bindings to work!

Well, it seemed that there is only one option, to compile and configure everything to work manually. And that is exactly what I did. Finding all this was a pretty hard, so I decided to post everything here on my blog. There are probably some strange things, because I am no real Linux expert (and this is the first time ever I have created .deb packages), but following my instructions you should get opencv to work on maemo (with the newest PR1.2 firmware). So, keep on reading.

How to get OpenCV to work on n900

The OpenCV needs to be build inside scratchbox and then deployed to the real n900 in question. The installation is based on the OpenCV installation instructions from the wiki: http://opencv.willowgarage.com/wiki/InstallGuide%20:%20Debian

I have built successfully the whole system from the stable package, not from the SVN (for some reason I wasn’t able to get cmake to compile from SVN)

NOTE: This can be built for both the X86 and the ARMEL. Just change to different scratchbox environment with sb-menu

If you want to try things on the emulator, you should compile the X86. Otherwise use ARMEL (so you can deploy it to the n900). Probably might be best to do both?

Working with the scratchbox

If you want to use the latest package, get subversion.

1. Install subversion

fakeroot apt-get install subversion

2. Install the rest of the prerequisites

apt-get install build-essential

apt-get install cmake

apt-get install pkg-config

apt-get install libpng12-0 libpng12-dev libpng++-dev libpng3

apt-get install libpnglite-dev ibpngwriter0-dev libpngwriter0c2

apt-get install zlib1g-dbg zlib1g zlib1g-dev

apt-get install libjasper-dev libjasper-runtime libjasper1

apt-get install pngtools libtiff4-dev libtiff4 libtiffxx0c2 libtiff-tools

apt-get install libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-prog

apt-get install ffmpeg libavcodec-dev libavcodec52 libavformat52 libavformat-dev

apt-get install libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev

apt-get install libxine1-ffmpeg libxine-dev libxine1-bin

apt-get install libunicap2 libunicap2-dev

apt-get install libdc1394-22-dev libdc1394-22 libdc1394-utils

apt-get install swig

apt-get install libv4l-0 libv4l-dev

apt-get install python-numpy

3. Get the files and save them to your MyDocs scratchbox directory

(if default installation is done, this can be found in ubuntu from /scratchbox/users//home//MyDocs/

RECOMMENDED: download the latest stable Unix version

http://sourceforge.net/projects/opencvlibrary/files/

untar the file for example to OpenCV-2.1.0/ (the version I have tested this with)

or if you want to try your luck, from svn

https://code.ros.org/svn/opencv/tags/latest_tested_snapshot/

4. create a build directory (the only difference to that one, is that o is not a capital letter

mkdir opencv-2.1.0

cd opencv-2.1.0

5. Now, lets use cmake to generate the makefile

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D BUILD_PYTHON_SUPPORT=ON -D BUILD_EXAMPLES=ON ../OpenCV-2.1.0

This will use the cmake to build the make file

6. Now, we must create the .deb package for the opencv

export DEBULLNAME=”Your name”

dh_make -e your.name@example.org –createorig

When asked for what kind of binary, just type s (= single)

After this you can edit the installation info etc. at ./debian (for example nano ./debian/control and just write a short description here)

7. Now, build the package (you have to be in the opencv-2.1.0/ folder

dpkg-buildpackage -rfakeroot

This will display a lot of output and you should see the build process in percentage running towards 100% (this will take some time, so grab a cup of coffee. For example check http://coffeeproject.com/shop/magento/index.php for some nice stuff)

8. If everything went okay, now you should be able to install the application from the .deb package

cd ..

fakeroot dpkg -i opencv-2.1.0-1_armel.deb

OR

fakeroot dpkg -i opencv-2.1.0-1_i386.deb

Now you should have the whole thing installed on the machine (now scratchbox environment). The problem here is, that python is not configured properly.

9. Configure library path

Because the .deb installer does not install all the libraries correctly (at least with these instructions), you have to configure the path manually.

Export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH

sudo ldconfig (OR fakeroot, if inside scratchbox)

10. Configure Python

Now, finally only one part is still missing! The thing we went all this trouble through, configuring the python to work. In n900 you can replace python2.5 with just basic python command

Python2.5 [in scratchbox python leads to 2.3 version of python]

>>>import sys

>>>print sys.path

>>>sys.path.append(“/usr/local/lib/python2.5/site-packages/

And after this everything should work just fine. Test it

11. Test OpenCV with python

>>>import cv

If no error comes up, this should work now😀 You can test the installation in scratchbox by going to the original folder OpenCV-2.1.0/samples/python. Normally, when running on PC machine, the python test could be done for example by running python delaunay.py. If you try to run

python2.5 delaunay.py

You will get no error, but nothing will show on the screen (at least when run solely inside the scratchbox and no virtual machine). If you run the same thing in n900, it should display you some nice stuff😀

Okay, that was it. Have fun tinkering with opencv and python. If you get any errors/bug/missing things, please, post here so we can try to fix those.

-Japskua

12 thoughts on “OpenCV 2.1.0 with Python bindings on Maemo (n900)

  1. The libs is too large,my rootfs is not enough to used.
    My rootfs only has 30MiB.
    IS your rootfs enough in your N900,when you after installed those things?

    Thanks for your info.

    • Hi, good to see that people are still interested in this post😀
      To asnwer to your question amd5200, I cannot say for sure, because after I updated the firmware (read: formated the whole memory of my phone) I haven’t installed the OpenCV back. I am now away for few weeks from home without my cables, so I cannot check the case. However, if I remember correctly, I had no problems with the rootfs size.
      I promise to get back in to this after getting back home. Just my thought though, maybe installing the opencv to another location on the phone might help?

  2. on my n900 it says no module named cv.
    i installed compiled opencv from repo.
    i installed python-opencv too.
    would it work if i copy opencv2.1 modules on my computer to my n900’s python modules path?

    • If I remember correctly, installing the opencv from the repo has missing python bindings. I doubt it works if you just move the modules from your PC because it uses different architecture than N900. I just recommend following my instructions on getting the thing to work (it does take some time and is a bit complicated, but it works)

  3. btw which repositories do we have to add to get all those prerequisites?
    i’ve added extras extras-devel etc. all the repos.
    but im still missing some of those packages for example : libpng.. , libjpeg8

  4. i followed all the steps you mentioned above but still
    No module named cv😦 :(: :(:(:(

  5. there is no file in my site-packages dir.:/

  6. * If you also want to use OpenCV from Python, add this:

    apt-get install libpython2.6 python-dev python2.6-dev # Only if you want to use python

    it says on debian-opencv installation page ??

    • Hmm… It might be that you are missing Extras-Testing? Perhaps that solves the problems? Also, you should have installed python-dev. (that is kind of a prerequisite to even use python at all on n900).

  7. i got a lot of cv so files on my /usr/local/lib directory
    libcv.so
    libcv.so.2.1
    libcv.so.2.1.0
    libcvaux.so
    ….. and so on
    but i got only numpy files under /usr/local/lib/python2.5/
    and no files under site-packages
    anyway i’ll try recompiling after i get all of those prerequisites installed fully.

  8. only debian repos. has libpngwriter package for armel.
    and im running on an ubuntu machine:/ ubuntu has same package for only amd64 and i386 i guess that’s the problem.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s