This is my first article for the year 2013, am still excited about Microsoft Kinect for windows sdk. In this article i will answer some of the questions asked to me after I published the previous article. This article will focus on the Cursor and selected and Clicking the Buttons in a Kinect application.

Objective

In this article I wanted to show you on how to use your hand a
cursor to move to certain buttons and click those buttons and respond to events
on those button.
Article based on
My daughter
is 2 years old and while I was playing around with Kinect I realized that I can
create an application that can educate her on a lot of things. The idea started
by having images of fruits and when a button is selected or clicked, I will
play an audio or mp3 saying the name of the fruit. I was not going to record
myself, so I goggled and found a nice site that did text to speech http://ctrlq.org/listen/ I converted all my text to mp3’s and the
voices are clear. Now the game will have
various buttons representing a fruit and also there is a hand that will be used
as a cursor when the First skeleton is detected or the first person is detected
on our game.
Final Output of our
Application

FINAL OUTPUT

Figure 1.1

Figure 1.2

Figure 1.3

Figure 1.4

Figure 1.5

In Figure 1.5 I have increased the width and height of the hand
because I realized that my daughter was not seeing what she was moving, after I
increased the same to the one you see in figure 1.5 she was able to see it and in
figure 1.3 and 1.4 is my daughter selected the fruits and also imitating the
voice that tells her what is the name of the fruit. After an hour of playing
the game we left the Tech Room and we went to the kitchen and I showed her all
the fruits and she was able to identify them with the names she heard from our
Kinect application. You can extend the game and include the Animals and play
animal sounds when one is selected.

In the Example project I have provided all the images I used and
also the mp3’s are included in the project. I will dissect the application code
but will not explain from the article because as usually I try to comment each
and every line in the code I will provide you.

Where do I Start

Create
a WPF application as I have explained in the previous articles.

The
First thing we need to create is the hand cursor. Create a new item selected a
“Usercontrol” and name it “HandCursor” and
the xaml should look like this

Create a class file and
name it ActionStatus.cs and its
contents should look like this

using System;
using System.Text;
namespace WpfApplication1
{
//These are the different statusses
public enum ActionStatus
{
NotStarted,
Enter, //the cursor just entered the button
Exit, //the cursor is not on the button
Completed //an Event can be fired
}
}

Create
a class file and name it ButtonExtension.cs
and its contents should look like this

Create
a class file and name it ButtonPosition.cs
and its contents should look like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication1
{
//track the Position of the button.
public class ButtonPosition
{
public double Left { get; set; }
public double Right { get; set; }
public double Top { get; set; }
public double Bottom { get; set; }
}
}

Create
a class file and name it CursorPoint.cs and
its contents should look like this

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApplication1
{
//track the position of the Cursor
public class CursorPoint
{
public double X { get; set; }
public double Y { get; set; }
}
}

Create
a class file and name it GestureButton.cs
and its contents should look like this

Reference

Conclusion

Thank you again for reading the other awesome article of Microsoft
Kinect for Windows. My next article will be about identifying players in your
application.

Thank you again for visiting DotNetFunda.com !

Happy New Year.

Vuyiswa Maseko

About the Author

Full Name: Vuyiswa MasekoMember Level: NotApplicable Member Status: Member,MVP,AdministratorMember Since: 7/6/2008 11:50:44 PMCountry: South Africa Thank you for posting at Dotnetfunda
[Administrator] http://www.Dotnetfunda.com
Vuyiswa Junius Maseko is a Founder of Vimalsoft (Pty) Ltd (http://www.vimalsoft.com/) and a forum moderator at www.DotnetFunda. Vuyiswa has been developing for 16 years now. his major strength are C# 1.1,2.0,3.0,3.5,4.0,4.5 and vb.net and sql and his interest were in asp.net, c#, Silverlight,wpf,wcf, wwf and now his interests are in Kinect for Windows,Unity 3D. He has been using .net since the beta version of it. Vuyiswa believes that Kinect and Hololen is the next generation of computing.Thanks to people like Chris Maunder (codeproject), Colin Angus Mackay (codeproject), Dave Kreskowiak (Codeproject), Sheo Narayan (.Netfunda),Rajesh Kumar(Microsoft) They have made vuyiswa what he is today.

I am getting 3 errors, I don't understand why, I have everything in references.
The only thing that is different is that I am using an Xbox360 Kinect. I will try with a windows one tomorrow

Error 1 'WpfApplication1.MainWindow' does not contain a definition for 'InfraredStreamEnabled' and no extension method 'InfraredStreamEnabled' accepting a first argument of type 'WpfApplication1.MainWindow' could be found (are you missing a using directive or an assembly reference?) C:\Users\sergiu\Google Drive\Welfare\KinectforWindowsSDKV1\Vuyiswamb_Articles_634926411267159453_WpfApplication1\WpfApplication1\WpfApplication1\MainWindow.xaml.cs 199 26 WpfApplication1

Error 2 'WpfApplication1.MainWindow' does not contain a definition for 'RedEffectsEnabled' and no extension method 'RedEffectsEnabled' accepting a first argument of type 'WpfApplication1.MainWindow' could be found (are you missing a using directive or an assembly reference?) C:\Users\sergiu\Google Drive\Welfare\KinectforWindowsSDKV1\Vuyiswamb_Articles_634926411267159453_WpfApplication1\WpfApplication1\WpfApplication1\MainWindow.xaml.cs 205 26 WpfApplication1

Error 3 'WpfApplication1.MainWindow' does not contain a definition for 'InfraredStreamEnabled' and no extension method 'InfraredStreamEnabled' accepting a first argument of type 'WpfApplication1.MainWindow' could be found (are you missing a using directive or an assembly reference?) C:\Users\sergiu\Google Drive\Welfare\KinectforWindowsSDKV1\Vuyiswamb_Articles_634926411267159453_WpfApplication1\WpfApplication1\WpfApplication1\MainWindow.xaml.cs 286 18 WpfApplication1