Kinect SDK Beta is here, and i’ve already played, short tutorial for basics

well it’s the eve of “zelda: ocarina of time” to be released on the 3ds, and Microsoft finally released the Kinect SDK beta, totally unrelated i know, but just to get the context of time here. GMT that is, as out US counterparts have to wait a few days later for zelda. Anyhoo, its Thursday the 16th of June and the SDK for kinect is finally available on windows. The research subdomain of Microsoft finally stopped its lies of an end of spring release and changed its pages to a download link and some live coverage of the release event.

The kinect programming api works with either c++ or c# and visual studio has express versions of both of these for free, i think you just need to register to use them, being a student i’ve got the full visual studio ultimate installed so i won’t be going through that bit, but if you’re embarking on this journey then you should already know your way around an IDE.

my src code for my little app =here ya’ll

And the tutorial, if you can call it that, is after the continue reading..

Some of the examples that are available also need directX sdk and runtime installed. The little tutorial i’m about to go through also uses coding4fun libraries that need to be downloaded too, this made it simpler for the depth video, though you could just use the source code that comes in an example and is found at C:\Users\Public\Documents\Microsoft Research KinectSDK Samples\NUI\SkeletalViewer\ after you’ve installed the sdk. All of the kinect SDK needs .net 4 installed though and only windows 7 is supported.

There are some videos from the which show the basics of what to do, i followed some of them and noted down some of the more core things, the first things to do are to download the sdk from and the coding 4 fun library from and if you havent the IDE then either the visual studio express for c# or c++, this little tut is in c#, grab them from

once installed, load up visual studio and create a c# project of type wpf application

In the solution explorer window go to references  right click add reference and in the .NET tab order by name by clicking name heading and find Microsoft.Research.Kinect and add it. To add the coding for fun library go to browse and fin where you unzipped the dll, choose the wpf one.
add reference in visual studioadd research kinect sdk reference
Next make sure the properties window is open
view -> properties window

click outside of the box in MainWindow.xaml if no properties are showing and the properties box should come up. Clicking in the window itself might refer to grid properties, we want window properties which is the outside part, grid or windows will be named in the top of the properties window. Now click events in the properties window, search “loaded” and double click “loaded” for the loaded event stub code to be added to the MainWindow.xaml.cs file. I assume this is like the code behind file in aspx web page development. Do the same for “Closed”. typically the signature looks like
private void Window_Loaded(object sender, RoutedEventArgs e)
loaded event
closed event

now the cs file is there add the using statements for kinect to the bottom of the using list, the list is at the top of the file.

using Microsoft.Research.Kinect.Nui;
using Microsoft.Research.Kinect.Audio;
using Coding4Fun.Kinect.Wpf;

Nui is Natural User Interface

Next create a runtime object, have it as a global variable but a new object created in MainWindow(),

Runtime nui;
public MainWindow()
nui = new Runtime();

Then initialize it in theprivate void Window_Loaded(object sender, RoutedEventArgs e) event with:  nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);

In the private void Window_Closed(object sender, EventArgs e) add: nui.Uninitialize(); this last statement stop the program from hanging when its closed

private void Window_Loaded(object sender, RoutedEventArgs e)
nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);

Window_Closed((object sender, RoutedEventArgs e)

Great, add an image from the toolbox to the grid, the grid should be there by default, you’ll know the grid by the code view of the xaml file, the grid makes it easier to drag things around. make the image 320 x 240, copy and paste it to make another, to position them you may need to use the margin properties in the properties window.

I’ve also added buttons to move the camera up and down for now, apparently this shouldn’t be done often, no more than 15 times every 20 seconds, so don’t over do it lol. so, with a button selected go to the properties in the properties window and find content to rename the text within the button, i named mine up and the other down. genius i know, also with the button selected go to event and double click  “click” to add a click event in the code, it will give you a click event stub in the code (the cs file). you can also add click=”some_name_of_button_event” to the button code in the .xaml file the stub will generate its name from that. While we’re at it, lets add a text box, the code in the xaml should have a name for the textbox, something like textBox1. we can use this in the cs file.

Moving on, add some code to them clicks, just some thing simple like the following for the up button click event
if(nui.NuiCamera.ElevationAngle < 20)
nui.NuiCamera.ElevationAngle += 5;
textBox1.Text = nui.NuiCamera.ElevationAngle.ToString();

and for the down button click event
if(nui.NuiCamera.ElevationAngle >-20)
nui.NuiCamera.ElevationAngle -= 5;
textBox1.Text = nui.NuiCamera.ElevationAngle.ToString();

maybe also wrap them up in a try catch block, sometimes it gave errors (maybe that maximum amount of usage thing)

What the above does: it just tilts the kinect and then shows the value in the text box, 0 is level and it goes about 27 either way.

next on the window load event add a video event. Note after the += press tab tab, that should put the code in and create the event stub code
nui.VideoFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_VideoFrameReady);
and then open the stream
nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);

in the void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e) event that should of been created add the following where image1 is the image added to the window earlier (it may be a different name, look for the name of the image in xaml view)
PlanarImage image = e.ImageFrame.Image;
image1.Source = BitmapSource.Create(image.Width, image.Height, 96, 96, PixelFormats.Bgr32,
null, image.Bits, image.Width * image.BytesPerPixel);

That’s the video sorted, now for the depth, this uses the coding4fun library

in the window load mehtod add
nui.DepthFrameReady += new EventHandler<ImageFrameReadyEventArgs>(nui_DepthFrameReady);
nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth);

and in void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e) add
PlanarImage image = e.ImageFrame.Image;
image2.Source = e.ImageFrame.ToBitmapSource();

extra notes
stride one row of pixels in memory to the next. thats image width and padding.

the videos i started from are from

i didnt go through the following yet thouhg, the skeletal one came before the camera one apparently

This entry was posted in General, lartens, News, PC, Tech and tagged , , , , , . Bookmark the permalink.

1 Response to Kinect SDK Beta is here, and i’ve already played, short tutorial for basics

  1. Dark Owner says:

    Hello I was checking out your site and you seem to have an interesting application.
    Its within the title “Kinect SDK Beta is here, and i’ve already played, short tutorial for basics”
    I don’t know if you can send me the code please?


Leave a Reply

Your email address will not be published. Required fields are marked *