← February March May →

Python library for reactable’s TUIO protocol

Although I don’t normally write much about my studies at Bauhaus-University Weimar I’d like to show you today one particular interesting product of my university work: pyTUIO.

First some background: Some time ago I attended a workshop on tangible user interfaces at the great Interface Culture Lab Linz that was held by Martin Kaltenbrunner. We learned a lot of theoretical stuff about physical and tangible user interfaces and even had a look on using a very cool Software: reacTIVision.

fiducial example

reacTIVision is a video tracking software for so-called fiducials (see left image), markers that can be attached to any object. While being filmed by a camera, reacTIVision recognizes these markers and determines their position and other relevant data.

This information is then sent as OSC messages to a specific socket. The Music Technology Group for example created the reactable by using reacTIVision and a custom software. Hop over to Youtube if you want to know how it looks like.

Then last year, during the summer semester, I had the pleasure to work with Nicole Weber to develope the software for her Newsmachine, a realtime video mixer, based on reacTIVision, Python and Pygame. This was great fun but still had some bugs, programmatically and logically. Building a live video mixer with Pygame wasn’t the best idea since it seemed to have reached almost its limit of performance. Anyway, it actually led to something better:

pyTUIO

A Python library that understands the TUIO protocol.

I abstracted most of the logic from the Newsmachine code and tried to make it very easy to start tracking tangible objects. Consider this working code snippet:

import tuio
tracking = tuio.Tracking()

try:
    while 1:
        tracking.update()
        for obj in tracking.objects():
            print obj
except KeyboardInterrupt:
    tracking.stop()

This is all it takes to start receiving positional data of tangible objects.

Nodebox

I’m also very happy to see it included in Nodebox, which is “a Mac OS X application that lets you create 2D visuals (static, animated or interactive) using Python programming code and export them as a PDF or a QuickTime movie.”

I really like the idea of being creative with code, so it was a no-brainer to ask the developers of Nodebox to add the library. Don’t miss the documentation of the TUIO library at the Nodebox site.

While holding two fiducials in front of the camera, the following Python code created in Nodebox the image on the right, for example:

tuio objects demo nodebox

tuio = ximport("tuio")

def setup():
    global tracking
    tracking = tuio.Tracking()

def draw():
    global tracking
    tracking.update()
    fontsize(10)
    for obj in tracking.objects():
        x = obj.xpos * WIDTH
        y = obj.ypos * HEIGHT
        rotate(obj.angle)
        rect(x, y, 20, 20)
        reset()
        text(obj, x, y)

def stop():
    global tracking
    tracking.stop()

Google Code project

I also would like to encourage you to go to pyTUIO’s Google Code project site to learn more about it and see some other examples.

Django March 10, 2008, 3:44 p.m. comments (4)