HeiRes – MS Hackathon – PartyCrasher

On 23rd May 2014 the company HeiRes organized together with Microsoft Germany a hackathon in my hometown Dresden. The goal was to build an app in about 8 hours through the night.
I joined a team with Christian and our idea was to build a ‘PartyCrasher’-App. When you leave your kids alone at home over the weekend they may get the idea to have a party at your house which you may not want because they made a mess the last time. So why don’t you set up the PartyCrasher App in you living room that consists of a Kinect for Windows controller that is hooked to a little PC. The Kinect watches the scene in the living room and starts to take pictures as soon as there are more than a specified number of people, for example more than 3. At this time the Kinect starts to take pictures in an interval that you can configure (maybe every minute).

So we’ve started the hackathon with this little architecture in our mind.
PartyCrasher

In this blog post I want to share how easy it was to program this little Kinect service (console application) that is hooked to the Kinect hardware. We’ve made use of the Kinect for Windows SDK V2 Preview, Kinect.ReactiveV2 and Rx to implement the photo shooting every specified amount of time as soon as there a more than the specified number of people in the scene.

using Kinect.ReactiveV2;
using Microsoft.Kinect;
using System;
using System.Linq;
using System.Reactive.Linq;

static void Main(string[] args)
{
  var kinect = KinectSensor.Default;
  kinect.Open();

  var frameDescription = kinect.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Rgba);
  var bytes = new byte[frameDescription.Width * frameDescription.Height * 4];

  var moreThanPeople = 3;
  var intervalInSeconds = 60;

  var reader = kinect.ColorFrameSource.OpenReader();
  var bodies = new Body[6];

  var subscription = kinect.BodyFrameArrivedObservable()
                           .SelectBodies(bodies)
                           .SelectTracked()
                           .Where(_ => _.Count() > moreThanPeople)
                           .Sample(TimeSpan.FromSeconds(intervalInSeconds))
                           .Subscribe(bs =>
                           {
                             using(var frame = reader.AcquireLatestFrame())
                             {
                               if(frame == null) return;
                               frame.CopyConvertedFrameDataToArray(bytes, ColorImageFormat.Rgba);
                             }

                             SaveInBlobStorage(frameDescription, bytes);
                           });

  Console.WriteLine("[ENTER] to stop");
  Console.ReadLine();

  subscription.Dispose();
  kinect.Close();
}

We’ve continued the hackathon with implementing the bits that saved the pictures in Azure BlobStorage. The file references to the BlobStorage were saved in a ravenDB on ravenHQ. Later on we’ve implemented an ASP.NET MVC service on Azure websites that served the pictures taken to a Windows Store App. While implementing the picture download in the Windows Store App we unfortunately ran out of time. This was the App when we had to stop.
PartyCrasherApp

Anyways the whole hackathon was really good fun. Big thanks to HeiRes and Microsoft and maybe some time in the future we’ll finish the PartyCrasher-App.

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s