Basically the implementation of the blob tracker native in touchlib is very confusing.
What it does is quite simple though.
There are a couple main steps:
1- Find the blobs in the screen. This is done by counting the number of connected white pixels in the screen. Pixels that touch more than 3 (from top of my head) pixels around them that are also white are part of the same blob. Then it does some checks on the shape too, to see if it is roughly circular. From this part, the blobtracker knows coordinates of blobs on the screen.
2- Now the blobtracker needs to identify which finger corresponds to which blob. This is done by comparing the position of each of the blobs with the blobs in the previous frame:
- If there is a blob close enough in the previous frame, the blob in the current frame gets the ID of the blob in the previous frame: it’s the same finger that moved.
- If there is no blob close enough: it is a new finger, so make a new unused ID for it.
- There are also blob IDs present in the previous frame that get no new blob assigned to them: these fingers are no longer touching the screen.
3- Now we know for each blob either if it is new, if it moved, and we also know the fingers that stopped touching the screen. For each of these options send an event for finger-down, finger-up or finger-moved.
4- OSC then listens for these events and bundles them into a frame and sends them out as TUIO messages to Flash or other applications.
Basically the number of fingers is so small (for the computer) that even for 100 fingers the naive algorithm of comparing each finger to all options from the previous frame is good enough. The native algorithm in touchlib uses a double-recursive function which is more complicated and also performance heavy.
The above naive approach does have the drawback that the data that is collected is a bit rough. For instance, when a finger ‘skips’ over the screen or the user moves really fast, the blob may sometimes get lost esp. with lower framerate cameras. If the blob is lost only for 1 camera frame the finger gets a new ID, and what appears as 1 movement to the user is several movements to the application.
That’s about it. Good luck!