Since I have been playing around with the Kinect for Windows SDK I’ve created a lot of little new projects and samples to try things out. Starting point was always something like this:
var sensor = KinectSensor.KinectSensors
.FirstOrDefault(_ => _.Status == KinectStatus.Connected);
if (sensor == null) throw new InvalidOperationException("No kinect connected");
sensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30);
sensor.SkeletonStream.EnableTrackingInNearRange = true;
sensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
sensor.SkeletonStream.Enable();
sensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
sensor.Start();
A lot of code just to set up a Kinect sensor, isn’t it?
Why not using a fluent style with less and cleaner code to set up a Kinect Sensor? So I came up with the idea of FluentKinect, a project with a few extension methods. Now I can set up my Kinect Sensor this way:
var sensor = KinectSensor.KinectSensors
.FirstOrDefault(_ => _.Status == KinectStatus.Connected);
if (sensor == null) throw new InvalidOperationException("No kinect connected");
sensor.EnableColorStream()
.EnableSkeletonStream()
.EnableDepthStream()
.Seated()
.NearMode()
.Start();
Because I most often use the 640×480 option anyway, the format is an optional parameter when enabling the streams and it defaults to *640x480Fps30.
I’ve exracted the two little lines that gets the first connected Kinect Sensor to a class called KinectConnector. At the moment an exception is thrown when no Kinect unit is connected. This is not a very good way of handling this scenario and will be changed in the future.
Now the code is even cleaner:
var sensor = KinectConnector.GetKinect()
.EnableColorStream()
.EnableSkeletonStream()
.EnableDepthStream()
.Seated()
.NearMode()
.Start();
For an even shorter and quicker Setup I’ve implemented the method ‘KickStart’ which enables the three streams and calls Start() on the KinectSensor object.
For future ‘try out samples’ I’ll just have to code this now:
var sensor = KinectConnector.GetKinect()
.KickStart();


