Click here to Skip to main content
13,344,016 members (97,775 online)
Click here to Skip to main content
Add your own
alternative version


27 bookmarked
Posted 20 Nov 2011

Getting most of Kinect SDK in C# - part 1 of ?: Initialization

, 6 Jan 2012
Rate this:
Please Sign up or sign in to vote.
A series about experimenting with Kinect for Windows SDK
This is an old version of the currently published article.


This is part one of series documenting my experiments with Kinect for Windows SDK.
After first two or three artices this seriers should make quite good walktrough for beginners and nice reference for more advanced developers.

Series table of contents:

  1. Initialization
  2. ImageStreams
  3. Coming soon...


Kinect is a sensor originaly developed for Microsoft's XBOX 360 console. It has regular video camera, IR camera for depth detection and array of microphones.
Here you cand find all information about Kinect and its SDK for Windows.

SDK basics

To use SDK in your application you need to reference Microsoft.Research.Kinect assembly. It contains two namespaces:

  • Microsoft.Research.Kinect.Nui - Used for visual features
  • Microsoft.Research.Kinect.Audio - Used for audio features
At this point I will focus on NUI part of SDK and its features:
  • DepthStream - Interface to depth sensor
  • VideoStream - Interface to video camera
  • SkeletonEngine - Engine for tracing up to two human bodies
  • NuiCamera - Device info and control (mainly for getting/setting elevation angle)

To start coding you need to use the Runtime class from SDK. This class provides an entry point for device enumeration and initialization. In most of cases all you need is to get instance of Runtime class:

Runtime rt = Runtime.Kinects[0];

This will give you control over first Kinect found in system. If you have more Kinects connected you will want to enumerate devices trough Runtime.Kinects collection:

foreach (Runtime CurrentRuntime in Runtime.Kinects)
    // Do your stuff...

Runtime Initialization

No matter which way you will get reference to Runtime you must Initialize() it. Failing to remember about it will cause exceptions while accessing ImageStreams or SkeletonEngine.

Before calling Initialize() you should check the status of runtime and device by examining Status property.
Documentation describes statuses as:

  • Connected - The sensor is fully connected and ready.
  • Error - An error has occured.
  • Disconnected - The sensor is not connected to the USB connector.
  • NotPowered - The sensor is not powered up.
  • NotReady - Some part of the sensor is not yet ready.
You should only proceed if Status is KinectStatus.Connected. Status can be monitored by attaching to Runtime.Kinects.StatusChanged event.

Upon initialization several options are passed to Runtime.
According to documentation their meaning is quite straightforward:

  • UseColor - Process color information.
  • UseDepth - Process depth information.
  • UseDepthAndPlayerIndex - Process the player index.
  • UseSkeletalTracking - Process skeletal tracking data.
Not enabling some of features probably will result in performance changes. I will try to verify it later.

Next thing you should do is to Open() the ImageStreams. Again, failing to remember about this will result in exceptions when accessing frames. Providing wrong parameters will result in InvalidOperationException.


                          | RuntimeOptions.UseSkeletalTracking
                          | RuntimeOptions.UseColor

CurrentRuntime.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution1280x1024, ImageType.Color);
CurrentRuntime.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex);


Pieces of code shown above are taken from my first working application - InfoTool.
At the moment all this tool does is:

  • Enumerating trough devices
  • Initializing all devices
  • Opening ImageStreams
  • Displaing all information collected during steps above
Here is a sample output:


This sample output shows that there is one Kinect available for usage and all initializations where executed successfully.
As you can see, VideoStream and DepthStream have some improper parameters at startup and are changed to proper ones by calling Open().

Points of Interest

Next experiments will include:

  • Determine best way of working with ImageStreams
  • Skeletal tracking
  • Benchmarking / Performance tuning


2011-11-20: Initial submission

2012-01-06: Added series TOC and updated source code (common for whole series) 


This article, along with any associated source code and files, is licensed under The Microsoft Public License (Ms-PL)


About the Author

Jarek Kruza
Poland Poland
Programming since 10 years old with first commercial app sold in age of 16.

In past got Bachelor's degree in Computer Sciences and worked as Linux administrator and software developer.

Currently slightly over 30 and working as IT Project Manager for Flextronics.

Still coding for fun and/or money.

You may also be interested in...

Comments and Discussions

Discussions on this specific version of this article. Add your comments on how to improve this article here. These comments will not be visible on the final published version of this article.
QuestionTrying to work with Microsoft.Kinect Pin
Scott Zastrow26-Feb-14 15:05
memberScott Zastrow26-Feb-14 15:05 
AnswerRe: Trying to work with Microsoft.Kinect Pin
Jarek Kruza26-Feb-14 21:30
memberJarek Kruza26-Feb-14 21:30 
QuestionI have downloaded a code for Kinect and face\ng the following problems. Pin
Prafulla Ashok Natu12-Mar-12 2:29
memberPrafulla Ashok Natu12-Mar-12 2:29 
AnswerRe: I have downloaded a code for Kinect and face\ng the following problems. Pin
Jarek Kruza12-Mar-12 2:36
memberJarek Kruza12-Mar-12 2:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.180111.1 | Last Updated 6 Jan 2012
Article Copyright 2011 by Jarek Kruza
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid