Partilhar via


Playing with “Kinect for Windows SDK” Series

KinectForWindows <<Based on Kinect for Windows SDK beta 2>>

I have been playing with Kinect for Windows SDK from last few weeks. It’s really a fun. With several things happening on Kinect, apart from Xbox gaming and Entertainment, Kinect is coming out from Living room, check out The Kinect Effect, announcement on Kinect for Windows commercially available Starting February 1, 2012: Use the Power of Kinect for Windows to Change the World and The Kinect Accelerator on Microsoft BizSpark.

I really got excited to explore SDK.

What you need to begin -  Kinect Sensor, USB powered cable for Kinect Sensor and Kinect for Windows SDK beta 2. I recommend Understanding Kinect Hardware on channel 9.

This week in this series, I am covering how to get started with Kinect for Windows SDK

  • Start a new WPF Application Project using Visual Studio 2010

  • Add reference Microsoft.Research.Kinect.dll from "%KINECTSDK_DIR%\Assemblies"

  • Add using directive in MainWindow.xaml
    using Microsoft.Research.Kinect.Nui;

  • Declare Runtime variable named nui in MainWindow class level
    Runtime nui;

  • Add Window_Loaded event handler for MainWindow
    if (Runtime.Kinects.Count > 0)
    {
    nui = Runtime.Kinects[0];
    nui.Initialize(RuntimeOptions.UseColor);
    }

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

  • Define Kinects_StatusChanged
    void Kinects_StatusChanged(object sender, StatusChangedEventArgs e)
    {
    switch (e.Status)
    {
    case KinectStatus.Connected:
    nui = e.KinectRuntime;
    nui.Initialize(RuntimeOptions.UseColor);
    break;
    case KinectStatus.Disconnected:
    //handle what to do when disconnected
    break;
    case KinectStatus.Error:
    //handle what to do when error
    break;
    case KinectStatus.NotPowered:
    //handle what to do when not powered
    break;
    case KinectStatus.NotReady:
    //handle what to do when not ready
    break;
    default:
    break;

    }
    }

  • Add Window closed handler for MainWindow

              private void Window_Closed(object sender, EventArgs e)
{
if (nui!=null)
{
nui.Uninitialize();
}

}

Let us also see how Kinect Camera can be tilted.

  • Added two buttons Up and Down Tilt in MainWindow and Click handler for button to Tilt Camera up and down.

private void TiltUp_Click(object sender, RoutedEventArgs e)
{
if ((nui.NuiCamera.ElevationAngle)<=Camera.ElevationMaximum)
{
if ((nui.NuiCamera.ElevationAngle+4)>=Camera.ElevationMaximum)
{
nui.NuiCamera.ElevationAngle = Camera.ElevationMaximum;
}
else
   {
nui.NuiCamera.ElevationAngle += 4;
}
}
}

private void TiltDown_Click(object sender, RoutedEventArgs e)
{
if ((nui.NuiCamera.ElevationAngle)>= Camera.ElevationMinimum)
{
if ((nui.NuiCamera.ElevationAngle - 4) <= Camera.ElevationMinimum)
{
nui.NuiCamera.ElevationAngle = Camera.ElevationMinimum;
}
else
{
nui.NuiCamera.ElevationAngle -= 4;
}
}
}

and Run it, and try Tilt up and down…

image

 Warning: The tilt mechanism in the sensor array is not rated for frequent use. You should tilt the Kinect sensor as few times as possible, to minimize wear on the camera and to minimize tilting time. The camera motor is not designed for constant or repetitive movement, and attempts to use it that way may cause degradation of motor function. Source Readme for Kinect for Windows SDK - Beta 2 release

Kinect for Windows on Social

Facebook, Twitter, Blog and Resources on Microsoft.com

Next article in the series talks about Kinect Skeleton tracking. Stay tuned...

WpfKinectQuickStarter.zip

Comments

  • Anonymous
    January 14, 2012
    Good one Sir !!
  • Anonymous
    January 15, 2012
    Really appreciate. This will encourage people to work on more on this. Quite detail explanation.