adrift on a cosmic ocean

Writings on various topics (mostly technical) from Oliver Hookins and Angela Collins. We have lived in Berlin since 2009, have two kids, and have far too little time to really justify having a blog.

OpenCV on the N900

Posted by Oliver on the 27th of July, 2011 in category Tech
Tagged with: maemon900opencvpython

I've been playing around with OpenCV over the last few weeks while reading/coding along with the Learning OpenCV book. Overall I'm pretty impressed with how easy it is to do quite complex things, thanks to the rich library of visual computing functions. The library is natively in C, but there are also python bindings using SWIG. It is actually an interesting exercise taking the examples in the Learning OpenCV book (which were written for C) and rewriting them in Python. Incidentally, my worked examples are here if you want to reuse them or take a look at my terrible code.

Actually there are not too many changes necessary and you don't have to worry about pointers or memory management which is handy. The great thing about having a Python library to use is that it is generally cross-platform. Sure enough, someone has packaged OpenCV for Maemo 5. Unfortunately the default Python version in the Scratchbox build environment for the platform is 2.3, which apparently doesn't play nicely when trying to build python-opencv. So last night I rebuilt against Python 2.5 which is also available in the regular "Fremantle" repositories for the phone and today have a working python-opencv environment.

I ran one of the example programs which simply opens the default system camera and displays it on the screen, both on my laptop and on my phone and this is the result:

OpenCV Screenshot

I'm not sure if OpenCV has any camera focusing calls, but in any case none are used in this example obviously so the quality is not great. There is also some colour-correction that perhaps the standard imaging utilities in the phone uses but OpenCV lacks so the colours are a bit off. Rest assured though, that both the computer and the phone are indeed running the same (very simple) script (chapter2/

A bit more code and you could have the computer and phone tracking each other, and after a few more iterations lead to some kind of T-800/T-1000 cyber-stand-off ;) I'm talking to the python-opencv package maintainer to get the fixes incorporated into the public repositories (extras-devel right now) but if you want them earlier please let me know.

© 2010-2018 Oliver Hookins and Angela Collins