I am back to work on the OSX Cocoa multi touch thing after being away doing some paying work for a few weeks. I am pretty happy with the prototype, as far as most of the concepts seemed to work OK. The only thing that was a bit iffy was my recursive blob finding algorithm. It works fairly well and fairly quickly, and it was fun to figure it out, but I am sure that it is very sub-optimal. So, i went to find out how the big boys do it. I grabbed the opentouch libs (thanks Pawel for all the great work!) and read the blob detector code.
Now i am a pretty code-savvy guy, i have been coding in C-like languages for a loong time now, but these pixel-level algorithms make my head spin without some direction as to what is really going on. So i had to look further afield. Somewhere in Pawels documentation I came across a reference to this paper:
A Linear-Time Component-Labeling Algorithm Using Contour Tracing Technique
Which is basically what the opentouch algo is based on. So I started from scratch (so i would know how it all worked in the end) and rewrote the algorithm described in the paper in Cocoa. (well, with a few little C bits, but mostly Cocoa). With a nice working blob finder and a nice working sequence grabber and a stack of other design ideas that are scattered through my prototype, i started a new project form scratch to make a proper application. So far what I have is a very stripped down blob detector.
All it does so far is grab images from any firewire cameras and analyze them for blobs based on a simple threshold and background subtraction. It hasnt really been optimized for speed yet, although it is pretty quick. I think the slowest part is just setting the image into the NSImageView. Those views were never really meant to show video, so if you bump the raw camera size up to 640×480 it can get a bit slow. But I will be doing quite a bit of optimization later on. (and for actual blob detection, you really dont need to see the video, and if you did, it would make more sense to use a different view)
There is a pre-process pipeline (sorta) so if you feel the need to add any filters or anything before it gets to the blob detection portion of the show, you can do that easily. The blob detector is currently written to handle NSImages, but it would be fairly trivial to change that for CIImages or CGImages. (or all three)
In any case, here is the code for anyone who wants it:
[UPDATE:] i managed to more than triple the performance of the blob detector last night. I will post more details and the newer code in a new blog post a bit later this morning once i have had some brekky and caffeine. :-)












Awesome work Ben, can’t wait to test it :-)
OpenTouch code is nasty in many places :-) So rewriting it to Obj-C makes a lot of sense it allows for better integration with OS X. What happened to the previous version of your software, the one with configurator ?
Best,
Pawel Solyga
Hey Pawel,
Yeah, the older version of the software is a big mess. It is the prototype and it is filled with dead-end experimental code, two or three different ways to get the same things done, and all sorts of debugging methods and other junk. Not to mention poorly commented and such. But is was, as i said, a prototype. I was going to post it, but I dont have time to go through and clean it up, so instead i started a new app.
I am now going back through that code and refactoring it, doing some performance testing and basically taking a bit more rigorous approach to the development process. Part of that is basically rebuilding the new app from the ground up with the new refactored bits and pieces. this should eventually yield a beta-quality app. (which i can then update and add onto) that is what i am posting.
Cheers!
-b
Ok sounds good. Looking forward for newer source code with better performance of blob tracker.
Great work:-)
Cheers,
Pawel Solyga