"Recovering Gracefully from Loss of Skeletal Tracking"
- Posted: May 11, 2012 at 6:00 AM
- 6,353 Views
Today's project is a sharing of lessons learned by Carl Franklin while creating his GesturePak project (GesturePak (Beta) for the Kinect - A "no code" gesture recording and matching library)
The Kinect For Windows SDK v1.0 is awesome, but it doesn't recover well when it loses sight of you whilst tracking your skeleton. With a timer control and a little code to restart the KinectSensor, you can recover is 5 seconds or less.
This is the same code I use in GesturePak, a gesture recording and recognition SDK for Kinect for Windows.
Create a new WPF application and add a reference to the Kinect SDK assembly:
C:\Program Files\Microsoft SDKs\Kinect\v1.0\Assemblies\Microsoft.Kinect.dll
You don't need any controls for this demo. It simply turns the form red when tracking, and white when not tracking.
The basic idea is that when we lose tracking for the first time, you kick off a timer to fire it's Tick event in 1/2 a second. In the timer Tick handler you stop the Kinect Sensor, Start it up again, and then set the timer's Interval to a more reasonable amount of time. I use 5 seconds, but you should test it in your app. If it's too short, you don't give the Kinect time to track you, and if it's too long and it doesn''t track you, you could be sitting and waiting too long. 5 seconds seems reasonable to me.
When the state changes from not tracking to tracking, you simply disable the timer.
Here's the code in both C# and VB.NET. In each case you can replace the default code behind MainWindow.xaml and run it. The C# app has to have a reference to System.Windows.Forms