Kinect basics on WPF: Part 1

Kinect is quite a fascinating device which have utilities in many fields. Like a person can play a game like FIFA using just his body motion or a medical situation can be measured using a Kinect. Though since quite a time, the device is there in the market but still there are a few applications on Kinect device. So the motive of these tutorial series is to develop a basic understanding of Kinect development.

Here, in this blog post, we will be covering some basics of Kinect V2, where our main focus is on three type of streams: Color stream, Depth stream and Infrared stream. There is one another stream: Body Stream which I will cover in my next post.

 

COLOR STREAM, DEPTH STREAM and INFRARED STREAM

Our Kinect Sensor is just a device which sends only the raw data to our system, now it is upon a developer to use that raw data in whatever way he feels like. But with Kinect SDK 2.0, we get few additional classes to utilize that data. So, the SDK provides us ColorStream class to access the color data from a Kinect Device.

Similarly, to access Infrared Frames coming from Kinect Device we need InfraredStream class which provides us functionality to access infrared frames and accordingly we can perform an operation.

DepthStream class is one special class which is different from the classes discussed above. Using this class, one can access the data of Depth of a person or object standing in front of the Kinect device. This way we can find to how much distance is a visible object from Kinect sensor.

Here, I am building a WPF application in Visual Studio to perform Kinect functionality. To add Kinect DLL file, just follow the steps:

 

Go to the solution explorer of your WPF project -> right click on references -> Add reference -> Assemblies -> Extensions -> Microsoft Kinect.

 

Inside the project, open MainWindows.xaml.cs or the .cs file of your page and add the namespace:

 

Now in the body of the .cs file, add the following code to initial the variables to use Kinect in the application:

 

After initializing variables, add the following code into the Windows_Loaded method. Here, we will fetch the default Kinect sensor into _sensor, so that, there is no error. Then, after checking whether sensor is there or not, open the sensor: _sensor.Open(). Then, we will define which Frames will the _reader be accepting. In the code below, we added options to access three frame source types: Color, Depth, Infrared which we can use

 

Now, after we have added code for initializing sensor, assigning values of FrameSourceTypes to the reader, we will move to the XAML file or the designer file. Here, we have to add some code for Image control within the page so that, we can get the Stream of those three frames on that control. The code will be:

 

Now in XAML.CS file add the following code:

In the above code, I have used ‘_mode’ to toggle between the states of the video stream and comparing it’s value in the reader function to toggle in the video stream.

Now, run the program and test with a Kinect V2. 🙂

I hope with this blog post, the basics of Kinect development on WPF are covered up.  Many more are in the line for helping in Kinect development. Thanks!