Kinect’ing with F# and XNA

Kinect is an exciting new input device for computing. It is a natural for gaming but can be applied to many general, PC applications as well.

Update – Kinect coming to laptops (it seems)

F# – as functional language – offers some useful features for gesture recognition, namely the ability to create “functional state machines” (more later).

I have been playing around with Kinect and XNA in F# and have thus far achieved the following:

A spinning cube with pictures of cars and the ability control the spin and its direction by hand gestures. The picture below shows the cube and two circles (which represent the hand positions). Putting both circles on the cube will stop its spinning; putting the right-hand circle will make the cube spin right; and so forth.

The source for the above code is here:

Now the interesting part about F# and functional state machines. Functional programming (especially the tail-recursive kind) is a useful way building pattern recognition machinery. As an example, see my (much faster) json parser that uses functional state machines – intead of regular expressions – for parsing json numbers and strings:

Note the (|PJsonNumber|_|) active pattern function and the equivalent regular expression in the comments therein. The F# code is much longer but its also much faster because it works in a streaming mode (lots of intermediate object creations are not required). But the main point is that such a method of pattern recognition can be applied almost any s


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s