Setting Up Your Development Environment (Beta 2 SDK)

Download

Right click “Save as…”

Embed code for this video

Copy the code above to embed our video on your website/blog.

Close

Video format

Note: These selections will fall back to the next best format depending upon browser capability.

Close

Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)

Please use the newly updated Kinect for Windows SDK Quickstart series. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.

 

This video covers how to set up your development environment. You may find it easier to follow along by downloading the Kinect for Windows SDK Quickstarts samples and slides that have been updated for Beta 2 (Nov, 2011).

  • [00:35] Sample Requirements
  • [01:50] Starting the Demo
  • [02:13] Adding References
  • [02:45] Coding4Fun Kinect Library
  • [03:23] Initializing the Kinect Runtime
  • [05:41] Uninitializing the Kinect Runtime

Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)

The video in the Kinect for Windows SDK has not been updated, but the tutorial below has the following changes:

  • The Microsoft.Research.Kinect DLL version is now 1.0.0.45.
  • The requirements for DirectX samples have been clarified to say that they are only required for C++.
  • The speech sample requirements have been updated for Beta 2. If you are using an x64 PC, note that you should install both the x86 and x64 Speech Platform Runtime (see Speech samples below).
  • The source code for shipping examples is now in "\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip"
  • The Kinect runtime now provides a StatusChanged event that will fire if a Kinect is connected, disconnected, and so forth. See below for a code snippet for how to subscribe and handle the StatusChanged event.
  • For an example on setting up and handling Kinect connect/disconnect events, refer to the ShapeGame sample.
  • For an example  on how to show two Kinects at the same time, refer to the SkeletalViewer sample.

 

Task: Download Sample Requirements

Some samples use DirectX and the Microsoft Speech APIs. For these demos to work, you must download the correct pre-requisite software.

Kinect for Windows SDK:

Visual Studio:

DirectX Samples (for C++ Skeletal Viewer)

Speech Samples:

For Speech samples:

 

Task: Setting up a new Visual Studio 2010 Project

  • In this task, you’ll create a new Visual Studio 2010 project and add references to the correct libraries
  • Start Visual Studio 2010 (Express Editions or higher)
  • Select File –> New Project –> Windows Presentation Foundation and set the name for your project
    image

 

Add a reference

  • C# – From the Solution Explorer, right click on References and select Add Reference as shown below

image

 

  • Visual Basic – From the Solution Explorer, right click on the project name and select Add Reference as shown below

 

image

Visual Basic / C# – In the Add Reference dialog, switch to the .NET tab, click the Component Name header to sort references alphabetically, then scroll down to select Microsoft.Research.Kinect and click OK. Make sure to select 1.0.0.45.

image

 

Add a using statement

Within your project, you can now add a using statement to reference the Kinect namespaces:

C#

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

Visual Basic

Imports Microsoft.Research.Kinect.Nui
Imports Microsoft.Research.Kinect.Audio

Optional: Using the Coding4Fun Kinect Toolkit

Go to http://c4fkinect.codeplex.com and download the latest version of the Coding4Fun Kinect Toolkit. This library is filled with useful items to help with a variety of tasks, such  as converting the data from the Kinect to a data array or Bitmap.

Depending on if you are building a WPF or Windows Form application, we have two different DLLs:

  • WPF Applications: use the Coding4Fun.Kinect.Wpf.dll
  • Windows Form Applications: use the Coding4Fun.Kinect.WinForm.dll

C#

// if you're using WPF
using Coding4Fun.Kinect.Wpf;

// if you're using WinForms
using Coding4Fun.Kinect.WinForm;

Visual Basic

' if you're using WPF
Imports Coding4Fun.Kinect.Wpf

' if you're using WinForms
Imports Coding4Fun.Kinect.WinForm

Initializing and Uninitializing the runtime

For NUI, we have to initialize and uninitialize the runtime.  In our examples, we typically will initialize on the Loaded event on the Window and we'll uninitialize on the Closed event. Depending on what needs to be done, the Initialize method on the runtime will be tweaked though the concepts stay the same.

Create the Window_Loaded event

Go to the properties window (F4), select the MainWindow, select the Events tab, and double click on the Loaded event to create the Window_Loaded event

image

 

Initializing the runtime

Create a new Runtime variable named “nui” outside of the Window_Loaded event. When the Window_Loaded event fires, we will call the SetupKinect method that checks to see if there is at least one Kinect plugged in, and if there is, it uses the first Kinect (0 representing the first Kinect) and initializes the Runtime (more details on that later). 

C#

//Kinect Runtime
Runtime nui;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    SetupKinect(); 
    
}
private void SetupKinect()
{
    if (Runtime.Kinects.Count == 0)
    {
        this.Title = "No Kinect connected";
    }
    else
    {
        //use first Kinect
        nui = Runtime.Kinects[0];
        nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking);
    }
}

Visual Basic

       'Kinect Runtime
        Private nui As Runtime

        Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
            SetupKinect()
            AddHandler Runtime.Kinects.StatusChanged, AddressOf Kinects_StatusChanged
        End Sub
        Private Sub SetupKinect()
            If Runtime.Kinects.Count = 0 Then
                Me.Title = "No Kinect connected"
            Else
                'use first Kinect
                nui = Runtime.Kinects(0)
                nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)
            End If
        End Sub

 

Handling multiple Kinects

You can see how many Kinects are connected by getting the count of Kinects as shown in the code below. Note that for multiple Kinects, you can only have one Kinect do skeletal tracking at a time (color and depth camera work for all) and each Kinect needs to be in its own USB hub, otherwise it won’t have enough USB bandwidth.

C#

[code lang=”csharp”]

int KinectCount = Runtime.Kinects.Count;

[/code]

Visual Basic

[code lang=”vb”]

Dim KinectCount as Integer = Runtime.Kinects.Count

[/code]

 

Handling Kinect Status Change events

You can also handle events when the status changes for Kinects that are plugged in. To do this, first register for the StatusChanged event as shown below. When this event fires, it returns a KinectStatus enum with the following possible values: Connected, Error, Disconnected, NotReady, or NotPowered.

 

C#

[code lang=”csharp”]

Runtime.Kinects.StatusChanged += new EventHandler<StatusChangedEventArgs>(Kinects_StatusChanged);

void Kinects_StatusChanged(object sender, StatusChangedEventArgs e)
{
    string message = "Status Changed: ";
    switch (e.Status)
    {
        case KinectStatus.Connected:
            message += "Connected";
            break;
        case KinectStatus.Disconnected:
            message += "Disconnected";
            break;
        case KinectStatus.Error:
            message += "Error";
            break;
        case KinectStatus.NotPowered:
            message += "Not Powered";
            break;
        case KinectStatus.NotReady:
            message += "Not Ready";
            break;
        default:
            if (e.Status.HasFlag(KinectStatus.Error))
            {
                message += "Kinect error";
            }
            break;
    }
    this.Title = message;
}

[/code]

 

Visual Basic

[code lang=”vb”]

AddHandler Runtime.Kinects.StatusChanged, AddressOf Kinects_StatusChanged

Private Sub Kinects_StatusChanged(sender As Object, e As StatusChangedEventArgs)
    Dim message As String = "Status Changed: "
    Select Case e.Status
        Case KinectStatus.Connected
            message += "Connected"
            Exit Select
        Case KinectStatus.Disconnected
            message += "Disconnected"
            Exit Select
        Case KinectStatus.[Error]
            message += "Error"
            Exit Select
        Case KinectStatus.NotPowered
            message += "Not Powered"
            Exit Select
        Case KinectStatus.NotReady
            message += "Not Ready"
            Exit Select
        Case Else
            If e.Status.HasFlag(KinectStatus.[Error]) Then
                message += "Kinect error"
            End If
            Exit Select
    End Select
    Me.Title = message


End Sub

 

[/code]

 

Setting Runtime Options

In the Window_Loaded event, initialize the runtime with the options you want to use. For this example, set RuntimeOptions.UseColor to use the RGB camera:

C#

nui.Initialize(RuntimeOptions.UseColor);

Visual Basic

nui.Initialize(RuntimeOptions.UseColor)

RuntimeOptions is a Flag enumeration, this means you can set multiple options as parameters in the Initialize method by separating them with the pipe "|" character (the "or" operator) in c# or the "Or" operator in Visual Basic. The example below sets the runtime to use the color camera, a depth camera, and skeletal tracking:

C#

nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking );

Visual Basic

nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)

Uninitializing the Runtime

Remember that when you are done using the Kinect Runtime, you should call the Uninitialize method. For a WPF application, you would typically do this in the Windows_Closed event:

C#

nui.Uninitialize();

Visual Basic

nui.Uninitialize()

Comment on the Post

Already have a Channel 9 account? Please sign in