<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" media="screen" href="/styles/xslt/rss.xslt"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:media="http://search.yahoo.com/mrss/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:c9="http://channel9.msdn.com">
<channel>
	<title>Kinect for Windows SDK Beta 2 Quickstarts  - Channel 9</title>
    <atom:link rel="self" type="application/rss+xml" href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed"></atom:link>
    <itunes:summary>Update: Kinect for Window SDK v1 Quickstart Series now Availble (Feb 1st)Please use the newly updated Kinect for Windows SDK Quickstart series. The content below will only work with the&amp;nbsp;Beta 2 version of the Kinect for Windows SDK.&amp;nbsp;. &amp;nbsp; Updated for Kinect for Windows SDK Beta 2 (Nov, 2011) This Quickstart series shows the basics of using the Kinect for Windows SDK, including: Installing and using the Kinect sensor, Setting up your development environment, Reading camera data, Understanding how depth data works, skeletal tracking and working with the Kinect microphone to record audio and use speech recognition. </itunes:summary>
    <itunes:author>Microsoft</itunes:author>
    <itunes:subtitle></itunes:subtitle>
    <image>
      <url>http://files.channel9.msdn.com/thumbnail/70ef5441-34c1-4667-86fd-7ef3b97f8c59.jpg</url>
      <title>Kinect for Windows SDK Beta 2 Quickstarts  - Channel 9</title>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts</link>
    </image>
    <itunes:image href="http://files.channel9.msdn.com/thumbnail/70ef5441-34c1-4667-86fd-7ef3b97f8c59.jpg"></itunes:image>
    <itunes:category text="Technology"></itunes:category>
    <description>Update: Kinect for Window SDK v1 Quickstart Series now Availble (Feb 1st)Please use the newly updated Kinect for Windows SDK Quickstart series. The content below will only work with the&amp;nbsp;Beta 2 version of the Kinect for Windows SDK.&amp;nbsp;. &amp;nbsp; Updated for Kinect for Windows SDK Beta 2 (Nov, 2011) This Quickstart series shows the basics of using the Kinect for Windows SDK, including: Installing and using the Kinect sensor, Setting up your development environment, Reading camera data, Understanding how depth data works, skeletal tracking and working with the Kinect microphone to record audio and use speech recognition. </description>
    <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts</link>
    <language>en</language>
    <pubDate>Sun, 19 May 2013 00:03:47 GMT</pubDate>
    <lastBuildDate>Sun, 19 May 2013 00:03:47 GMT</lastBuildDate>
    <generator>Rev9</generator>
    <c9:totalResults>6</c9:totalResults>
    <c9:pageCount>1</c9:pageCount>
    <c9:pageSize>100</c9:pageSize>
  <item>
      <title>Audio Fundamentals (Beta 2 SDK)</title>
      <description><![CDATA[<h2>Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)</h2><p>Please use the newly updated <a href="http://channel9.msdn.com/Series/KinectQuickstart">Kinect for Windows SDK Quickstart series</a>. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.</p><p>&nbsp;</p><p>This video covers the basics of reading audio data from the Kinect microphone array, a demo adapted from the built in audio recorder. The video also covers speech recognition using Kinect.&nbsp; You may find it easier to follow along by downloading the <a href="http://files.ch9.ms/coding4fun/KinectForWindowsSDKBeta2.zip">Kinect for Windows SDK Quickstarts samples and slides</a> that have been updated for Beta 2 (Nov, 2011).</p><ul><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals#time=0m35s">00:35</a>] Kinect microphone information </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals#time=1m10s">01:10</a>] Audio data </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals#time=2m15s">02:15</a>] Speech recognition information </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals#time=5m8s">05:08</a>] Recording audio </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals#time=8m17s">08:17</a>] Speech recognition demo </li></ul><h3>&nbsp;</h3><h3>Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)</h3><p>The video has not been updated for Beta 2, but the following changes have been made:</p><ul><li>Beta 2 now enables you to record audio on a Single-Threaded Apartment (STA) thread, the default thread that is used for WPF applications. Previously, you had to create a new thread marked as a Multi-Threaded Apartment (MTA) for audio processing to work. </li><li>Beta 2 includes a new WPF audio example, KinectAudioDemo, that demonstrates speech recognition and calculating the angle of the current sound source. </li></ul><h3>Setup</h3><p>The steps below assume you have setup your development environment as explained in the &quot;<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started">Setting Up Your Development Environment</a>&quot; video.</p><h1>Task: Designing Your UI</h1><p>We’ll add in a Slider and two Button controls, and we'll also use some stack panels to be sure everything lines up nicely:</p><p><strong>XAML</strong><br><pre class="brush: xml">
&lt;Window x:Class=&quot;AudioRecorder.MainWindow&quot;
        xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</a>
        xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;">http://schemas.microsoft.com/winfx/2006/xaml&quot;</a>
        Title=&quot;Audio Recorder Sample&quot; Height=&quot;159&quot; Width=&quot;525&quot;&gt;
    &lt;Grid&gt;
        &lt;StackPanel&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot;&gt;
                &lt;Label Content=&quot;Seconds to Record: &quot; /&gt;
                &lt;Label Content=&quot;{Binding ElementName=RecordForTimeSpan, Path=Value}&quot; /&gt;
            &lt;/StackPanel&gt;
            &lt;Slider Name=&quot;RecordForTimeSpan&quot; Minimum=&quot;1&quot;  Maximum=&quot;25&quot; IsSnapToTickEnabled=&quot;True&quot; /&gt;
            &lt;StackPanel Orientation=&quot;Horizontal&quot; HorizontalAlignment=&quot;Center&quot;&gt;
                &lt;Button Content=&quot;Record&quot; Height=&quot;50&quot; Width=&quot;100&quot; Name=&quot;RecordButton&quot; /&gt;
                &lt;Button Content=&quot;Play&quot; Height=&quot;50&quot; Width=&quot;100&quot; Name=&quot;PlayButton&quot; /&gt;
            &lt;/StackPanel&gt;
            &lt;MediaElement Name=&quot;audioPlayer&quot; /&gt;
        &lt;/StackPanel&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;
</pre></p><p><a href="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B4%5D.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image_thumb%5B2%5D-1.png" alt="image" width="558" height="190" border="0"></a></p><h3>Creating Click events</h3><p>For each button, we'll want to create a click event. Go to the properties window (F4), select the <strong>RecordButton</strong>, select the Events tab, and double click on the Click event to create the <strong>RecordButton_Click</strong> event. Do the same for the Play Button so we have the <strong>PlayButton_Click</strong> event wired up as well</p><p><a href="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B9%5D.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image_thumb%5B5%5D.png" alt="image" width="293" height="162" border="0"></a></p><h1>Task: Working with the KinectAudioSource</h1><p>The first task is to add in the Kinect Audio library:</p><p><strong>C#</strong><br><pre class="brush: csharp">
using Microsoft.Research.Kinect.Audio;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Imports Microsoft.Research.Kinect.Audio
</pre></p><h2>Synchronous and asynchronous recording</h2><p>There are two ways we can record audio. You can record audio synchronously, meaning that the UI thread will in effect be “frozen” while we record audio using it. Alternatively, you can record audio on a separate thread so that the UI thread remains responsive to events while the recording happens in parallel.&nbsp; Our sample includes both methods so you can choose which one is required for your application.</p><p>&nbsp;</p><p>We’ll build variables to hold the amount of time we’ll record, the file name of the recording, and to enable asynchronous recording, we’ll use the <strong>FinishedRecording </strong>event to notify the UI thread that we're done recording:</p><p><strong>C#</strong><br><pre class="brush: csharp">
double _amountOfTimeToRecord;
string _lastRecordedFileName;
private event RoutedEventHandler FinishedRecording;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private _amountOfTimeToRecord As Double
Private _lastRecordedFileName As String
Private Event FinishedRecording As RoutedEventHandler
</pre></p><p>&nbsp;</p><p>Next we’ll create the RecordAudio method that will do the actual audio recording.</p><p><strong>C#</strong><br><pre class="brush: csharp">
private void RecordAudio()
{
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Sub RecordAudio()
End Sub
</pre></p><p>To create threads, we'll add in the System.Threading namespace:</p><p><strong>C#</strong><br><pre class="brush: csharp">
using System.Threading;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Imports System.Threading
</pre></p><p>Now we'll create the thread and do some simple end-user management in the <strong>RecordButton_Click</strong> event. First we'll disable the two buttons, record the audio, and create a unique file name.</p><p>&nbsp;</p><p>Then we have the option of calling the RecordAudio method either synchronously or asynchronously as shown below:</p><p>‘<strong>C#</strong><br><pre class="brush: csharp">
private void RecordButton_Click(object sender, RoutedEventArgs e)
{
    RecordButton.IsEnabled = false;
    PlayButton.IsEnabled = false;
    _amountOfTimeToRecord = RecordForTimeSpan.Value; 
    _lastRecordedFileName = DateTime.Now.ToString(&quot;yyyyMMddHHmmss&quot;) &#43; &quot;_wav.wav&quot;;
            
    var t = new Thread(new ThreadStart(RecordAudio));
    t.SetApartmentState(ApartmentState.MTA);
    t.Start();
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Sub RecordButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)

    RecordButton.IsEnabled = False
    PlayButton.IsEnabled = False
    _amountOfTimeToRecord = RecordForTimeSpan.Value
    _lastRecordedFileName = Date.Now.ToString(&quot;yyyyMMddHHmmss&quot;) &amp; &quot;_wav.wav&quot;

    Dim t = New Thread(New ThreadStart(AddressOf RecordAudio))
    t.SetApartmentState(ApartmentState.MTA)
    t.Start()

End Sub
</pre></p><h1>Task: Capturing Audio Data</h1><p>From here, this sample and the built-in sample are pretty much the same. We'll only add three differences: the <strong>FinishedRecording</strong> event, a dynamic playback time, and the dynamic file name. Note that the <strong>WriteWavHeader</strong> function is the exact same as the one in the built-in demo as well. Since we leverage different types of streams, we'll add the System.IO namespace:</p><p><strong>C#</strong><br><pre class="brush: csharp">
using System.IO;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Imports System.IO
</pre></p><p>The entire <strong>RecordAudio</strong> method:</p><p><strong>C#</strong><br><pre class="brush: csharp">
private void RecordAudio()
{
    using (var source = new KinectAudioSource())
    {
        var recordingLength = (int) _amountOfTimeToRecord * 2 * 16000;
        var buffer = new byte[1024];
        source.SystemMode = SystemMode.OptibeamArrayOnly;
        using (var fileStream = new FileStream(_lastRecordedFileName, FileMode.Create))
        {
            WriteWavHeader(fileStream, recordingLength);

            //Start capturing audio                               
            using (var audioStream = source.Start())
            {
                //Simply copy the data from the stream down to the file
                int count, totalCount = 0;
                while ((count = audioStream.Read(buffer, 0, buffer.Length)) &gt; 0 &amp;&amp; totalCount &lt; recordingLength)
                {
                    fileStream.Write(buffer, 0, count);
                    totalCount &#43;= count;
                }
            }
        }

        if (FinishedRecording != null)
            FinishedRecording(null, null);
    }
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Sub RecordAudio()
    Using source = New KinectAudioSource

        Dim recordingLength = CInt(Fix(_amountOfTimeToRecord)) * 2 * 16000
        Dim buffer = New Byte(1023) {}

        source.SystemMode = SystemMode.OptibeamArrayOnly

        Using fileStream = New FileStream(_lastRecordedFileName, FileMode.Create)

            WriteWavHeader(fileStream, recordingLength)

            'Start capturing audio                               
            Using audioStream = source.Start()

                'Simply copy the data from the stream down to the file
                Dim count As Integer, totalCount As Integer = 0
                count = audioStream.Read(buffer, 0, buffer.Length)
                Do While count &gt; 0 AndAlso totalCount &lt; recordingLength

                    fileStream.Write(buffer, 0, count)
                    totalCount &#43;= count

                    count = audioStream.Read(buffer, 0, buffer.Length)
                Loop

            End Using

        End Using

        RaiseEvent FinishedRecording(Nothing, Nothing)

    End Using

End Sub
</pre></p><h1>Task: Playing Back the Audio We Just Captured</h1><p>So we've recorded the audio, saved it, and fired off an event that said we're done—let's hook into it. We'll wire up that event in the <strong>MainWindow</strong> constructor:</p><p><strong>c#</strong><br><pre class="brush: csharp">
public MainWindow()
{
    InitializeComponent();

    FinishedRecording &#43;= new RoutedEventHandler(MainWindow_FinishedRecording);
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Public Sub New()
    InitializeComponent()

    AddHandler FinishedRecording, AddressOf MainWindow_FinishedRecording
End Sub
</pre></p><p>Since that event will return on a non-UI thread, we'll need to use the Dispatcher to get us back on a UI thread so we can reenable those buttons:</p><p><strong>C#</strong><br><pre class="brush: csharp">
void MainWindow_FinishedRecording(object sender, RoutedEventArgs e)
{
    Dispatcher.BeginInvoke(new ThreadStart(ReenableButtons));
}

private void ReenableButtons()
{
    RecordButton.IsEnabled = true;
    PlayButton.IsEnabled = true;
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Sub MainWindow_FinishedRecording(sender As Object, e As RoutedEventArgs)
    Dispatcher.BeginInvoke(New ThreadStart(ReenableButtons))
End Sub

Private Sub ReenableButtons()
    RecordButton.IsEnabled = True
    PlayButton.IsEnabled = True
End Sub
</pre></p><p>And finally, we'll make the Media element play back the audio we just saved!&nbsp; We'll also verify both that the file exists and that the user recorded some audio:</p><p><strong>c#</strong><br><pre class="brush: csharp">
private void PlayButton_Click(object sender, RoutedEventArgs e)
{
    if (!string.IsNullOrEmpty(_lastRecordedFileName) &amp;&amp; File.Exists(_lastRecordedFileName))
    {
        audioPlayer.Source = new Uri(_lastRecordedFileName, UriKind.RelativeOrAbsolute);
        audioPlayer.LoadedBehavior = MediaState.Play;
        audioPlayer.UnloadedBehavior = MediaState.Close;
    }
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Sub PlayButton_Click(sender As Object, e As RoutedEventArgs)

    If (Not String.IsNullOrEmpty(_lastRecordedFileName)) AndAlso File.Exists(_lastRecordedFileName) Then

        audioPlayer.Source = New Uri(_lastRecordedFileName, UriKind.RelativeOrAbsolute)
        audioPlayer.LoadedBehavior = MediaState.Play
        audioPlayer.UnloadedBehavior = MediaState.Close

    End If

End Sub
</pre></p><h1>Task: Speech Recognition</h1><p>To do speech recognition, we need to bring in the speech recognition namespaces from the speech SDK:</p><p><strong>C#</strong><br><pre class="brush: csharp">
using Microsoft.Speech.AudioFormat;
using Microsoft.Speech.Recognition;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Imports Microsoft.Speech.AudioFormat
Imports Microsoft.Speech.Recognition
</pre></p><p>In VB we'll also need to add in a MTA flag as well under the <strong>Sub Main</strong>.&nbsp; C# does not need this.</p><p>Visual Basic</p><p><pre class="brush: vb">
&lt;MTAThread()&gt; _
Shared Sub Main(ByVal args() As String)
</pre></p><p>Next, we need to setup the KinectAudioSource in a way that's compatbile for speech recognition:</p><p><strong>C#</strong><br><pre class="brush: csharp">
using (var source = new KinectAudioSource())
{
    source.FeatureMode = true;
    source.AutomaticGainControl = false; //Important to turn this off for speech recognition
    source.SystemMode = SystemMode.OptibeamArrayOnly; //No AEC for this sample
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Using source = New KinectAudioSource

source.FeatureMode = True
source.AutomaticGainControl = False 'Important to turn this off for speech recognition
source.SystemMode = SystemMode.OptibeamArrayOnly 'No AEC for this sample

End Using
</pre></p><p>With that in place, we can initialize the SpeechRecognitionEngine to use the Kinect recognizer, which was downloaded earlier:</p><p><strong>C#</strong><br><pre class="brush: csharp">
private const string RecognizerId = &quot;SR_MS_en-US_Kinect_10.0&quot;;
RecognizerInfo ri = SpeechRecognitionEngine.InstalledRecognizers().Where(r =&gt; r.Id == RecognizerId).FirstOrDefault();
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Const RecognizerId As String = &quot;SR_MS_en-US_Kinect_10.0&quot;
Dim ri As RecognizerInfo = SpeechRecognitionEngine.InstalledRecognizers().Where(Function(r) r.Id = RecognizerId).FirstOrDefault()
</pre></p><p>Next, a &quot;grammar&quot; needs to be setup, which specifies which words the speech recognition engine should listen for.&nbsp; The following code creates a grammar for the words &quot;red&quot;, &quot;blue&quot; and &quot;green&quot;.</p><p><strong>C#</strong><br><pre class="brush: csharp">
using (var sre = new SpeechRecognitionEngine(ri.Id))
{                
    var colors = new Choices();
    colors.Add(&quot;red&quot;);
    colors.Add(&quot;green&quot;);
    colors.Add(&quot;blue&quot;);
    var gb = new GrammarBuilder();
    //Specify the culture to match the recognizer in case we are running in a different culture.                                 
    gb.Culture = ri.Culture;
    gb.Append(colors);
  
    // Create the actual Grammar instance, and then load it into the speech recognizer.
    var g = new Grammar(gb);                  
    sre.LoadGrammar(g);
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Using sre = New SpeechRecognitionEngine(ri.Id)

Dim colors = New Choices
colors.Add(&quot;red&quot;)
colors.Add(&quot;green&quot;)
colors.Add(&quot;blue&quot;)

Dim gb = New GrammarBuilder
'Specify the culture to match the recognizer in case we are running in a different culture
gb.Culture = ri.Culture
gb.Append(colors)

' Create the actual Grammar instance, and then load it into the speech recognizer.
Dim g = New Grammar(gb)

sre.LoadGrammar(g)

End Using
</pre></p><p>Next, several events are hooked up so you can be notified when a word is recognized, hypothesized, or rejected:</p><p><strong>C#</strong><br><pre class="brush: csharp">
sre.SpeechRecognized &#43;= SreSpeechRecognized;
sre.SpeechHypothesized &#43;= SreSpeechHypothesized;
sre.SpeechRecognitionRejected &#43;= SreSpeechRecognitionRejected;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
AddHandler sre.SpeechRecognized, AddressOf SreSpeechRecognized
AddHandler sre.SpeechHypothesized, AddressOf SreSpeechHypothesized
AddHandler sre.SpeechRecognitionRejected, AddressOf SreSpeechRecognitionRejected
</pre></p><p>Finally, the audio stream source from the Kinect is applied to the speech recognition engine:</p><p><strong>C#</strong><br><pre class="brush: csharp">
using (Stream s = source.Start())
{
    sre.SetInputToAudioStream(s,
                              new SpeechAudioFormatInfo(
                                  EncodingFormat.Pcm, 16000, 16, 1,
                                  32000, 2, null));
    Console.WriteLine(&quot;Recognizing. Say: 'red', 'green' or 'blue'. Press ENTER to stop&quot;);
    sre.RecognizeAsync(RecognizeMode.Multiple);
    Console.ReadLine();
    Console.WriteLine(&quot;Stopping recognizer ...&quot;);
    sre.RecognizeAsyncStop();                       
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Using s As Stream = source.Start()

sre.SetInputToAudioStream(s, New SpeechAudioFormatInfo(EncodingFormat.Pcm, 16000, 16, 1, 32000, 2, Nothing))

Console.WriteLine(&quot;Recognizing. Say: 'red', 'green' or 'blue'. Press ENTER to stop&quot;)

sre.RecognizeAsync(RecognizeMode.Multiple)
Console.ReadLine()
Console.WriteLine(&quot;Stopping recognizer ...&quot;)
sre.RecognizeAsyncStop()

End Using
</pre></p><p>The event handlers specified earlier display information based on the result of the user's speech being recognized:</p><p><strong>C#</strong><br><pre class="brush: csharp">
static void SreSpeechRecognitionRejected(object sender, SpeechRecognitionRejectedEventArgs e)
{
    Console.WriteLine(&quot;\nSpeech Rejected&quot;);
    if (e.Result != null)
        DumpRecordedAudio(e.Result.Audio);
}

static void SreSpeechHypothesized(object sender, SpeechHypothesizedEventArgs e)
{
    Console.Write(&quot;\rSpeech Hypothesized: \t{0}\tConf:\t{1}&quot;, e.Result.Text, e.Result.Confidence);
}

static void SreSpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{
    Console.WriteLine(&quot;\nSpeech Recognized: \t{0}&quot;, e.Result.Text);
}

private static void DumpRecordedAudio(RecognizedAudio audio)
{
    if (audio == null)
        return;

    int fileId = 0;
    string filename;
    while (File.Exists((filename = &quot;RetainedAudio_&quot; &#43; fileId &#43; &quot;.wav&quot;)))
        fileId&#43;&#43;;

    Console.WriteLine(&quot;\nWriting file: {0}&quot;, filename);
    using (var file = new FileStream(filename, System.IO.FileMode.CreateNew))
        audio.WriteToWaveStream(file);
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Shared Sub SreSpeechRecognitionRejected(ByVal sender As Object, ByVal e As SpeechRecognitionRejectedEventArgs)

     Console.WriteLine(vbLf &amp; &quot;Speech Rejected&quot;)
     If e.Result IsNot Nothing Then
          DumpRecordedAudio(e.Result.Audio)
     End If

End Sub
Private Shared Sub SreSpeechHypothesized(ByVal sender As Object, ByVal e As SpeechHypothesizedEventArgs)

     Console.Write(vbCr &amp; &quot;Speech Hypothesized: &quot; &amp; vbTab &amp; &quot;{0}&quot; &amp; vbTab &amp; &quot;Conf:&quot; &amp; vbTab &amp; &quot;{1}&quot;, e.Result.Text, e.Result.Confidence)

End Sub
Private Shared Sub SreSpeechRecognized(ByVal sender As Object, ByVal e As SpeechRecognizedEventArgs)

     Console.WriteLine(vbLf &amp; &quot;Speech Recognized: &quot; &amp; vbTab &amp; &quot;{0}&quot;, e.Result.Text)

End Sub

Private Shared Sub DumpRecordedAudio(ByVal audio As RecognizedAudio)
     If audio Is Nothing Then
          Return
     End If

     Dim fileId As Integer = 0
     Dim filename As String
     filename = &quot;RetainedAudio_&quot; &amp; fileId &amp; &quot;.wav&quot;
     Do While File.Exists(filename)
          fileId &#43;= 1
          filename = &quot;RetainedAudio_&quot; &amp; fileId &amp; &quot;.wav&quot;
     Loop

     Console.WriteLine(vbLf &amp; &quot;Writing file: {0}&quot;, filename)
     Using file = New FileStream(filename, System.IO.FileMode.CreateNew)
          audio.WriteToWaveStream(file)
     End Using

End Sub
</pre></p><p>In the case of a word being rejected, the audio is written out to a WAV file so it can be listened to later.</p><h1>Recap</h1><p>We've created an application that can record audio for a variable amount of time with Kinect!</p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed&WT.dl=0&WT.entryid=Entry:RSSView:8f11529e21704d75a6da9f0000573858">]]></description>
      <comments>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals</comments>
      <itunes:summary>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. &amp;nbsp; This video covers the basics of reading audio data from the Kinect microphone array, a demo adapted from the built in audio recorder. The video also covers speech recognition using Kinect.&amp;nbsp; 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] Kinect microphone information [01:10] Audio data [02:15] Speech recognition information [05:08] Recording audio [08:17] Speech recognition demo &amp;nbsp;Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)The video has not been updated for Beta 2, but the following changes have been made: Beta 2 now enables you to record audio on a Single-Threaded Apartment (STA) thread, the default thread that is used for WPF applications. Previously, you had to create a new thread marked as a Multi-Threaded Apartment (MTA) for audio processing to work. Beta 2 includes a new WPF audio example, KinectAudioDemo, that demonstrates speech recognition and calculating the angle of the current sound source. SetupThe steps below assume you have setup your development environment as explained in the &amp;quot;Setting Up Your Development Environment&amp;quot; video. Task: Designing Your UIWe’ll add in a Slider and two Button controls, and we&#39;ll also use some stack panels to be sure everything lines up nicely: XAML
&amp;lt;Window x:Class=&amp;quot;AudioRecorder.MainWindow&amp;quot;
        xmlns=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
        xmlns:x=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml&amp;quot;
        Title=&amp;quot;Audio Recorder Sample&amp;quot; Height=&amp;quot;159&amp;quot; Width=&amp;quot;525&amp;quot;&amp;gt;
    &amp;lt;Grid&amp;gt;
        &amp;lt;StackPanel&amp;gt;
            &amp;lt;StackPanel Orientation=&amp;quo</itunes:summary>
      <itunes:duration>708</itunes:duration>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals</link>
      <pubDate>Thu, 16 Jun 2011 17:15:43 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_2MB_ch9.wmv" expression="full" duration="708" fileSize="129716642" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_ch9.mp3" expression="full" duration="708" fileSize="5666998" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_ch9.wma" expression="full" duration="708" fileSize="5733607" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_ch9.wmv" expression="full" duration="708" fileSize="81913681" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_high_ch9.mp4" expression="full" duration="708" fileSize="225968144" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_low_ch9.mp4" expression="full" duration="708" fileSize="31044905" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals.ism/manifest" expression="full" duration="708" fileSize="8506" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/3858/8f11529e-2170-4d75-a6da-9f0000573858/AudioFundamentals_ch9.wmv" length="81913681" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Clint Rutkas, Dan Fernandez</dc:creator>
      <itunes:author>Clint Rutkas, Dan Fernandez</itunes:author>
      <slash:comments>13</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Audio-Fundamentals/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Working with Depth Data (Beta 2 SDK)</title>
      <description><![CDATA[<h2>Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)</h2><p>Please use the newly updated <a href="http://channel9.msdn.com/Series/KinectQuickstart">Kinect for Windows SDK Quickstart series</a>. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.</p><p>&nbsp;</p><p>&nbsp;</p><p>This video covers the basics of using depth data from Kinect. You may find it easier to follow along by downloading the <a href="http://files.ch9.ms/coding4fun/KinectForWindowsSDKBeta2.zip">Kinect for Windows SDK Quickstarts samples and slides</a> that have been updated for Beta 2 (Nov, 2011).</p><ul><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data#time=0m43s">00:43</a>] Depth data overview </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data#time=4m56s">04:56</a>] Initializing the Kinect Runtime </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data#time=5m46s">05:46</a>] Using the depth data to create an image </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data#time=12m13s">12:13</a>] Using the PlayerIndex </li></ul><h3>Setup</h3><p>The steps below assume you have setup your development environment as explained in the &quot;<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started">Setting Up Your Development Environment</a>&quot; video.</p><p>&nbsp;</p><h3>Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)</h3><ul><ul><li>Creating the Kinect runtime uses the <strong>SetupKinect</strong> method used in the <a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started">Setting Up Your Development Environment</a> example. </li><li>Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: &quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&quot; in the “Managed\KinectWpfViewers” solution. </li></ul></ul><p>&nbsp;</p><h1>Task Setup the Depth Camera event</h1><h3>Designing the UI</h3><p>Add an image with Width=320 and Height=240 as shown below:</p><p><strong>XAML</strong><br><pre class="brush: xml">
    &lt;Image Height=&quot;240&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;62,41,0,0&quot; Name=&quot;image1&quot; Stretch=&quot;Fill&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;320&quot; /&gt;
</pre></p><p><a href="http://files.channel9.msdn.com/thumbnail/2ef23a05-59df-4ddf-9558-2bb3c0328751.PNG" rel="lightbox"><img src="http://files.channel9.msdn.com/thumbnail/2ef23a05-59df-4ddf-9558-2bb3c0328751.PNG" alt=""></a></p><h3>Setup the Depth Camera Event</h3><p>Create an instance of the Kinect <strong>Runtime</strong> outside of the Window_Loaded event. Then, initialize the Runtime to use <strong>DepthAndPlayerIndex</strong> and <strong>UseSkeletalTracking</strong>. Finally register for <strong>DepthFrameReady</strong> event and open the Depth stream as shown below.</p><p><strong>C#<br></strong><pre class="brush: csharp">
//Kinect Runtime
Runtime nui = new Runtime(); 

private void Window_Loaded(object sender, RoutedEventArgs e)
{
    //UseDepthAndPlayerIndex and UseSkeletalTracking
    nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking);

    //register for event
    nui.DepthFrameReady &#43;= new EventHandler&lt;ImageFrameReadyEventArgs&gt;(nui_DepthFrameReady);

    //DepthAndPlayerIndex ImageType
    nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, 
        ImageType.DepthAndPlayerIndex); 
}

void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private nui As New Runtime

Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)

    'UseDepthAndPlayerIndex and UseSkeletalTracking
    nui.Initialize(RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)

    'register for event
    AddHandler nui.DepthFrameReady, AddressOf nui_DepthFrameReady

    'DepthAndPlayerIndex ImageType
    nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.DepthAndPlayerIndex)

End Sub

Private Sub nui_DepthFrameReady(ByVal sender As Object, ByVal e As ImageFrameReadyEventArgs)

End Sub
</pre></p><h3>Understanding the PlanarImage byte[] Array</h3><p>The DepthFrameReady event returns an ImageFrame class that contains a PlanarImage.&nbsp; That PlanarImage contains a byte[] array which contains the distance of each pixel. The array:</p><ul><li>Starts at top left of image </li><li>Moves left to right, then top to bottom </li><li>Represents distance for pixel </li></ul><h3>Calculating Distance</h3><p>Because there are 2 bytes per pixel (16 bits) representing the distance, you will need to use bitshift operators to get the distance for a particular pixel. The exact bitshifting depends on the <strong>ImageType</strong> you use</p><p><strong>Depth Image Type</strong><br>Bitshift second byte left by 8<br>Distance (0,0) = (int)(Bits[0] | Bits[1] &lt;&lt; 8 );</p><p><strong>DepthAndPlayerIndex Image Type</strong><br>Bitshift first byte right by 3 (to remove player index), and second byte left by 5<br>Distance (0,0) =(int)(Bits[0] &gt;&gt; 3 | Bits[1] &lt;&lt; 5);</p><p>The method below shows returning the distance in millimeters using the 2 bytes for a particular pixel.</p><p><strong>C#<br></strong><pre class="brush: csharp">
private int GetDistanceWithPlayerIndex(byte firstFrame, byte secondFrame)
{
  //offset by 3 in first byte to get value after player index 
  int distance = (int)(firstFrame &gt;&gt; 3 | secondFrame &lt;&lt; 5);
  return distance;
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Function GetDistanceWithPlayerIndex(ByVal firstFrame As Byte, ByVal secondFrame As Byte) As Integer

    'offset by 3 in first byte to get value after player index 
    Dim distance As Integer = (CInt(firstFrame) &gt;&gt; 3 Or CInt(secondFrame) &lt;&lt; 5)
    Return distance

End Function
</pre></p><p>The DepthAndPlayerIndex image type is offset by 3 since the first three bits represent the Player Index. The Player Index has up to six possible values.</p><ul><li>0 – No player </li><li>1 – Skeleton 0 </li><li>2 – Skeleton 1 </li><li>... </li></ul><p>Note: While depth data is available for multiple players, you can only have skeletal/joint data for a maximum of two players.</p><p>To get a player index, we'll use the following formula. Since the player index is only in the first byte, we do not need the pixels second byte.</p><p><strong>C#<br></strong><pre class="brush: csharp">
private static int GetPlayerIndex(byte firstFrame)
{
    //returns 0 = no player, 1 = 1st player, 2 = 2nd player...
    return (int)firstFrame &amp; 7; 
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Shared Function GetPlayerIndex(ByVal firstFrame As Byte) As Integer

    'returns 0 = no player, 1 = 1st player, 2 = 2nd player...
    'bitwise &amp; on firstFrame
    Return CInt(firstFrame) And 7

End Function
</pre></p><h3>Using distance to color values</h3><p>Now that we know the distance for a particular pixel using the formula above, we can loop through all of the bytes in the byte[] array and dynamically assign colors to pixels based on their distance.</p><p>To begin with, we'll build a colorFrame byte[] array using the Bgr (Blue, Green, Red) pixel format. What this means is that each pixel (ex: the pixel at 0,0) is represented by four bytes, one each for Blue, Green, Red, and an empty one (or transparency byte if you choose the Bgra format).</p><p>For example, the snippet below would color the pixel blue if the current distance for that pixel was &lt; 900 millimeters from the Kinect. To set the color to blue, we set the first byte (BlueIndex) to the maximum value, 255.</p><p><strong>C#</strong><br><pre class="brush: csharp">
if (distance &lt;= 900)
{
    //we are very close
    colorFrame[index &#43; BlueIndex] = 255;
    colorFrame[index &#43; GreenIndex] = 0;
    colorFrame[index &#43; RedIndex] = 0;
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
If distance &lt;= 900 Then

    'we are very close
    colorFrame(index &#43; BlueIndex) = 255
    colorFrame(index &#43; GreenIndex) = 0
    colorFrame(index &#43; RedIndex) = 0

End If
</pre></p><p>Similarly, we can use the code snippet below to check if the current pixel represents a Player Index. If it does, we'll set the maximum value for both green and red which produces a yellow/gold-like color.</p><p><strong>C#</strong><br><pre class="brush: csharp">
if (GetPlayerIndex(depthData[depthIndex]) &gt; 0)
{
    //we are the farthest
    colorFrame[index &#43; BlueIndex] = 0;
    colorFrame[index &#43; GreenIndex] = 255;
    colorFrame[index &#43; RedIndex] = 255;
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
If GetPlayerIndex(depthData(depthIndex)) &gt; 0 Then

    'we are the farthest
    colorFrame(index &#43; BlueIndex) = 0
    colorFrame(index &#43; GreenIndex) = 255
    colorFrame(index &#43; RedIndex) = 255

End If
</pre></p><h3>Setting a monochrome intensity</h3><p>While the previous examples we hard-coded colors, you can also build a monochrome histogram that scales the color range (0-255) proportionally based on the distance range (850-4000).</p><p>To get a monochrome appearance, the intensity is applied equally to all three colors (blue, green, red).</p><p><strong>C#</strong><br><pre class="brush: csharp">
//equal coloring for monochromatic histogram
var intensity = CalculateIntensityFromDepth(distance);

colorFrame[index &#43; BlueIndex] = intensity;
colorFrame[index &#43; GreenIndex] = intensity;
colorFrame[index &#43; RedIndex] = intensity;

const float MaxDepthDistance = 4000; // max value returned
const float MinDepthDistance = 850; // min value returned
const float MaxDepthDistanceOffset = MaxDepthDistance - MinDepthDistance;

public static byte CalculateIntensityFromDepth(int distance)
{
   //formula for calculating monochrome intensity for histogram
   return (byte)(255 - (255 * Math.Max(distance - MinDepthDistance, 0)  / (MaxDepthDistanceOffset)));
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
'equal coloring for monochromatic histogram
Dim intensity = CalculateIntensityFromDepth(distance)

colorFrame(index &#43; BlueIndex) = intensity
colorFrame(index &#43; GreenIndex) = intensity
colorFrame(index &#43; RedIndex) = intensity

Private Const MaxDepthDistance As Single = 4000 ' max value returned
Private Const MinDepthDistance As Single = 850 ' min value returned
Private Const MaxDepthDistanceOffset As Single = MaxDepthDistance - MinDepthDistance

Public Shared Function CalculateIntensityFromDepth(ByVal distance As Integer) As Byte

    'formula for calculating monochrome intensity for histogram
    Return CByte(255 - (255 * Math.Max(distance - MinDepthDistance, 0) / (MaxDepthDistanceOffset)))

End Function
</pre></p><h3>Putting it all together</h3><p>Using the formulas above, we'll now return a byte[] array that has a color value for each pixel based on if the distance for that pixel:</p><ul><li>&gt; 900 = Blue </li><li>&gt; 900 &amp;&amp; &lt; 2000 = Green </li><li>&gt; 2000 = Red </li></ul><p>If the pixel represents a player, the color will be yellow/gold.</p><p><strong>C#<br></strong><pre class="brush: csharp">
private byte[] GenerateColoredBytes(ImageFrame imageFrame)
{
    int height = imageFrame.Image.Height;
    int width = imageFrame.Image.Width;

    //Depth data for each pixel
    Byte[] depthData = imageFrame.Image.Bits; 

    //colorFrame contains color information for all pixels in image
    //Height x Width x 4 (Red, Green, Blue, empty byte)
    Byte[] colorFrame = new byte[imageFrame.Image.Height * imageFrame.Image.Width * 4];

    //Bgr32  - Blue, Green, Red, empty byte
    //Bgra32 - Blue, Green, Red, transparency 
    //You must set transparency for Bgra as .NET defaults a byte to 0 = fully transparent

    //hardcoded locations to Blue, Green, Red (BGR) index positions       
    const int BlueIndex = 0;
    const int GreenIndex = 1;
    const int RedIndex = 2;

    var depthIndex = 0;
    for (var y = 0; y &lt; height; y&#43;&#43;)
    {        
        var heightOffset = y * width;

        for (var x = 0; x &lt; width; x&#43;&#43;)
        {
            var index = ((width - x - 1) &#43; heightOffset) * 4;

            //var distance = GetDistance(depthData[depthIndex], depthData[depthIndex &#43; 1]);
            var distance = GetDistanceWithPlayerIndex(depthData[depthIndex], depthData[depthIndex &#43; 1]);

            if (distance &lt;= 900)
            {
                //we are very close
                colorFrame[index &#43; BlueIndex] = 255;
                colorFrame[index &#43; GreenIndex] = 0;
                colorFrame[index &#43; RedIndex] = 0;       
            }
            else if (distance &gt; 900 &amp;&amp; distance &lt; 2000)
            {
                //we are a bit further away
                colorFrame[index &#43; BlueIndex] = 0;
                colorFrame[index &#43; GreenIndex] = 255;
                colorFrame[index &#43; RedIndex] = 0;
            }
            else if (distance &gt; 2000)
            {
                //we are the farthest
                colorFrame[index &#43; BlueIndex] = 0;
                colorFrame[index &#43; GreenIndex] = 0;
                colorFrame[index &#43; RedIndex] = 255;
            }

            //Color a player
            if (GetPlayerIndex(depthData[depthIndex]) &gt; 0)
            {
                //we are the farthest
                colorFrame[index &#43; BlueIndex] = 0;
                colorFrame[index &#43; GreenIndex] = 255;
                colorFrame[index &#43; RedIndex] = 255;
            }

            //jump two bytes at a time
            depthIndex &#43;= 2;
        }
    }

    return colorFrame;
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Private Function GenerateColoredBytes(ByVal imageFrame As ImageFrame) As Byte()

    Dim height As Integer = imageFrame.Image.Height
    Dim width As Integer = imageFrame.Image.Width

    'Depth data for each pixel
    Dim depthData() As Byte = imageFrame.Image.Bits

    'colorFrame contains color information for all pixels in image
    'Height x Width x 4 (Red, Green, Blue, empty byte)
    Dim colorFrame(imageFrame.Image.Height * imageFrame.Image.Width * 4 - 1) As Byte

    'Bgr32  - Blue, Green, Red, empty byte
    'Bgra32 - Blue, Green, Red, transparency 
    'You must set transparency for Bgra as .NET defaults a byte to 0 = fully transparent

    'hardcoded locations to Blue, Green, Red (BGR) index positions       
    Const BlueIndex As Integer = 0
    Const GreenIndex As Integer = 1
    Const RedIndex As Integer = 2

    Dim depthIndex = 0
    For y = 0 To height - 1

        Dim heightOffset = y * width

        For x = 0 To width - 1

            Dim index = ((width - x - 1) &#43; heightOffset) * 4

            Dim distance = GetDistanceWithPlayerIndex(depthData(depthIndex), depthData(depthIndex &#43; 1))

            If distance &lt;= 900 Then

                'we are very close
                colorFrame(index &#43; BlueIndex) = 255
                colorFrame(index &#43; GreenIndex) = 0
                colorFrame(index &#43; RedIndex) = 0

            ElseIf distance &gt; 900 AndAlso distance &lt; 2000 Then

                'we are a bit further away
                colorFrame(index &#43; BlueIndex) = 0
                colorFrame(index &#43; GreenIndex) = 255
                colorFrame(index &#43; RedIndex) = 0

            ElseIf distance &gt; 2000 Then

                'we are the farthest
                colorFrame(index &#43; BlueIndex) = 0
                colorFrame(index &#43; GreenIndex) = 0
                colorFrame(index &#43; RedIndex) = 255

            End If

            '//Color a player
            If GetPlayerIndex(depthData(depthIndex)) &gt; 0 Then

                'we are the farthest
                colorFrame(index &#43; BlueIndex) = 0
                colorFrame(index &#43; GreenIndex) = 255
                colorFrame(index &#43; RedIndex) = 255

            End If

            'jump two bytes at a time
            depthIndex &#43;= 2

        Next x

    Next y

    Return colorFrame

End Function
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed&WT.dl=0&WT.entryid=Entry:RSSView:6e71e1a9a94844b0908f9efd005862a9">]]></description>
      <comments>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data</comments>
      <itunes:summary>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. &amp;nbsp; &amp;nbsp; This video covers the basics of using depth data from Kinect. 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:43] Depth data overview [04:56] Initializing the Kinect Runtime [05:46] Using the depth data to create an image [12:13] Using the PlayerIndex SetupThe steps below assume you have setup your development environment as explained in the &amp;quot;Setting Up Your Development Environment&amp;quot; video. &amp;nbsp; Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)Creating the Kinect runtime uses the SetupKinect method used in the Setting Up Your Development Environment example. Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: &amp;quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&amp;quot; in the “Managed\KinectWpfViewers” solution. &amp;nbsp; Task Setup the Depth Camera eventDesigning the UIAdd an image with Width=320 and Height=240 as shown below: XAML
    &amp;lt;Image Height=&amp;quot;240&amp;quot; HorizontalAlignment=&amp;quot;Left&amp;quot; Margin=&amp;quot;62,41,0,0&amp;quot; Name=&amp;quot;image1&amp;quot; Stretch=&amp;quot;Fill&amp;quot; VerticalAlignment=&amp;quot;Top&amp;quot; Width=&amp;quot;320&amp;quot; /&amp;gt;
  Setup the Depth Camera EventCreate an instance of the Kinect Runtime outside of the Window_Loaded event. Then, initialize the Runtime to use DepthAndPlayerIndex and UseSkeletalTracking. Finally register for DepthFrameReady event and open the Depth stream as shown below. C#
//Kinect Runtime
Runtime nui = new Runtime(); 

private void Window_Loaded(object sender, RoutedEv</itunes:summary>
      <itunes:duration>1017</itunes:duration>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data</link>
      <pubDate>Thu, 16 Jun 2011 17:15:36 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_2MB_ch9.wmv" expression="full" duration="1017" fileSize="618474274" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_ch9.mp3" expression="full" duration="1017" fileSize="8140686" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_ch9.wma" expression="full" duration="1017" fileSize="8232935" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_ch9.wmv" expression="full" duration="1017" fileSize="131787536" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_high_ch9.mp4" expression="full" duration="1017" fileSize="335396489" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_low_ch9.mp4" expression="full" duration="1017" fileSize="40838156" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1.ism/manifest" expression="full" duration="1017" fileSize="8426" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/62a9/6e71e1a9-a948-44b0-908f-9efd005862a9/KinectDepth1_ch9.wmv" length="131787536" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Dan Fernandez</dc:creator>
      <itunes:author>Dan Fernandez</itunes:author>
      <slash:comments>38</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Working-with-Depth-Data/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Camera Fundamentals (Beta 2 SDK)</title>
      <description><![CDATA[<h2>Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)</h2><p>Please use the newly updated <a href="http://channel9.msdn.com/Series/KinectQuickstart">Kinect for Windows SDK Quickstart series</a>. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.</p><p>&nbsp;</p><p>This video covers the basics of reading camera data from the Kinect sensor.&nbsp; You may find it easier to follow along by downloading the <a href="http://files.ch9.ms/coding4fun/KinectForWindowsSDKBeta2.zip">Kinect for Windows SDK Quickstarts samples and slides</a> that have been updated for Beta 2 (Nov, 2011).</p><ul><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals#time=0m25s">00:25</a>] Camera data information </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals#time=3m30s">03:30</a>] Creating the UI </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals#time=4m48s">04:48</a>] Initializing the Kinect runtime </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals#time=7m18s">07:18</a>] Reading values from the RGB camera </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals#time=11m26s">11:26</a>] Reading values from the Depth camera </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals#time=13m06s">13:06</a>] Adjusting camera tilt&nbsp; </li></ul><h3>&nbsp;</h3><h3>Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)</h3><p>The video has not been updated for Beta 2, but the following changes have been made:</p><ul><li>Creating the Kinect runtime uses the <strong>SetupKinect</strong> method used in the <a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started">Setting Up Your Development Environment</a> example. </li><li>Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: &quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&quot; in the “Managed\KinectWpfViewers” solution. </li></ul><h3>Setup</h3><p>The steps below assume you have setup your development environment as explained in the <a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started">Setting Up Your Development Environment</a> video.</p><h2>To get a depth or color image you must do the following</h2><ol><li>Create an instance of a runtime object </li><li>Initialize the instance with the correct options </li><li>Subscribe to an event to receive camera data </li><li>Open the video stream </li><li>Convert the raw camera data into an image </li></ol><h1>Task: Display the RGB Camera Image</h1><h2>Designing your UI</h2><p>We’ll add two 320x240 Image controls to the MainWindow XAML file as shown in the following XAML:</p><p><strong>XAML<br></strong><pre class="brush: xml">
&lt;Window x:Class=&quot;WpfApplication1.MainWindow&quot;
        xmlns=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;">http://schemas.microsoft.com/winfx/2006/xaml/presentation&quot;</a>
        xmlns:x=&quot;<a href="http://schemas.microsoft.com/winfx/2006/xaml&quot;">http://schemas.microsoft.com/winfx/2006/xaml&quot;</a>
        Title=&quot;MainWindow&quot; Height=&quot;350&quot; Width=&quot;800&quot;&gt;
    &lt;Grid&gt;
        &lt;Image Height=&quot;240&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;12,20,0,0&quot; Name=&quot;image1&quot; Stretch=&quot;Fill&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;320&quot; /&gt;
        &lt;Image Height=&quot;240&quot; HorizontalAlignment=&quot;Left&quot; Margin=&quot;355,20,0,0&quot; Name=&quot;image2&quot; Stretch=&quot;Fill&quot; VerticalAlignment=&quot;Top&quot; Width=&quot;320&quot; /&gt;
    &lt;/Grid&gt;
&lt;/Window&gt;
</pre></p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B2%5D.png" alt="image" width="640" height="290" border="0"></p><h3>Initializing the runtime</h3><p>In the <strong>Window_Loaded </strong>event, initialize the runtime with the options you want to use. For this example, set <strong>RuntimeOptions.UseColor</strong> to use the RGB and depth camera:</p><p><strong>C#</strong><br><pre class="brush: csharp">
//Kinect Runtime
Runtime nui;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    SetupKinect();
}
private void SetupKinect()
{
    if (Runtime.Kinects.Count == 0)
    {
        this.Title = &quot;No Kinect connected&quot;;
    }
    else
    {
        //use first Kinect
        nui = Runtime.Kinects[0];
 
        //Initialize to return both Color &amp; Depth images
        nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);
    }
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
'Kinect Runtime
Private nui As Runtime
Private Sub Window_Loaded(ByVal sender As Object, ByVal e As RoutedEventArgs)
    SetupKinect()
End Sub
Private Sub SetupKinect()
    If Runtime.Kinects.Count = 0 Then
        Me.Title = &quot;No Kinect connected&quot;
    Else
        'use first Kinect
        nui = Runtime.Kinects(0)
        'Initialize to return both Color &amp; Depth images
        nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepth)
    End If
</pre></p><h3>Subscribe to the VideoFrameReady event</h3><p>To read values from the RGB camera, add an event handler for the <strong>VideoFrameReady</strong> event on the Kinect Runtime in the <strong>Window_Loaded</strong> event as shown below:</p><blockquote><p><strong>Tip:</strong> You can have Visual Studio automatically build the event handler for you by typing &quot;<strong>nui.VideoFrameReady</strong> &#43;=&quot; and hitting the tab key twice.</p></blockquote><p><strong>C#<br></strong><pre class="brush: csharp">
nui.VideoFrameReady &#43;= new EventHandler&lt;ImageFrameReadyEventArgs&gt;(nui_VideoFrameReady);

void nui_VideoFrameReady(object sender, ImageFrameReadyEventArgs e)
{
   // event code goes here
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
AddHandler nui.VideoFrameReady, AddressOf nui_VideoFrameReady

Private Sub nui_VideoFrameReady(ByVal sender As Object, ByVal e As ImageFrameReadyEventArgs)
    ' event code goes here
End Sub
</pre></p><p><strong>Understanding the video frame ready returned values</strong></p><p>The video frame returns an <strong>ImageFrameReadyEventArgs </strong>that contains an <strong>ImageFrame </strong>class. As shown below, the <strong>ImageFrame </strong>class contains two things:</p><ul><li>Metadata about the image, such as <strong>ImageType </strong>to know if it’s a depth or color image, and resolution to know the size of the image </li><li><strong>Image </strong>– the actual image data, which is stored in the <strong>Bits byte[] </strong>array </li></ul><p><a href="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B3%5D.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image_thumb%5B1%5D.png" alt="image" width="640" height="220" border="0"></a></p><h2>Converting the byte[] array to an image</h2><p>To convert the byte[] array that represents the camera image to display it in an Image control (ex: image1 below), call the <strong>BitmapSource.Create </strong>method as shown below. The last parameter is stride. The <em>stride</em> is the number of bytes from one row of pixels in memory to the next row of pixels in memory. Stride is also called <em>pitch</em>.&nbsp; For more information, go to <a title="http://msdn.microsoft.com/en-us/library/aa473780(VS.85).aspx" href="http://msdn.microsoft.com/en-us/library/aa473780(VS.85).aspx">http://msdn.microsoft.com/en-us/library/aa473780(VS.85).aspx</a>:</p><p><strong>C#<br></strong><pre class="brush: csharp">
PlanarImage imageData = e.ImageFrame.Image;
image1.Source = BitmapSource.Create(imageData.Width, imageData.Height, 96, 96, 
                PixelFormats.Bgr32, null, imageData.Bits, data.Width * imageData.BytesPerPixel);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Dim imageData As PlanarImage = e.ImageFrame.Image
image1.Source = BitmapSource.Create(imageData.Width, imageData.Height, 96, 96, _
    PixelFormats.Bgr32, Nothing, imageData.Bits, imageData.Width * imageData.BytesPerPixel)
</pre></p><p>The <a href="http://c4fkinect.codeplex.com/">Coding4Fun Kinect Toolkit</a> has an extension method built into the ImageFrame class that simplifies creating the bitmap:</p><p><strong>C#<br></strong><pre class="brush: csharp">
image1.Source = e.ImageFrame.ToBitmapSource();
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
image1.Source = e.ImageFrame.ToBitmapSource()
</pre></p><h3>Getting Supported Resolutions</h3><p>The Kinect cameras can support different resolutions depending on what ImageType is passed in. To determine these resolutions, call the <strong>GetValidResolutions</strong> on the <strong>ImageStream </strong>object:</p><p><strong>C#</strong><br><pre class="brush: csharp">
var x = ImageStream.GetValidResolutions(ImageType.DepthAndPlayerIndex);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
Dim x = ImageStream.GetValidResolutions(ImageType.DepthAndPlayerIndex)
</pre></p><p><strong>Open the VideoStream</strong></p><p>Before the event will fire, you must call the Open method on VideoStream as shown below. This opens a video stream, sets the PoolSize to 2, sets the resolution to 640x480, and sets the return image as a color image:</p><p><strong>C#</strong><br><pre class="brush: csharp">
nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.VideoStream.Open(ImageStreamType.Video, 2, ImageResolution.Resolution640x480, ImageType.Color)
</pre></p><p><strong>Understanding PoolSize</strong></p><p>Pool Size is the number of buffers you want queued up. Usually, you want one displaying, and one being filled. The minimum is two but specifying more than two will give you slightly more latency in the frames you display, and so you’ll be more likely to have one waiting for you. The trade off, then, is smoother playback but higher latency.</p><h1>Task: Displaying Depth Data</h1><p>To add depth data, we use the same steps as above.</p><h3>Update the Runtime Initialization</h3><p>First, let’s review and see that the <strong>Initialize </strong>method includes <strong>RuntimeOptions.UseDepth </strong>to receive depth data from Kinect:</p><p><strong>C#</strong></p><p><pre class="brush: csharp">
nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepth);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepth)
</pre></p><h3>Subscribe to the DepthFrameReady event</h3><p>Next, add the event handler to receive the Depth information. For simplicity, we’ll use the Coding4Fun Kinect toolkit to display the depth image in the <strong>image2 Image </strong>control:</p><p><strong>C#</strong></p><p><pre class="brush: csharp">
nui.DepthFrameReady &#43;= new EventHandler&lt;ImageFrameReadyEventArgs&gt;(nui_DepthFrameReady);

void nui_DepthFrameReady(object sender, ImageFrameReadyEventArgs e)
{
    image2.Source = e.ImageFrame.ToBitmapSource(); 
}
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
AddHandler nui.DepthFrameReady, AddressOf nui_DepthFrameReady

Private Sub nui_DepthFrameReady(ByVal sender As Object, ByVal e As ImageFrameReadyEventArgs)
    image2.Source = e.ImageFrame.ToBitmapSource()
End Sub
</pre></p><h3>Open the Depth Stream</h3><p>Finally, we’ll call <strong>DepthStream.Open</strong> to open a 320x240 depth stream:</p><p><strong>C#</strong></p><p><pre class="brush: csharp">
nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.DepthStream.Open(ImageStreamType.Depth, 2, ImageResolution.Resolution320x240, ImageType.Depth)
</pre></p><p>The result is shown below:</p><p><a href="http://files.channel9.msdn.com/thumbnail/f6579560-3ab8-4997-a4d4-c150801b8e03.PNG" rel="lightbox"><img src="http://files.channel9.msdn.com/thumbnail/f6579560-3ab8-4997-a4d4-c150801b8e03.PNG" alt=""></a></p><h1>Task: Adjust the Kinect Camera Tilt</h1><blockquote><p><strong>Warning:</strong> The tilt mechanism in the sensor array is not rated for frequent use. Your code should not make calls to tilt the device more than 15 times in any two-minute window. Changing the tilt too often results in an error message from the function.</p></blockquote><h3>Setup</h3><p>Like before, create an instance of the Kinect <strong>Runtime </strong>class and call the <strong>Initialize</strong> method:</p><p><strong>C#</strong></p><p><pre class="brush: csharp">
Runtime nui = new Runtime();
nui.Initialize(RuntimeOptions.UseColor);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.Initialize(RuntimeOptions.UseColor)
</pre></p><h3>Adjusting the tilt</h3><p>To adjust the tilt or pitch, set the <strong>ElevationAngle </strong>property to a value between –27 (<strong>Camera.ElevationMinimum</strong>) and &#43;27 (<strong>Camera.ElevationMaximum</strong>). The code below sets the camera to the maximum elevation:</p><p><strong>C#</strong></p><p><pre class="brush: csharp">
nui.NuiCamera.ElevationAngle = Camera.ElevationMaximum;
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.NuiCamera.ElevationAngle = Camera.ElevationMaximum
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed&WT.dl=0&WT.entryid=Entry:RSSView:4ef787820c27406f89d89efc0065168e">]]></description>
      <comments>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals</comments>
      <itunes:summary>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. &amp;nbsp; This video covers the basics of reading camera data from the Kinect sensor.&amp;nbsp; 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:25] Camera data information [03:30] Creating the UI [04:48] Initializing the Kinect runtime [07:18] Reading values from the RGB camera [11:26] Reading values from the Depth camera [13:06] Adjusting camera tilt&amp;nbsp; &amp;nbsp;Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)The video has not been updated for Beta 2, but the following changes have been made: Creating the Kinect runtime uses the SetupKinect method used in the Setting Up Your Development Environment example. Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: &amp;quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&amp;quot; in the “Managed\KinectWpfViewers” solution. SetupThe steps below assume you have setup your development environment as explained in the Setting Up Your Development Environment video. To get a depth or color image you must do the followingCreate an instance of a runtime object Initialize the instance with the correct options Subscribe to an event to receive camera data Open the video stream Convert the raw camera data into an image Task: Display the RGB Camera ImageDesigning your UIWe’ll add two 320x240 Image controls to the MainWindow XAML file as shown in the following XAML: XAML
&amp;lt;Window x:Class=&amp;quot;WpfApplication1.MainWindow&amp;quot;
        xmlns=&amp;quot;http://schemas.microsoft.com/winfx/2006/xaml/presentation&amp;quot;
     </itunes:summary>
      <itunes:duration>936</itunes:duration>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals</link>
      <pubDate>Thu, 16 Jun 2011 17:14:38 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_2MB_ch9.wmv" expression="full" duration="936" fileSize="193517155" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_ch9.mp3" expression="full" duration="936" fileSize="7496811" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_ch9.wma" expression="full" duration="936" fileSize="7584071" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_ch9.wmv" expression="full" duration="936" fileSize="108779049" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_high_ch9.mp4" expression="full" duration="936" fileSize="297677523" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_low_ch9.mp4" expression="full" duration="936" fileSize="34974023" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals.ism/manifest" expression="full" duration="936" fileSize="8522" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/168e/4ef78782-0c27-406f-89d8-9efc0065168e/CameraFundamentals_ch9.wmv" length="108779049" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Dan Fernandez</dc:creator>
      <itunes:author>Dan Fernandez</itunes:author>
      <slash:comments>35</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Camera-Fundamentals/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Skeletal Tracking Fundamentals (Beta 2 SDK)</title>
      <description><![CDATA[<h2>Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)</h2><p>Please use the newly updated <a href="http://channel9.msdn.com/Series/KinectQuickstart">Kinect for Windows SDK Quickstart series</a>. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.</p><p>&nbsp;</p><p>This video covers the basics of skeletal tracking using the Kinect sensor.&nbsp; You may find it easier to follow along by downloading the <a href="http://files.ch9.ms/coding4fun/KinectForWindowsSDKBeta2.zip">Kinect for Windows SDK Quickstarts samples and slides</a> that have been updated for Beta 2 (Nov, 2011).</p><ul><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals#time=0m31s">00:31</a>] Skeleton Tracking API </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals#time=1m24s">01:24</a>] Understanding Skeleton Quality and Joint data </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals#time=3m27s">03:27</a>] Setup skeleton tracking </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals#time=3m44s">03:44</a>] Adding a basic hand tracked cursor </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals#time=9m12s">09:12</a>] Using <strong>TransformSmoothing</strong> to remove “skeletal jitter” </li></ul><h2>&nbsp;</h2><h3>Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)</h3><p>The video has not been updated for Beta 2, but the following changes have been made:</p><ul><li>Previously, the <strong>SkeletonFrameReady </strong>event would only fire when there was a tracked skeleton. The <strong>SkeletonFrameReady</strong> has been updated to fire continuously even when there are no skeletons being tracked. To get tracked skeletons, you can filter the list of skeletons to see if the <strong>TrackingState</strong> property is set to <strong>SkeletonTrackingState.Tracked</strong>. </li><li>Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: &quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&quot; </li></ul><h3>&nbsp;</h3><h3>Setup</h3><p>The steps below assume you have setup your development environment as explained in the <a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started">Setting Up Your Development Environment</a> video.</p><h1>Task: Setup skeleton tracking</h1><p>Create the Window_Loaded event</p><p>Go to the properties window (F4), select the MainWindow, select the Events tab, and double click on the Loaded event to create the <strong>Window_Loaded</strong> event</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B2%5D-1.png" alt="image" width="377" height="251" border="0"></p><p>&nbsp;</p><p><strong>Initializing the runtime</strong></p><p>Create a new variable <u>outside</u> of the Window_Loaded event to reference the Kinect runtime.</p><p><strong>C#<br></strong><pre class="brush: csharp">
Runtime nui = new Runtime();
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: csharp">
Dim nui As New Runtime()
</pre></p><p>In the <strong>Window_Loaded </strong>event, initialize the runtime with the options you want to use. For this example, set <strong>RuntimeOptions.UseSkeletalTracking </strong>to receive skeletal data and register for the <strong>SkeletonFrameReady</strong> event.</p><p><strong>C#<br></strong><pre class="brush: csharp">
nui.Initialize(RuntimeOptions.UseSkeletalTracking);

nui.SkeletonFrameReady &#43;= new EventHandler&lt;SkeletonFrameReadyEventArgs&gt;(nui_SkeletonFrameReady);

void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
}
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
nui.Initialize(RuntimeOptions.UseSkeletalTracking)

AddHandler nui.SkeletonFrameReady, AddressOf nui_SkeletonFrameReady

Private Sub nui_SkeletonFrameReady(ByVal sender As Object, ByVal e As SkeletonFrameReadyEventArgs)

End Sub
</pre></p><h2>Running the application</h2><p>Add a breakpoint inside the SkeletonFrameReady event and run the application.</p><blockquote><p><strong>Note</strong> – You will need to stand far enough away that the Kinect can see all or most of your skeleton for the SkeletonFrameReady event to fire.</p></blockquote><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image5.png" alt="image" width="684" height="44"></p><p>&nbsp;</p><p>When the breakpoint fires, you can inspect the <strong>SkeletonFrameReadyEventArgs </strong>to see that the <strong>SkeletonFrame</strong> returns a collection of six skeletons as shown below.</p><p>&nbsp;</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B11%5D.png" alt="image" width="640" height="343" border="0"></p><p>&nbsp;</p><p>&nbsp;</p><h1>Task: Add a basic hand tracked cursor</h1><p>In this example, we're going to use the position of the tracked skeleton's, head, left hand, and right hand to move ellipse controls.</p><h2>Designing your UI</h2><p>Starting from the project above, switch to MainWindow.xaml and make sure you can see the XAML code. We will add three three ellipses of varying color onto a Canvas control named <strong>MainCanvas</strong> as shown in the XAML below.</p><p><strong>XAML</strong><br><pre class="brush: xml">
&lt;Canvas Name=&quot;MainCanvas&quot;&gt;
    &lt;Ellipse Canvas.Left=&quot;0&quot; Canvas.Top=&quot;0&quot; Height=&quot;50&quot; Name=&quot;headEllipse&quot; Stroke=&quot;Black&quot; Width=&quot;50&quot; Fill=&quot;Orange&quot; /&gt;
    &lt;Ellipse Canvas.Left=&quot;50&quot; Canvas.Top=&quot;0&quot; Height=&quot;50&quot; Name=&quot;rightEllipse&quot; Stroke=&quot;Black&quot; Width=&quot;50&quot; Fill=&quot;SlateGray&quot; /&gt;
    &lt;Ellipse Canvas.Left=&quot;100&quot; Canvas.Top=&quot;0&quot; Fill=&quot;SpringGreen&quot; Height=&quot;50&quot; Name=&quot;leftEllipse&quot; Stroke=&quot;Black&quot; Width=&quot;50&quot; /&gt;
&lt;/Canvas&gt;
</pre></p><h3>Get the Tracked Skeleton</h3><p>In the <strong>SkeletonFrameReady </strong>event, we'll use a LINQ query to get the first tracked skeleton.</p><p><strong>C#<br></strong><pre class="brush: csharp">
void nui_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
    SkeletonFrame allSkeletons = e.SkeletonFrame;

    //get the first tracked skeleton
    SkeletonData skeleton = (from s in allSkeletons.Skeletons
                             where s.TrackingState == SkeletonTrackingState.Tracked
                             select s).FirstOrDefault();
}
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
Private Sub nui_SkeletonFrameReady(ByVal sender As Object, ByVal e As SkeletonFrameReadyEventArgs)
    Dim allSkeletons As SkeletonFrame = e.SkeletonFrame

    'get the first tracked skeleton
    Dim skeleton As SkeletonData = ( _
        From s In allSkeletons.Skeletons _
        Where s.TrackingState = SkeletonTrackingState.Tracked _
        Select s).FirstOrDefault()
End Sub
</pre></p><h3>Getting a Joint position</h3><p>A <strong>Joint </strong>position returns <strong>X,Y,Z </strong>values as explained below</p><ul><li>X = Horizontal position measured as the distance, in meters from the Kinect along the X Axis </li><li>Y = Vertical position measured as the distance, in meters from the Kinect along the Y Axis </li><li>Z = Distance from Kinect measured in meters </li></ul><p><strong>Scaling a Joint value</strong></p><p>Given that the X and Y positions are distance measurements, we can use the Coding4Fun Kinect Toolkit <strong>ScaleTo </strong>method to scale the value to a maximum X and Y position as shown below.</p><p><strong>C#<br></strong><pre class="brush: csharp">
Joint HandRight =  skeleton.Joints[JointID.HandRight].ScaleTo(640, 480);
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(640, 480)
</pre></p><p>You can also constrain the maximum values for the skeletal joints to a smaller range.&nbsp; For example, if you were designing an application where the user can reach around the screen to touch things, you may not want them to have to walk two feet left or right to reach the edges.&nbsp; By using the second version of the <strong>ScaleTo</strong> method, you can specify the range of the specified joint to something smaller as shown:</p><p><strong>C#<br></strong><pre class="brush: csharp">
Joint HandRight =  skeleton.Joints[JointID.HandRight].ScaleTo(640, 480, .5f, .5f);
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
Dim HandRight = skeleton.Joints(JointID.HandRight).ScaleTo(640, 480, .5f, .5f)
</pre></p><p>This code will make it so that your right hand only has to travel one meter (joint range of -0.5 to &#43;0.5) to traverse the pixels at 0 to 640. If you set this value to –1 to &#43;1, for example, then the right hand would have to travel two meters total, one meter to the left, one meter to the right to traverse the 640 pixels.</p><p>Also, as you can see above, you can get a particular <strong>Joint</strong>, like the <strong>HandRight Joint</strong>, by using the skeleton indexer for the <strong>Joints </strong>collection.</p><h3>Setting an Ellipse Position</h3><p>To move the ellipses in our <strong>MainWindow</strong>&nbsp; to the location of a <strong>Joint</strong>, we will use the method below that sets the <strong>Canvas.Left </strong>and <strong>Canvas.Top </strong>position to the X (Left) and Y (Top) value from the <strong>Joint </strong>parameter.</p><p><strong>C#<br></strong><pre class="brush: csharp">
private void SetEllipsePosition(FrameworkElement ellipse, Joint joint)
{
    var scaledJoint = joint.ScaleTo(640, 480, .5f, .5f);

    Canvas.SetLeft(ellipse, scaledJoint.Position.X);
    Canvas.SetTop(ellipse, scaledJoint.Position.Y);
}
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
Private Sub SetEllipsePosition(ByVal ellipse As FrameworkElement, ByVal joint As Joint)
    Dim scaledJoint = joint.ScaleTo(640, 480,.5f,.5f)

    Canvas.SetLeft(ellipse, scaledJoint.Position.X)
    Canvas.SetTop(ellipse, scaledJoint.Position.Y)
End Sub
</pre></p><h3>&nbsp;</h3><h3>Putting it all together</h3><p>Finally, in the <strong>nui_SkeletonFrameReady </strong>event, call the SetEllipsePosition methods for the three joints as shown below:</p><p><strong>C#<br></strong><pre class="brush: csharp">
SetEllipsePosition(headEllipse, skeleton.Joints[JointID.Head]);
SetEllipsePosition(leftEllipse, skeleton.Joints[JointID.HandLeft]);
SetEllipsePosition(rightEllipse, skeleton.Joints[JointID.HandRight]);
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
SetEllipsePosition(headEllipse, skeleton.Joints(JointID.Head))
SetEllipsePosition(leftEllipse, skeleton.Joints(JointID.HandLeft))
SetEllipsePosition(rightEllipse, skeleton.Joints(JointID.HandRight))
</pre></p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B18%5D.png" alt="image" width="640" height="333" border="0"></p><p>&nbsp;</p><p>&nbsp;</p><h1>Task: Using <strong>TransformSmoothing</strong> to for less skeletal jitter</h1><p>Using the same application as above, you may notice jitteriness in the hand positions as small changes between updates to the SkeletalFrameReady event change the location of the ellipses.</p><p><strong>Using TransformSmoothParameters</strong></p><p>To see the difference between using and not using TransformSmoothing, toggle the true/false <strong>TransformSmooth</strong> property.&nbsp; There are two ways to use TransformSmoothing, you can set it to true and it will use a default set of parameters, or you can customize and experiment with each of the parameters to find the parameters that work best for your application. To do that, you’ll need create the <strong>TransformSmoothParameters</strong> struct yourself and define the parameters.</p><p>You must set the TransformSmoothParameters <u>after</u> calling the <strong>nui.Initialize </strong>method.</p><blockquote><p><strong>Note:</strong> Since every application is different, you will need to experiment with the parameters to understand what's right for your application.</p></blockquote><p><strong>C#<br></strong><pre class="brush: csharp">
private void SetupKinect()
{
     if (Runtime.Kinects.Count == 0)
     {
         this.Title = &quot;No Kinect connected&quot;; 
     }
     else
     {
         //use first Kinect
         nui = Runtime.Kinects[0];
         //Initialize to do skeletal tracking
         nui.Initialize(RuntimeOptions.UseSkeletalTracking);
         //add event to receive skeleton data
         nui.SkeletonFrameReady &#43;= new EventHandler&lt;SkeletonFrameReadyEventArgs&gt;(nui_SkeletonFrameReady);
         //to experiment, toggle TransformSmooth between true &amp; false
         // parameters used to smooth the skeleton data
         nui.SkeletonEngine.TransformSmooth = true;
         TransformSmoothParameters parameters = new TransformSmoothParameters();
         parameters.Smoothing = 0.7f;
         parameters.Correction = 0.3f;
         parameters.Prediction = 0.4f;
         parameters.JitterRadius = 1.0f;
         parameters.MaxDeviationRadius = 0.5f;
         nui.SkeletonEngine.SmoothParameters = parameters;
     }
}
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
        Private Sub SetupKinect()
            If Runtime.Kinects.Count = 0 Then
                Me.Title = &quot;No Kinect connected&quot;
            Else
                'use first Kinect
                nui = Runtime.Kinects(0)
                'Initialize to do skeletal tracking
                nui.Initialize(RuntimeOptions.UseSkeletalTracking)
                'add event to receive skeleton data
                AddHandler nui.SkeletonFrameReady, AddressOf nui_SkeletonFrameReady
                'to experiment, toggle TransformSmooth between true &amp; false
                ' parameters used to smooth the skeleton data
                nui.SkeletonEngine.TransformSmooth = True
                Dim parameters As New TransformSmoothParameters()
                parameters.Smoothing = 0.7f
                parameters.Correction = 0.3f
                parameters.Prediction = 0.4f
                parameters.JitterRadius = 1.0f
                parameters.MaxDeviationRadius = 0.5f
                nui.SkeletonEngine.SmoothParameters = parameters
            End If
        End Sub
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed&WT.dl=0&WT.entryid=Entry:RSSView:11c93a9515994c55b7f09efd005e0c65">]]></description>
      <comments>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals</comments>
      <itunes:summary>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. &amp;nbsp; This video covers the basics of skeletal tracking using the Kinect sensor.&amp;nbsp; 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:31] Skeleton Tracking API [01:24] Understanding Skeleton Quality and Joint data [03:27] Setup skeleton tracking [03:44] Adding a basic hand tracked cursor [09:12] Using TransformSmoothing to remove “skeletal jitter” &amp;nbsp;Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)The video has not been updated for Beta 2, but the following changes have been made: Previously, the SkeletonFrameReady event would only fire when there was a tracked skeleton. The SkeletonFrameReady has been updated to fire continuously even when there are no skeletons being tracked. To get tracked skeletons, you can filter the list of skeletons to see if the TrackingState property is set to SkeletonTrackingState.Tracked. Beta 2 includes a sample (Microsoft.Samples.Kinect.WpfViewers) set of user controls for visualizing data from the Color/RGB and Depth cameras that you can reuse in your application. The samples can be found at: &amp;quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&amp;quot; &amp;nbsp;SetupThe steps below assume you have setup your development environment as explained in the Setting Up Your Development Environment video. Task: Setup skeleton trackingCreate 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  &amp;nbsp; Initializing the runtime Create a new variable outside of the Window_Loaded event to reference the Kinect runtime. C#
Runtime nui = new Runtime();
 </itunes:summary>
      <itunes:duration>736</itunes:duration>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals</link>
      <pubDate>Thu, 16 Jun 2011 17:13:16 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_2MB_ch9.wmv" expression="full" duration="736" fileSize="159508403" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_ch9.mp3" expression="full" duration="736" fileSize="5894796" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_ch9.wma" expression="full" duration="736" fileSize="5964915" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_ch9.wmv" expression="full" duration="736" fileSize="100777849" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_high_ch9.mp4" expression="full" duration="736" fileSize="248429445" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_low_ch9.mp4" expression="full" duration="736" fileSize="38941464" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals.ism/manifest" expression="full" duration="736" fileSize="8682" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/0c65/11c93a95-1599-4c55-b7f0-9efd005e0c65/SkeletalTrackingFundamentals_ch9.wmv" length="100777849" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Dan Fernandez</dc:creator>
      <itunes:author>Dan Fernandez</itunes:author>
      <slash:comments>72</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Skeletal-Tracking-Fundamentals/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Setting Up Your Development Environment (Beta 2 SDK)</title>
      <description><![CDATA[<h2>Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)</h2><p>Please use the newly updated <a href="http://channel9.msdn.com/Series/KinectQuickstart">Kinect for Windows SDK Quickstart series</a>. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.</p><p>&nbsp;</p><p>This video covers how to set up your development environment. You may find it easier to follow along by downloading the <a href="http://files.ch9.ms/coding4fun/KinectForWindowsSDKBeta2.zip">Kinect for Windows SDK Quickstarts samples and slides</a> that have been updated for Beta 2 (Nov, 2011).</p><ul><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started#time=5m6s">00:35</a>] Sample Requirements </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started#time=1m50s">01:50</a>] Starting the Demo </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started#time=2m13s">02:13</a>] Adding References </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started#time=2m45s">02:45</a>] Coding4Fun Kinect Library </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started#time=3m23s">03:23</a>] Initializing the Kinect Runtime </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started#time=5m41s">05:41</a>] Uninitializing the Kinect Runtime </li></ul><h3>Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)</h3><p>The video in the Kinect for Windows SDK has not been updated, but the tutorial below has the following changes:</p><ul><li>The Microsoft.Research.Kinect DLL version is now <strong>1.0.0.45</strong>. </li><li>The requirements for DirectX samples have been clarified to say that they are only required for C&#43;&#43;. </li><li>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). </li><li>The source code for shipping examples is now in &quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&quot; </li><li>The Kinect runtime now provides a <strong>StatusChanged</strong> 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 <strong>StatusChanged</strong> event. </li><li>For an example on setting up and handling Kinect connect/disconnect events, refer to the ShapeGame sample. </li><li>For an example&nbsp; on how to show two Kinects at the same time, refer to the SkeletalViewer sample. </li></ul><p>&nbsp;</p><h1>Task: Download Sample Requirements</h1><p>Some samples use DirectX and the Microsoft Speech APIs. For these demos to work, you must download the correct pre-requisite software.</p><p><strong>Kinect for Windows SDK:</strong></p><ul><li><a href="http://www.kinectforwindows.org">http://www.kinectforwindows.org</a> </li></ul><p><strong>Visual Studio:</strong></p><ul><li><a href="http://www.microsoft.com/express/">Visual Studio 2010 Express edition</a> of the demo in the appropriate programming language or <a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=26bae65f-b0df-4081-ae6e-1d828993d4d0&amp;displaylang=en">Visual Studio Professional or higher</a> </li></ul><p><strong>DirectX Samples (for C&#43;&#43; Skeletal Viewer)</strong></p><ul><li><a href="http://www.microsoft.com/downloads/en/details.aspx?displaylang=en&amp;FamilyID=3021d52b-514e-41d3-ad02-438a3ba730ba">Microsoft DirectX® SDK - June 2010</a> or later version </li><li><a href="http://www.microsoft.com/downloads/en/details.aspx?familyid=2DA43D38-DB71-4C1B-BC6A-9B6652CD92A3&amp;displaylang=en">Current runtime for Microsoft DirectX® 9</a> </li></ul><p><strong>Speech Samples</strong>:</p><p>For Speech samples:</p><ul><li><a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=bb0f72cb-b86b-46d1-bf06-665895a313c7">Microsoft Speech Platform Runtime, version 10.2</a> – select 32-bit if you are running 32-bit Windows. If you have 64-bit Windows, we suggest that you install both the 32-bit and 64-bit runtime. </li><li><a href="http://www.microsoft.com/downloads/en/details.aspx?FamilyID=1b1604d3-4f66-4241-9a21-90a294a5c9a4&amp;displaylang=en">Microsoft Speech Platform - Software Development Kit, version 10.2</a> – select 32-bit or 64-bit according to your Windows installation </li><li><a href="http://go.microsoft.com/fwlink/?LinkId=220942">Kinect for Windows Runtime Language Pack, version 0.9</a> </li></ul><p>&nbsp;</p><h1>Task: Setting up a new Visual Studio 2010 Project</h1><ul><li>In this task, you’ll create a new Visual Studio 2010 project and add references to the correct libraries </li><li>Start Visual Studio 2010 (Express Editions or higher) </li><li>Select <strong>File </strong><strong>–&gt;</strong>&nbsp;<strong>New Project </strong><strong>–&gt;</strong>&nbsp;<strong>Windows Presentation Foundation</strong> and set the name for your project <br><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B5%5D.png" alt="image" width="640" height="368" border="0"> </li></ul><p>&nbsp;</p><h3>Add a reference</h3><ul><li><strong>C# –</strong> From the Solution Explorer, right click on <strong>References</strong> and select <strong>Add Reference </strong>as shown below </li></ul><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B8%5D.png" alt="image" width="418" height="174" border="0"></p><p>&nbsp;</p><ul><li><strong>Visual Basic</strong> – From the Solution Explorer, right click on the project name and select <strong>Add Reference</strong> as shown below </li></ul><p>&nbsp;</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B8%5D-1.png" alt="image" width="420" height="417" border="0"></p><p><strong>Visual Basic / C#</strong> – In the <strong>Add Reference</strong> dialog, switch to the <strong>.NET </strong>tab, click the <strong>Component Name </strong>header to sort references alphabetically, then scroll down to select <strong>Microsoft.Research.Kinect </strong>and click <strong>OK. </strong>Make sure to select <strong>1.0.0.45</strong>.</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image3.png" alt="image" width="518" height="431"></p><p>&nbsp;</p><h2>Add a using statement</h2><p>Within your project, you can now add a <strong>using</strong> statement to reference the Kinect namespaces:</p><p><strong>C#</strong></p><p><pre class="brush: csharp">
using Microsoft.Research.Kinect.Nui;
using Microsoft.Research.Kinect.Audio;
</pre></p><p><strong>Visual Basic</strong></p><p><pre class="brush: vb">
Imports Microsoft.Research.Kinect.Nui
Imports Microsoft.Research.Kinect.Audio
</pre></p><h3>Optional: Using the Coding4Fun Kinect Toolkit</h3><p>Go to <a href="http://c4fkinect.codeplex.com">http://c4fkinect.codeplex.com</a> 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&nbsp; as converting the data from the Kinect to a data array or Bitmap.</p><p>Depending on if you are building a WPF or Windows Form application, we have two different DLLs:</p><ul><li><strong>WPF Applications: </strong>use the Coding4Fun.Kinect.Wpf.dll </li><li><strong>Windows Form Applications: </strong>use the Coding4Fun.Kinect.WinForm.dll </li></ul><p><strong>C#</strong></p><p><pre class="brush: csharp">
// if you're using WPF
using Coding4Fun.Kinect.Wpf;

// if you're using WinForms
using Coding4Fun.Kinect.WinForm;
</pre></p><p><strong>Visual Basic</strong></p><p><pre class="brush: vb">
' if you're using WPF
Imports Coding4Fun.Kinect.Wpf

' if you're using WinForms
Imports Coding4Fun.Kinect.WinForm
</pre></p><h1>Initializing and Uninitializing the runtime</h1><p>For NUI, we have to initialize and uninitialize the runtime.&nbsp; In our examples, we typically will initialize on the <strong>Loaded</strong> event on the Window and we'll uninitialize on the <strong>Closed </strong>event. Depending on what needs to be done, the <strong>Initialize</strong> method on the runtime will be tweaked though the concepts stay the same.</p><h3>Create the Window_Loaded event</h3><p>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</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B5%5D-1.png" alt="image" width="377" height="251" border="0"></p><h3>&nbsp;</h3><h3>Initializing the runtime</h3><p>Create a new <strong>Runtime</strong> variable named “nui” <u>outside</u> of the Window_Loaded event. When the Window_Loaded event fires, we will call the <strong>SetupKinect </strong>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).&nbsp;</p><p><strong>C#<br></strong><pre class="brush: csharp">
//Kinect Runtime
Runtime nui;
private void Window_Loaded(object sender, RoutedEventArgs e)
{
    SetupKinect(); 
    
}
private void SetupKinect()
{
    if (Runtime.Kinects.Count == 0)
    {
        this.Title = &quot;No Kinect connected&quot;;
    }
    else
    {
        //use first Kinect
        nui = Runtime.Kinects[0];
        nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking);
    }
}
</pre></p><p><strong>Visual Basic<br></strong><pre class="brush: vb">
       '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 = &quot;No Kinect connected&quot;
            Else
                'use first Kinect
                nui = Runtime.Kinects(0)
                nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)
            End If
        End Sub
</pre></p><p>&nbsp;</p><h3>Handling multiple Kinects</h3><p>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.</p><p><strong>C#</strong></p><p>[code lang=”csharp”]</p><p>int KinectCount = Runtime.Kinects.Count;</p><p>[/code]</p><p><strong>Visual Basic</strong></p><p>[code lang=”vb”]</p><p>Dim KinectCount as Integer = Runtime.Kinects.Count</p><p>[/code]</p><p>&nbsp;</p><h3>Handling Kinect Status Change events</h3><p>You can also handle events when the status changes for Kinects that are plugged in. To do this, first register for the <strong>StatusChanged</strong> event as shown below. When this event fires, it returns a <strong>KinectStatus</strong> enum with the following possible values: Connected, Error, Disconnected, NotReady, or NotPowered.</p><p>&nbsp;</p><p><strong>C#</strong></p><p>[code lang=”csharp”]</p><pre>Runtime.Kinects.StatusChanged &#43;= new EventHandler&lt;StatusChangedEventArgs&gt;(Kinects_StatusChanged);</pre><pre>…</pre><p>void Kinects_StatusChanged(object sender, StatusChangedEventArgs e)<br>{<br>&nbsp;&nbsp;&nbsp; string message = &quot;Status Changed: &quot;;<br>&nbsp;&nbsp;&nbsp; switch (e.Status)<br>&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case KinectStatus.Connected:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Connected&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case KinectStatus.Disconnected:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Disconnected&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case KinectStatus.Error:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Error&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case KinectStatus.NotPowered:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Not Powered&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; case KinectStatus.NotReady:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Not Ready&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; default:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (e.Status.HasFlag(KinectStatus.Error))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Kinect error&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; break;<br>&nbsp;&nbsp;&nbsp; }<br>&nbsp;&nbsp;&nbsp; this.Title = message;<br>}</p><p>[/code]</p><p>&nbsp;</p><p><strong>Visual Basic</strong></p><p>[code lang=”vb”]</p><p>AddHandler Runtime.Kinects.StatusChanged, AddressOf Kinects_StatusChanged</p><p>…</p><p>Private Sub Kinects_StatusChanged(sender As Object, e As StatusChangedEventArgs)<br>&nbsp;&nbsp;&nbsp; Dim message As String = &quot;Status Changed: &quot;<br>&nbsp;&nbsp;&nbsp; Select Case e.Status<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case KinectStatus.Connected<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Connected&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case KinectStatus.Disconnected<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Disconnected&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case KinectStatus.[Error]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Error&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case KinectStatus.NotPowered<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Not Powered&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case KinectStatus.NotReady<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Not Ready&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Select<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Case Else<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; If e.Status.HasFlag(KinectStatus.[Error]) Then<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; message &#43;= &quot;Kinect error&quot;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End If<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Exit Select<br>&nbsp;&nbsp;&nbsp; End Select<br>&nbsp;&nbsp;&nbsp; Me.Title = message</p><p><br>End Sub</p><p>&nbsp;</p><p>[/code]</p><p>&nbsp;</p><h3>Setting Runtime Options</h3><p>In the <strong>Window_Loaded </strong>event, initialize the runtime with the options you want to use. For this example, set <strong>RuntimeOptions.UseColor</strong> to use the RGB camera:</p><p><strong>C#</strong><br><pre class="brush: csharp">
nui.Initialize(RuntimeOptions.UseColor);
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.Initialize(RuntimeOptions.UseColor)
</pre></p><p><strong>RuntimeOptions </strong>is a Flag enumeration, this means you can set multiple options as parameters in the Initialize method by separating them with the pipe &quot;<strong>|</strong>&quot; character (the &quot;or&quot; operator) in c# or the &quot;<strong>Or</strong>&quot; operator in Visual Basic. The example below sets the runtime to use the color camera, a depth camera, and skeletal tracking:</p><p><strong>C#<br></strong><pre class="brush: csharp">
nui.Initialize(RuntimeOptions.UseColor | RuntimeOptions.UseDepthAndPlayerIndex | RuntimeOptions.UseSkeletalTracking );
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.Initialize(RuntimeOptions.UseColor Or RuntimeOptions.UseDepthAndPlayerIndex Or RuntimeOptions.UseSkeletalTracking)
</pre></p><h3>Uninitializing the Runtime</h3><p>Remember that when you are done using the Kinect Runtime, you should call the <strong>Uninitialize</strong> method. For a WPF application, you would typically do this in the <strong>Windows_Closed</strong> event:</p><p><strong>C#<br></strong><pre class="brush: csharp">
nui.Uninitialize();
</pre></p><p><strong>Visual Basic</strong><br><pre class="brush: vb">
nui.Uninitialize()
</pre></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed&WT.dl=0&WT.entryid=Entry:RSSView:8b0685ac5f5543cc87649efe00713a32">]]></description>
      <comments>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started</comments>
      <itunes:summary>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. &amp;nbsp; 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&amp;#43;&amp;#43;. 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 &amp;quot;\Program Files\Microsoft SDKs\Kinect\v1.0 Beta2\Samples\KinectSDKSamples.zip&amp;quot; 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&amp;nbsp; on how to show two Kinects at the same time, refer to the SkeletalViewer sample. &amp;nbsp; Task: Download Sample RequirementsSome 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: http://www.kinectforwindows.org Visual Studio: Visual Studio 201</itunes:summary>
      <itunes:duration>410</itunes:duration>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started</link>
      <pubDate>Thu, 16 Jun 2011 17:11:58 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_2MB_ch9.wmv" expression="full" duration="410" fileSize="95950173" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_ch9.mp3" expression="full" duration="410" fileSize="3288629" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_ch9.wma" expression="full" duration="410" fileSize="3330407" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_ch9.wmv" expression="full" duration="410" fileSize="52503893" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_high_ch9.mp4" expression="full" duration="410" fileSize="137766648" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_low_ch9.mp4" expression="full" duration="410" fileSize="17706281" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment.ism/manifest" expression="full" duration="410" fileSize="8602" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/3a32/8b0685ac-5f55-43cc-8764-9efe00713a32/SettingUpDevEnvironment_ch9.wmv" length="52503893" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Dan Fernandez</dc:creator>
      <itunes:author>Dan Fernandez</itunes:author>
      <slash:comments>62</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Getting-Started/RSS</wfw:commentRss>
    </item>
  <item>
      <title>Installing and Using the Kinect Sensor (Beta 2 SDK)</title>
      <description><![CDATA[<h2>Update: Kinect for Window SDK v1 Quickstart Series now Available (Feb 1st)</h2><p>Please use the newly updated <a href="http://channel9.msdn.com/Series/KinectQuickstart">Kinect for Windows SDK Quickstart series</a>. The content below will only work with the Beta 2 version of the Kinect for Windows SDK.</p><p>&nbsp;</p><p>This video covers the basics of installing and using the Kinect sensor. You may find it easier to follow along by downloading the <a href="http://files.ch9.ms/coding4fun/KinectForWindowsSDKBeta2.zip">Kinect for Windows SDK Quickstarts samples and slides</a> that have been updated for Beta 2 (Nov, 2011).</p><ul><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware#time=2m34s">02:34</a>] Overview of Kinect Sensor </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware#time=5m6s">05:06</a>] Device Manager </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware#time=5m36s">05:36</a>] Using Kinect as an Audio Device </li><li>[<a href="http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware#time=7m11s">07:11</a>] Using Kinect for Speech Recognition </li></ul><h3>Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)</h3><p>The video has not been updated for Beta 2, but the following changes have been made:</p><ul><li>The new Web site for Kinect is <a href="http://kinectforwindows.org">http://kinectforwindows.org</a> </li></ul><h1>Installing the Kinect for Windows SDK</h1><p>Download the 32-bit or 64-bit version of the Kinect for Windows SDK at <a title="http://research.microsoft.com/kinectsdk" href="http://kinectforwindows.org">http://kinectforwindows.org</a></p><h1>Kinect Hardware Basics</h1><p><a href="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B7%5D-1.png"><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image_thumb%5B3%5D.png" alt="image" width="640" height="419" border="0"></a></p><p><strong>The Kinect Sensor consists of the following:</strong></p><ul><li><strong>RGB Camera </strong>– A regular video camera that has a resolution of 640x480 at 30 frames per second </li><li><strong>3D Depth Sensors </strong>– This is a combination of a depth projector (left reticule) and sensor (right reticule) to calculate distance. For more information, see the <a href="http://channel9.msdn.com/Shows/InsideXbox/The-tech-behind-Kinect-Major-subsystems-RGB-camera-Depth-Sensor">Tech behind Kinect video</a> </li><li><strong>Motorized Tilt </strong>– The motorized tilt enables you to adjust the camera up or down 27 degrees to ensure that the camera has the best possible view of you </li><li><strong>Multi-Array Microphone </strong>– A four-microphone array that is mounted as a single microphone in Windows </li></ul><h2>Device manager</h2><p>After installing the Kinect for Windows SDK and plugging in the Kinect to a USB port on your computer. Click <strong>Control Panel –&gt; Device Manager</strong>. You should see Microsoft Kinect as shown below</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image2.png" alt="image" width="276" height="78" border="0"></p><h2>Audio Microphone</h2><p>The Kinect microphone can be used for any application that uses a microphone. In the picture below, you’ll see that you can go to <strong>Control Panel –&gt; Sounds </strong>and select the <strong>Recording </strong>tab to see the Kinect microphone array</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image6.png" alt="image" width="431" height="475" border="0"></p><p>&nbsp;</p><h2><strong>Using the Kinect Microphone with Windows Sound Recorder</strong></h2><p>To use Kinect as a microphone for Windows Sound Recorder, simply ensure that the Kinect microphone is setup in the <strong>Sound control panel </strong>(above) as the default sound recorder. Click the <strong>Start Recording </strong>button to start recording using the Kinect as a microphone and click the <strong>Stop Recording </strong>button to be prompted where to save your file</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image10.png" alt="image" width="429" height="88" border="0"></p><h2>How to use Windows Speech Recognition with the Kinect microphone</h2><p>Click <strong>Start</strong> and type “Windows Speech Recognition” and hit enter or, in the Sound control panel, right click and select Configure Speech Recognition as shown below</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image16.png" alt="image" width="521" height="486" border="0"></p><p>&nbsp;</p><p>If you’ve never used speech recognition before, consider using the <strong>Take Speech Tutorial </strong>option and reviewing the <strong>Speech Reference Card</strong>. If you are familiar with speech recognition, select <strong>Start Speech Recognition</strong></p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B16%5D-1.png" alt="image" width="694" height="411" border="0"></p><p>Since the Kinect is a microphone array, make sure to select the <strong>Other </strong>option as shown below</p><p><img title="image" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/image%5B13%5D.png" alt="image" width="583" height="480" border="0"></p><p>Once the Windows Speech Recognition application has started, your screen will display the following widget, which you can use to interact with Speech Recognition application if required</p><p><a href="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/SNAGHTML237f6b5a%5B5%5D.png"><img title="SNAGHTML237f6b5a" src="http://files.channel9.msdn.com/wlwimages/9c00b398b405423b99d19efa016fae96/SNAGHTML237f6b5a_thumb%5B2%5D.png" alt="SNAGHTML237f6b5a" width="344" height="82" border="0"></a></p> <img src="http://m.webtrends.com/dcs1wotjh10000w0irc493s0e_6x1g/njs.gif?dcssip=channel9.msdn.com&dcsuri=http://channel9.msdn.com/Series/KinectSDKQuickstarts/feed&WT.dl=0&WT.entryid=Entry:RSSView:c94194fba322411e8a0a9efe0072ada8">]]></description>
      <comments>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware</comments>
      <itunes:summary>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. &amp;nbsp; This video covers the basics of installing and using the Kinect sensor. 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). [02:34] Overview of Kinect Sensor [05:06] Device Manager [05:36] Using Kinect as an Audio Device [07:11] Using Kinect for Speech Recognition Updates for Kinect for Windows SDK Beta 2 (Nov, 2011)The video has not been updated for Beta 2, but the following changes have been made: The new Web site for Kinect is http://kinectforwindows.org Installing the Kinect for Windows SDKDownload the 32-bit or 64-bit version of the Kinect for Windows SDK at http://kinectforwindows.org Kinect Hardware Basics The Kinect Sensor consists of the following: RGB Camera – A regular video camera that has a resolution of 640x480 at 30 frames per second 3D Depth Sensors – This is a combination of a depth projector (left reticule) and sensor (right reticule) to calculate distance. For more information, see the Tech behind Kinect video Motorized Tilt – The motorized tilt enables you to adjust the camera up or down 27 degrees to ensure that the camera has the best possible view of you Multi-Array Microphone – A four-microphone array that is mounted as a single microphone in Windows Device managerAfter installing the Kinect for Windows SDK and plugging in the Kinect to a USB port on your computer. Click Control Panel –&amp;gt; Device Manager. You should see Microsoft Kinect as shown below  Audio MicrophoneThe Kinect microphone can be used for any application that uses a microphone. In the picture below, you’ll see that you can go to Control Panel –&amp;gt; Sounds and select the Recording tab to see the Kinect microphone array  &amp;nbsp; Using th</itunes:summary>
      <itunes:duration>536</itunes:duration>
      <link>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware</link>
      <pubDate>Thu, 16 Jun 2011 16:52:09 GMT</pubDate>
      <guid isPermaLink="false">http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware</guid>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_100_ch9.jpg" height="75" width="100"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_220_ch9.jpg" height="165" width="220"></media:thumbnail>
      <media:thumbnail url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_512_ch9.jpg" height="384" width="512"></media:thumbnail>
      <media:group>
        <media:content url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_2MB_ch9.wmv" expression="full" duration="536" fileSize="348286845" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_ch9.mp3" expression="full" duration="536" fileSize="4291311" type="audio/mp3" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_ch9.wma" expression="full" duration="536" fileSize="4342753" type="audio/x-ms-wma" medium="audio"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_ch9.wmv" expression="full" duration="536" fileSize="86696648" type="video/x-ms-wmv" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_high_ch9.mp4" expression="full" duration="536" fileSize="196428729" type="video/mp4" medium="video"></media:content>
        <media:content url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_low_ch9.mp4" expression="full" duration="536" fileSize="26343483" type="video/mp4" medium="video"></media:content>
        <media:content url="http://smooth.ch9.ms/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall.ism/manifest" expression="full" duration="536" fileSize="8442" type="video/x-ms-wmv" medium="video"></media:content>
      </media:group>      
      <enclosure url="http://ak.channel9.msdn.com/ch9/ada8/c94194fb-a322-411e-8a0a-9efe0072ada8/KinectInstall_ch9.wmv" length="86696648" type="video/x-ms-wmv"></enclosure>
      <dc:creator>Dan Fernandez</dc:creator>
      <itunes:author>Dan Fernandez</itunes:author>
      <slash:comments>46</slash:comments>
      <wfw:commentRss>http://channel9.msdn.com/Series/KinectSDKQuickstarts/Understanding-Kinect-Hardware/RSS</wfw:commentRss>
    </item>    
</channel>
</rss>