Kinect is an amazing piece of technology. Not only for gaming, it can be used for variety of uses ranging from Healthcare, Security, IT etc. Starting with coding for Kinect seems daunting at first, mainly due to lack of knowledge and starting material.
This article documents my first attempt at coding for Kinect. So basically it’s a beginner level article which introduces us to Kinect. Before you begin, you must ensure that the following pre-requisites have been met.
- Kinect for Xbox 360 – You should have the retail version of Kinect hardware.
- Kinect for Windows SDK should be installed on your system.
- Coding4Fun Kinect Toolkit should be installed on your system.
After you install the Kinect for Windows SDK, plug-in your Kinect to your PC via the USB port and some device drivers should automatically get installed. Finally you should be able to see this screen.
Now that you have all set up, fire up Visual Studio and create a new WPF project. Add a reference to “Microsoft.Research.Kinect.dll” and “Coding4Fun.Kinect.Wpf.dll”. Next we will create a very basic application which captures Kinect’s RGB Video, Depth Video and try to create a Skeleton out of it. We will basically re-use the code from “Skeletal Viewer” sample that comes with Kinect for Windows SDK.
We will add two images to our XAML window to display the video streams. We will also add a Canvas to display the skeleton that we are tracking. Pretty simple!
<Window x:Class="MyFirstKinectApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" WindowState="Maximized" Loaded="Window_Loaded">
<Grid>
<Image x:Name="VideoFrameImage"
Height="500" Width="500" HorizontalAlignment="Left"
VerticalAlignment="Top"/>
<Canvas x:Name="SkeletalFrameImage"
Height="500" Width="500" HorizontalAlignment="Right"
VerticalAlignment="Top"/>
<Image x:Name="DepthFrameImage"
Height="500" Width="500" HorizontalAlignment="Left"
VerticalAlignment="Bottom"/>
</Grid>
</Window>
Coding4Fun dll helpfully add few extension methods which makes displaying the video streams a breeze. All we have to do is write:
VideoFrameImage.Source = e.ImageFrame.ToBitmapSource();
Next comes calculating and displaying the skeleton in the Canvas. You can follow the source code to see how it is actually being done.
Finally we end up with the following output:
That’s it! This is our sample sample application. As you move, the skeleton will mirror your movements. All we have to do now is to detect those movements and have some fun!
Comments
Post a Comment
As far as possible, please refrain from posting Anonymous comments. I would really love to know who is interested in my blog! Also check out the FAQs section for the comment policy followed on this site.