I love to do image processing and Haskell and wanted to put these two things together in an “effective” way.

Why do I want to program in Haskell? The answer is simple: I love the declarative style of functional programming. I can directly write my formulas into code. I waste less time doing rote jobs and think at a higher level, so it is good for my grey cells as well.

Also, I hate the fact that I have to manage the memory by myself in C / C++. My biggest problem with C is that, I am never at peace with my code. There might be a memory leak somewhere, a global variable might not have been updated and all that crap. My mind twists and turns in trying to reason about code. I just wanted a language where I would write code and just forget about it and it works just fine 🙂

The problem with doing image processing in C is that, using the default Haskell data types (lists, functions) makes the program too slow. One has to expect such speed hits as this is a very high level programming language. However, there are a few array libraries that speed up the code. The sped up code might not compete with C but it is reasonably fast.

I have used the hmatrix library for representing an image. What I like about this library is that there are a whole lot of lapack algos that can be implemented on them. This library allows one to write purely functional code. Just write the image as a 2D function( func (i,j) ) and use buildMatrix, voila! you have a new image.

Hmatrix was just perfect for the array library. I still had lot of problems with interfacing with my web camera. I understand that there is a HOpencv library which can do that but after glancing through the doumentation I felt that the API requires me to stay inside the IO monad. Which means the same stateful programming that I much abhor. Added to that it did not compile on my system and I had to find another way to grab images.

There seem to be nice examples on internet for grabbing images from web cameras (using v4l2 in linux) and I modified a C source and wrote FFI bindings to it. I am truly elated to find that the FFI bindings to v4l2 based image grabbing and the hmatrix work seamlessly :).

If any of you require the bindings reply and I will try to post them.