Click here to Skip to main content
11,428,497 members (66,472 online)
Click here to Skip to main content

Tagged as

Kinect status and setup the Kinect for interaction

, 24 Dec 2013 CPOL
Rate this:
Please Sign up or sign in to vote.
Kinect for windows status and setup the Kinect for interaction

Introduction 

The article will give you a getting started with kinect for windows sensor SDK 1.8 and how the kinect for interaction works. I am going to use the kinect sdk 1.8 and a WPF project using visual studio. 

Pre-Requisites   

  • Visual studio 2012
  • .NET 4.5
  • Kinect for windows sensor device.
  • Kinect for Windows SDK (http://go.microsoft.com/fwlink/?LinkID=323588)
  • Kinect for Windows Developer Toolkit (http://go.microsoft.com/fwlink/?LinkID=323589) 

Kinect for window sensor status

Create a WPF Application project WPFKinect18 using visual studio 2012.

Add the following references:From the C:\Program Files\Microsoft SDKs\Kinect\v1.8\Assemblies\ folder, add Microsoft.Kinect.dll.

From the C:\Program Files\Microsoft SDKs\Kinect\Developer Toolkit v1.8.0\Assemblies\ folder, add Kinect.Toolkit.dll, Kinect.Toolkit.Controls.dll and Kinect.Toolkit.Interaction.dll

Add the KinectSensorChooserUI to the MainWindow to get the Status of the Kinect sensor. Plugged, unplugged, powered.

And a label control to display the Kinect status change. 

Kinect not connected

Kinect is initializing (you can see the status by hovering on it)

Kinect Connected

Setup the Kinect for interaction

Copy these “KinectInteraction180_32.dll, KinectInteraction180_64.dll” dll’s on the output directory of your project. As shown below (you can find these dll’s in the source code of this article.)

Now change the “SensorChooserOnKinectChanged” event by the following code.

On the mainwindows.xaml

<k:kinectuserviewer k:kinectregion.kinectregion="{Binding ElementName=kinectRegion}" height="150" primaryusercolor="Violet" usercoloringmode="HighlightPrimary" horizontalalignment="Right" verticalalignment="Bottom">
</k:kinectuserviewer>

You can see the user depth image on the right bottom of the screen. User is detected in-front of Kinect but not active. The user is looking gray colored

Now the user is active and moving hand and its depth image becomes colored. And you can also see the user’s hand, both hands are track able. You can switch hand cursor control from left hand to right hand easily.

Adding the Kinect tile button inside the Kinect region

<k:kinecttilebutton click="ClickMe_Click" label="Click Me" x:name="ClickMe" />

In the MainWindow.cs page.

private void ClickMe_Click(object sender, RoutedEventArgs e)
        {
            KinectStatus.Content = "Clicked me";
        }

Hover hand on the button on the button

Taking your hand towards Kinect sensor, like pushing a button. Partial pushed button

Pressed button looks like this.

Take you hand back to fire up the click event of this button.

For scrolling area on the Kinect: grip your figures and scroll from left to right and right to left.

Using the code  

 MainWindow.xaml

<Window x:Class="WPFKinectSDK18.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:k="http://schemas.microsoft.com/kinect/2013"
        Title="MainWindow" Height="450" Width="625" Loaded="Window_Loaded" WindowState="Maximized">
    <Grid>
        <k:KinectSensorChooserUI HorizontalAlignment="Center" VerticalAlignment="Top" Name="sensorChooserUi" />
        <Label x:Name="KinectStatus" Content="Kinect status change" 
               HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="15"></Label>
        <k:KinectRegion x:Name="kinectRegion">
            <Grid>
                <k:KinectUserViewer VerticalAlignment="Bottom" HorizontalAlignment="Right" 
                UserColoringMode="HighlightPrimary" PrimaryUserColor="Violet" Height="150"
                k:KinectRegion.KinectRegion="{Binding ElementName=kinectRegion}" />
                <k:KinectTileButton x:Name="ClickMe" Label="Click Me" Click="ClickMe_Click" VerticalAlignment="Top" HorizontalAlignment="Left"></k:KinectTileButton>
                <k:KinectScrollViewer VerticalScrollBarVisibility="Disabled" HorizontalScrollBarVisibility="Auto" VerticalAlignment="Center">
                    <StackPanel Orientation="Horizontal" x:Name="StackPanelWithButton" />
                </k:KinectScrollViewer>
            </Grid>
        </k:KinectRegion>
    </Grid>
</Window> 
MainWindow.xaml.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Kinect;
using Microsoft.Kinect.Toolkit;
using Microsoft.Kinect.Toolkit.Controls;

namespace WPFKinectSDK18
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private KinectSensorChooser sensorChooser;
        public MainWindow()
        {
            InitializeComponent();
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            this.sensorChooser = new KinectSensorChooser();
            this.sensorChooser.KinectChanged += SensorChooserOnKinectChanged;
            this.sensorChooserUi.KinectSensorChooser = this.sensorChooser;
            this.sensorChooser.Start();
            GetTileButtonsForStackPanel();
        }
        private void SensorChooserOnKinectChanged(object sender, KinectChangedEventArgs args)
        {
            bool error = false;
            if (args.OldSensor != null)
            {
                try
                {
                    args.OldSensor.DepthStream.Range = DepthRange.Default;
                    args.OldSensor.SkeletonStream.EnableTrackingInNearRange = false;
                    args.OldSensor.DepthStream.Disable();
                    args.OldSensor.SkeletonStream.Disable();
                }
                catch (InvalidOperationException inEX) { error = true; }
            }

            if (args.NewSensor != null)
            {
                switch (Convert.ToString(args.NewSensor.Status))
                {
                    case "Undefined": KinectStatus.Content = "Undefined"; break;
                    case "Disconnected": KinectStatus.Content = "Disconnected"; break;
                    case "Connected": KinectStatus.Content = "Connected"; break;
                    case "Initializing": KinectStatus.Content = "Initializing"; break;
                    case "Error": KinectStatus.Content = "Error"; break;
                    case "NotPowered": KinectStatus.Content = "NotPowered"; break;
                    case "NotReady": KinectStatus.Content = "NotReady"; break;
                    case "DeviceNotGenuine": KinectStatus.Content = "DeviceNotGenuine"; break;
                    case "DeviceNotSupported": KinectStatus.Content = "DeviceNotSupported"; break;
                    case "InsufficientBandwidth": KinectStatus.Content = "InsufficientBandwidth"; break;
                    default: KinectStatus.Content = "Undefined"; break;
                }
                try
                {
                    args.NewSensor.DepthStream.Enable(DepthImageFormat.Resolution640x480Fps30);
                    args.NewSensor.SkeletonStream.Enable();
                    try
                    {
                        args.NewSensor.DepthStream.Range = DepthRange.Near;
                        args.NewSensor.SkeletonStream.EnableTrackingInNearRange = true;
                        args.NewSensor.SkeletonStream.TrackingMode = SkeletonTrackingMode.Seated;
                    }
                    catch (InvalidOperationException inEX)
                    {
                        args.NewSensor.DepthStream.Range = DepthRange.Default;
                        args.NewSensor.SkeletonStream.EnableTrackingInNearRange = false;
                        error = true;
                    }
                }
                catch (InvalidOperationException inEX) { error = true; }
            }
            if (!error) { kinectRegion.KinectSensor = args.NewSensor; }
        }

        private void ClickMe_Click(object sender, RoutedEventArgs e)
        {
            KinectStatus.Content = "Clicked me";
        }

        private void GetTileButtonsForStackPanel()
        {
            for (int i = 1; i <= 35; i++)
            {
                KinectTileButton ObjTileButton = new KinectTileButton();                
                ObjTileButton.Height = 250;
                ObjTileButton.Label = i;
                ObjTileButton.Click += (o, Args) => KinectStatus.Content = "You clicked on tile button : " + i;
                StackPanelWithButton.Children.Add(ObjTileButton);
            }
        }
    }
}

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pankaj Deharia Ignatiuz
Technical Lead Ignatiuz Software Pvt. Ltd.
India India
Working in the projects by using technologies (.Net, C#, MSSQL, Web, Desktop, Kinect based Natural user inter-phase development, dynamic CRM.)
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
GeneralTrying to see if it works on xbox360 kinect with PC adapter Pin
Victor Ng15-Feb-15 23:11
memberVictor Ng15-Feb-15 23:11 
QuestionThanks for your tut. Pin
Member 105060959-Apr-14 0:23
memberMember 105060959-Apr-14 0:23 
AnswerRe: Thanks for your tut. Pin
Pankaj Deharia9-Apr-14 0:58
memberPankaj Deharia9-Apr-14 0:58 
QuestionWhere to buy Kinect for Windows in India Pin
ramatbellcity10-Mar-14 21:42
memberramatbellcity10-Mar-14 21:42 
AnswerRe: Where to buy Kinect for Windows in India Pin
Pankaj Deharia Ignatiuz28-Mar-14 4:56
professionalPankaj Deharia Ignatiuz28-Mar-14 4:56 
QuestionProblem making it run Pin
N. Henrik Lauridsen6-Mar-14 2:40
memberN. Henrik Lauridsen6-Mar-14 2:40 
AnswerRe: Problem making it run Pin
Pankaj Deharia Ignatiuz28-Mar-14 4:43
professionalPankaj Deharia Ignatiuz28-Mar-14 4:43 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 24 Dec 2013
Article Copyright 2013 by Pankaj Deharia Ignatiuz
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid