Kinect for Windows SDK Programming Guide - Abhijit Jana - E-Book

Kinect for Windows SDK Programming Guide E-Book

Abhijit Jana

0,0
34,79 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

Kinect has been a game-changer in the world of motion games and applications since its first release. It has been touted as a controller for Microsoft Xbox but is much more than that. The developer version of Kinect, Kinect for Windows SDK, provides developers with the tools to develop applications that run on Windows. You can use this to develop applications that make interaction with your computer hands-free. This book focuses on developing applications using the Kinect for Windows SDK. It is a complete end to end solution using different features of Kinect for Windows SDK with step by step guidance. The book will also help you develop motion sensitive and speech recognition enabled applications. You will also learn about building application using multiple Kinects.The book begins with explaining the different components of Kinect and then moves into to the setting up the device and getting thedevelopment environment ready. You will be surprised at how quickly the book takes you through the details of Kinect APIs. You will use NUI to use the Kinect for Natural Inputs like skeleton tracking, sensing, speech recognizing. You will capture different types of stream, and images, handle stream event, and capture frame. Kinect device contains a motorized tilt to control sensor angles, you will learn how to adjust it automatically. The last part of the book teaches you how to build application using multiple Kinects and discuss how Kinect can be used to integrate with other devices such as Windows Phone and microcontroller.

Das E-Book können Sie in Legimi-Apps oder einer beliebigen App lesen, die das folgende Format unterstützen:

EPUB
MOBI

Seitenzahl: 420

Veröffentlichungsjahr: 2012

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Kinect for Windows SDK Programming Guide
Credits
About the Author
Acknowledgement
About the Reviewers
www.PacktPub.com
Support files, eBooks, discount offers and more
Why Subscribe?
Free Access for Packt account holders
Instant Updates on New Packt Books
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Understanding the Kinect Device
Components of Kinect for Windows
Inside the Kinect sensor
The color camera
IR emitter and IR depth sensor
How depth data processing works
Tilt motor
Microphone array
LED
Kinect for Windows versus Kinect for Xbox
Where can you use Kinect
Summary
2. Getting Started
System requirements for the Kinect for Windows SDK
Supported operating systems
System configuration
The Kinect sensor
The Kinect for Windows sensor
The Kinect for Xbox sensor
Development tools and software
Evaluation of the Kinect for Windows SDK
Downloading the SDK and the Developer Toolkit
Installing Kinect for Windows SDK
Installing the Developer Toolkit
Components installed by the SDK and the Developer Toolkit
Kinect management service
Connecting the sensor with the system
Verifying the installed drivers
Not able to view all the device components
Detecting the loaded drivers in Device Manager
Testing your device
Testing Kinect sensors
Testing the Kinect microphone array
Looking inside the Kinect SDK
Features of the Kinect for Windows SDK
Capturing the color image data stream
Processing the depth image data stream
Near Mode
Capturing the infrared stream
Tracking human skeleton and joint movements
Capturing the audio stream
Speech recognition
Human gesture recognition
Tilting the Kinect sensor
Getting data from the accelerometer of the sensor
Controlling the infrared emitter
The Kinect for Windows Developer Toolkit
The Face Tracking SDK
Kinect Studio
Making your development setup ready
The Coding4Fun Kinect Toolkit
Summary
3. Starting to Build Kinect Applications
How applications interact with the Kinect sensor
Understanding the classification of SDK APIs
Kinect Info Box – your first Kinect application
Creating a new Visual Studio project
Adding the Kinect libraries
Getting the Kinect sensor
The Kinect sensor
Defining the Kinect sensor
The collection of sensors
Starting up Kinect
Inside the sensor.Start() method
Enabling the data streams
Identifying the Kinect sensor
Initializing the sensor using device connection ID
Stopping the Kinect sensor
The Stop() method does the clean-up operation
Displaying information in the Kinect Info Box
Designing the Info Box UI
Binding the data
A quick look at INotifyPropertyChanged
Using INotifyPropertyChanged for data binding
Setting the DataContext
Setting up the information
That's all!
Dealing with the Kinect status
Monitoring the change in sensor status
Properties of the StatusChangedEventArgs class
Resuming your application automatically
Building KinectStatusNotifier
Setting up an application
How it works
Using KinectStatusNotifier
Test it out
Summary
4. Getting the Most out of Kinect Camera
Understanding the Kinect image stream
Types of color images
Different ways of retrieving the color stream from Kinect
Event model
Polling model
KinectCam – a Kinect camera application
Setting up the project
Designing the application – XAML and data binding
Capturing color image from the Kinect camera
Enabling the color stream channel
Enabling a channel with the image format
Choosing the image format
Disabling the color stream channel
Attaching the event handler
Processing the incoming image frames
Rendering image frames on the UI
Running the KinectCam
Looking inside color image stream helpers
The ColorImageStream class
The ColorImageFrame class
Capturing frames on demand
Extending the KinectCam
Getting the frame number
Changing image format on the fly
Bind available image formats
Changing the color image format
Calculating frame rate
How to calculate frame rate
Capturing and saving images
Saving images periodically
Trying to save image frames directly
Changing the sensor elevation angle
Maximum and minimum elevation angles
Adjusting the Kinect sensor angle
Playing around the color pixels
Applying RGB effects
Making grayscale effects
Inverting the color
Applying more effects to the camera
Applying the backlight compensation mode
Applying slow motion effects
Kinect Camera Effects – application
Seeing in low light
Making your application perform better
Using the Coding4Fun toolkit
Installing the Coding4Fun Kinect toolkit
Using assembly
Using the NuGet package
Using Coding4Fun Kinect libraries in your application
Summary
5. The Depth Data – Making Things Happen
Understanding the depth data stream
Depth data – behind the scenes
Stereo triangulation
Capturing and processing depth data
Enabling the depth stream channel
Attaching the event handler
Processing the depth frames
Depth data at first look
Looking inside depth image stream helpers
Depth data and distance
How the distance is calculated
Getting the distance from a particular pixel
Accessing the range of distance
Colorize depth data processing
Working with depth range
Special depth range values
Depth data distribution
Player index with depth data
How player index works
Identifying players
Getting the depth and player index automatically
A 3D view of depth data
The basics of the coordinate system
Basic elements of 3D graphics
Setting up the project
Give it a 3D effect
Creating the ViewPort
Using the camera
Controlling the camera position
Creating the 3D Model
Building the mesh object
Setting up the initial data points
Getting the depth data from Kinect
Have a look at 3D depth
Summary
6. Human Skeleton Tracking
How skeleton tracking works
Steps to remember
Skeleton tracking with the Kinect SDK
Start tracking skeleton joints
Tracking the right hand
Setting up the project
Creating a joint placeholder
Get Kinect running and instantiate skeleton tracking
Enabling and disabling the skeleton stream
Processing the skeleton frames
Mapping the skeleton joints with UI elements
Running the application
Adding more fun
Flow – capturing skeleton data
An intrusion detector camera application
Adding night vision
Looking inside skeleton stream helpers
The skeleton frame
The skeleton stream
Skeleton-tracking mode
Default skeleton tracking
Seated skeleton tracking
Using seated-skeleton tracking
Points to be considered with seated-skeleton tracking
Skeleton tracking in near mode
The Skeleton
Skeleton-tracking state
Counting the number of tracked skeletons
Choosing which skeleton to track
Skeleton-tracking ID
Monitoring changes in the skeleton
Limiting tracking for the intrusion-detector camera
The building blocks – Joints and JointCollection
Joint-tracking state
Steps to be followed for joint tracking
Create your own joints data point
Bones – connecting joints
Bone sequence
Bone sequence for a default skeleton
Bone sequence for a seated skeleton
Drawing bones between joints
Adjusting the Kinect sensor automatically and giving live feedback to users
Skeleton smoothing – soften the skeleton's movement
What causes skeleton jitters
Making skeleton movement softer
Smoothing parameters
How to check if skeleton smoothing is enabled
Exponential smoothing
Skeleton space transformation
The Advanced Skeleton Viewer application
Debugging the applications
Using conditional breakpoints
Using Kinect Studio
Getting data frames together
Summary
7. Using Kinect's Microphone Array
Verifying the Kinect audio configuration
Troubleshooting: Kinect USB Audio not recognizing
Using the Kinect microphone array with your computer
The Kinect SDK architecture for Audio
Kinect microphone array
The major focus area of Kinect audio
Why microphone array
Audio signal processing in Kinect
Taking control over the microphone array
Kinect audio stream
Starting and stopping the Kinect audio stream
Starting audio streaming after a time interval
Kinect sound recorder – capturing Kinect audio data
Setting up the project
Designing the application – XAML and data binding
Recording the Kinect audio
Starting the recording
Playing the recorded audio
Running the Kinect Sound Recorder
Processing the audio data
Echo cancellation
Noise suppression
Automatic gain control
Audio data processing with the Kinect sound recorder
Sound source localization
Sound source angle
Confidence level
Beamforming
Beam angle mode
Extending the Kinect Sound Recorder with sound source localization
Summary
8. Speech Recognition
How speech recognition works
Using Kinect with your Windows PC speech recognition
Beginning with Microsoft Speech API (SAPI)
Steps for building speech-enabled applications
Basic speech-recognition approach
Building grammar
Using Choice and GrammarBuilder
Appending new grammars
Building grammar using XML
Creating grammar from GrammarBuilder
Loading grammar into a recognizer
Unloading grammars
Draw What I Want – a speech-enabled application
Setting up the project
Designing the application – XAML and data binding
Data binding
Instantiating speech recognizer
Working with the speech recognition engine
Configuring Kinect audio
Creating grammar
Start the speech recognizer
Drawing an object when speech is recognized
Testing your application
Summary
9. Building Gesture-controlled Applications
What is a gesture
Approaches for gesture recognition
Basic gesture recognition
Gesture-detection technique
Representing skeleton joints
Calculating the distance between two joints
Building a clapping-hands application
Setting up the project
Implementing the gesture recognizer
Defining the types of gestures
Defining the types of recognition results
Creating the event argument for the gesture
Wrapping up everything with the gesture recognition engine
Plugging gestures into the application
Testing your application
A virtual rope workout application
Hands-raised-above-head gesture recognition
Steps to recognize basic gestures
Algorithmic gesture recognition
Which gestures can be considered as algorithmic
Understanding the algorithmic gesture detection approach
Implementing an algorithmic gesture
Adding gesture types
Extending the Event argument
Adding a GestureHelper class
Defining the GestureBase class
Implementing the SwipeToLeftGesture class
Adding the ZoomIn, ZoomOut, and SwipeToRight gesture classes
Implementing the GestureRecognitionEngine class
Using the GestureRecognitionEngine class
A demo application
Making it more flexible
Weighted network gesture recognition
What is a neural network
Gesture recognition with neural networks
Jump tracking with a neural network – an example
Template-based gesture recognition
Building gesture-enabled controls
Making a hand cursor
Getting the hand-cursor point
Identifying the objects
Enabling action for the objects
The Basic Interaction – a WPF application
Key things to remember
Summary
10. Developing Applications Using Multiple Kinects
Setting up the environment for multiple Kinects
Plugging the first Kinect sensor
Plugging the second Kinect sensor
Kinect sensors require an individual USB Controller
Multiple Kinects – how to reduce interference
Detecting multiple Kinects
Getting access to the individual sensor
Different ways to get a Kinect sensor's reference
Developing an application with multiple Kinects
Setting up the project
Designing the UI
Creating the KinectInfoCollection
Getting information from Kinects
Running the application
Controlling multiple sensor status changes
Extending Multiple Kinect Viewer with status change
Registering and handling the status change
Running the application
Identifying the devices automatically
Integrating with KinectStatusNotifier
Capturing data using multiple Kinects
Handling a failover scenario using Kinects
Challenges faced in developing applications using multiple Kinects
Applications where multiple Kinects can be used
Summary
11. Putting Things Together
Taking Kinect to the Cloud
Required components
Windows Azure
The Windows Azure SDK
The Kinect for Windows SDK
Designing the solution
Real-time implementations
Remotely using the Kinect with Windows Phone
Required components
The Windows Azure Service Bus
The Windows Phone SDK
Designing the solution
Real-time implementations
Using Kinect with a Netduino microcontroller
Required components
Microsoft .Net Micro Framework
Netduino
The Netduino SDK
Blinking of the on-board LED
Changing the Deployment Transport
Running the application
Connecting Kinect to a Netduino
Using an Internet connection
Listening to the request
Sending a request from a Kinect application
Taking it further
Augmented reality applications
Working with face tracking
Working with XNA and a 3D avatar
Summary
Index

Kinect for Windows SDK Programming Guide

Kinect for Windows SDK Programming Guide

Copyright © 2012 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, nor Packt Publishing, and its dealers and distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all of the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: December 2012

Production Reference: 1191212

Published by Packt Publishing Ltd.

Livery Place

35 Livery Street

Birmingham B3 2PB, UK.

ISBN 978-1-84969-238-0

www.packtpub.com

Cover Image by Sandeep Babu (<[email protected]>)

Credits

Author

Abhijit Jana

Reviewers

Atul Gupta

Anoop Madhusudhanan

Atul Verma

Acquisition Editor

James Keane

Lead Technical Editor

Susmita Panda

Technical Editors

Prasanna Joglekar

Dipesh Panchal

Farhaan Shaikh

Nitee Shetty

Copy Editors

Brandt D'Mello

Insiya Morbiwala

Aditya Nair

Alfida Paiva

Project Coordinator

Yashodhan Dere

Proofreaders

Ting Baker

Matthew Humphries

Indexer

Rekha Nair

Graphics

Valentina D'silva

Aditi Gajjar

Production Coordinator

Nitesh Thakur

Cover Work

Nitesh Thakur

About the Author

Abhijit Jana works at Microsoft as a .NET Consultant, as part of Microsoft Services Global Delivery, India. As a consultant, his job is to help customers design, develop, and deploy enterprise-level secure solutions using Microsoft Technology. Apart from being a former Microsoft MVP, he is a speaker and author as well as an avid technology evangelist. He has delivered sessions at prestigious Microsoft events such as TechEd, Web Camps, Azure Camps, Community Tech Days, Virtual Tech Days, DevDays, and developer conferences. He loves to work with different .NET communities and help them with different opportunities. He is a well-known author and has published many articles on different .NET community sites.

He shares his thoughts on his personal blog at http://abhijitjana.net. You can follow him on Twitter at @abhijitjana. Abhijit lives in Hyderabad, India, with his wife, Ananya and a beautiful little angel Nilova.

Note

Disclaimer

The opinions in this book are purely my personal opinions and do not reflect in any way the opinions of my employers.

Acknowledgement

Writing this book would not have been possible without the help of many people. I had a wonderful time while writing, which was mainly due to the skills, support, dedication, and motivation of the people around me.

First of all I am extremely thankful to Sachin Joshi, Pinal Dave, and Prasant Kraleti for the continuous support and motivation they gave me from the time I started writing this book. They have been awesome with their support at every stage of writing.

I am deeply thankful to the entire team at Packt Publishing, including Prasad, Susmita, Mayur, Prasanna, Dipesh, Farhaan, and Nitee. I would like to extend my thanks to the Project Coordinator, Yashodhan, for his support from the beginning. Thank you all for your effort and dedication.

A sincere thanks to Atul Gupta and Anoop Madhusudanan for their insightful and excellent technical review. They helped me to identify and fill the gaps and improve the overall quality of this book.

I would like to acknowledge the efforts of Atul Verma for his extended support for in-depth technical review, and also for his time in discussing, peer coding, and providing feedback on many topics.

I would like to thank Jebarson Jebamony for his excellent peer review for this book, and also for spending his time and effort in sharing his thoughts and feedback for improving the content. He also helped me to organize content and design many demo applications.

I would like to thank Arka Bhattacharya and Atul Sharma for their offline review of the book and for sharing their feedback. A big thank you to Rajesh R. Nair for helping me on designing sketches and icons, and also Rishabh Verma for capturing and sharing the dismantled sensor images with me.

My sincere thanks to Jag Dua and Sanjoyan Mitra, two true leaders I have worked with. I would like to extend my thanks to Jag for giving me his Kinect sensor when I was overseas and was urgently looking for a Kinect sensor for some experimentation.

I was fortunate enough to be present at many seminars and conferences over the past year, on Kinect. This helped me to interact with many developers and students who are really passionate about programming with Kinect. Thanks to each one of them for spending their time with me and discussing about their problems and questions.

A big thanks to the Kinect for Windows team, the Kinect for Windows Community, and my Community friends, and MSPs who helped me in writing this book. I would like to thank my friends Kunal Chowdhury, Abhishek Sur, Dhananjay Kumar, Suresh Bemagani, Sheo Narayan, and Sharavan Kasagoni for their continuous support and help while writing this book. I am also thankful to the bloggers on the various Kinect topics, and also the researchers who have been working and experimenting day in and day out with Kinect. On many occasions I have been reading their posts and referring to them.

I spent time in writing when I should have been sleeping, spending time with family, or playing with my newborn child. I'd never have been able to write this book without the support of my wife, Ananya. I cannot even express her love and support while I was writing this book. Thank you Ananya.

Being a Community lover and an active blogger, I have been writing blogs for the last couple of years; but this is the first time I am putting something in the form of a book. The credit goes to each one of you who has been connected with me and have been my blog reader and supporter.

I would really appreciate it if you would contact me at <[email protected]> for any kind of clarification.

About the Reviewers

Atul Gupta is currently a Principal Technology Architect at Infosys' Microsoft Technology Center, Infosys Labs. With more than 16 years of experience working on Microsoft technologies, his expertise spans User Interface technologies, and he currently works on touch and gestural interfaces with technologies such as Windows 8 and Kinect. He has prior experience on Windows Presentation Foundation (WPF), Silverlight, Windows 7, Deepzoom, Pivot, PixelSense, and Windows Phone 7.

He has co-authored the book ASP.NET 4 Social Networking, Packt Publishing. Earlier in his career, he has also worked on technologies such as COM, DCOM, C, VC++, ADO.NET, ASP.NET, AJAX, and ASP.NET MVC. He is a regular reviewer for Packt Publishing and has reviewed books on topics such as Silverlight and Generics.

He has authored papers for industry publications and websites, some of which are available on Infosys' Technology Showcase (http://www.infosys.com/microsoft/resource-center/pages/technology-showcase.aspx). Along with his colleagues from Infosys, he is also an active blogger (http://www.infosysblogs.com/microsoft). Being actively involved in professional Microsoft online communities and developer forums, he has received Microsoft's Most Valuable Professional award for multiple years in a row.

Anoop Madhusudanan has been a Microsoft MVP in C# for the last 3 years and has more than 10 years of experience with Microsoft technologies. Presently, he is working as a Solution Architect with the Cloud & Mobile Center of Excellence, Marlabs Inc. He works across multiple Microsoft technologies and platforms including Windows 8, ASP.NET, Windows Azure, and so on, across domains including education, healthcare, and telecom.

He blogs at http://amazedsaint.com and is the developer of various open source frameworks such as BrainNet Neural Network Library, ElasticObject, SilverDraw, MetaCoder, and so on. He is also an active contributor to CodeProject. His Twitter handle is @amazedsaint.

Atul Verma is a Technical Consultant at Microsoft Services Global Delivery and is a graduate from NIT, Hamirpur. He has been developing enterprise-level secure and scalable solutions using agile software methodologies for the past seven years. His technical expertise includes WPF, ASP.NET, WCF, SharePoint, Dynamics CRM, and Kinect for Windows. Apart from this, he also contributes to technical communities, technical seminars, open source projects, and blogs. He is currently studying the essence of Indian culture and loves to spend quality time with his family. You can follow him on Twitter at @verma_atul.

www.PacktPub.com

Support files, eBooks, discount offers and more

You might want to visit www.PacktPub.com for support files and downloads related to your book.

Did you know that Packt offers eBook versions of every book published, with PDF and ePub files available? You can upgrade to the eBook version at www.PacktPub.com and as a print book customer, you are entitled to a discount on the eBook copy. Get in touch with us at <[email protected]> for more details.

At www.PacktPub.com, you can also read a collection of free technical articles, sign up for a range of free newsletters and receive exclusive discounts and offers on Packt books and eBooks.

http://PacktLib.PacktPub.com

Do you need instant solutions to your IT questions? PacktLib is Packt's online digital book library. Here, you can access, read and search across Packt's entire library of books.

Why Subscribe?

Fully searchable across every book published by PacktCopy and paste, print and bookmark contentOn demand and accessible via web browser

Free Access for Packt account holders

If you have an account with Packt at www.PacktPub.com, you can use this to access PacktLib today and view nine entirely free books. Simply use your login credentials for immediate access.

Instant Updates on New Packt Books

Get notified! Find out when new books are published by following @PacktEnterprise on Twitter, or the Packt Enterprise Facebook page.

I dedicate this book to my parents, my lovely wife Ananya and my little angel Nilova.

Preface

Ever since its inception, Kinect has brought about a revolution in the field of NUI and hands-free gaming. There is no wonder that Kinect went on to shatter all records and become the fastest selling electronic device on earth. Although touted as a controller for Xbox console, Kinect applicability is beyond gaming domain and you can think of building applications for diverse domains such as health care, robotics, imaging, education, security, and so on. Thus we have the Kinect for Windows sensor, that enables applications to interacts with users via gestures and voice, and this opens up avenues that developers couldn't even have imagined before.

This book is mainly focussed on the Kinect for Windows SDK with which you can build applications that can leverage the power of the Kinect sensor. This book doesn't require any prior knowledge about the platform from the reader and its strength is the simplicity in which the concepts have been presented using code snippets, a step-by-step process, and detailed descriptions. This book covers:

A practical step-by-step tutorial to make learning easy for a beginnerA detailed discussion of all the APIs involved and the explanations of their usage in detailProcedures for developing motion-sensing applications and also methods used to enable speech recognition

What this book covers

Chapter 1, Understanding the Kinect Device, introduces Kinect as a hardware device. You will get an insight into the different components that make up Kinect and the technology behind this device, which makes the components work together. This chapter will also give an overview of the difference between Kinect for Xbox and Kinect for Windows sensor. You will also become familiar with different possibilities of domain specific applications that can be developed using the Kinect sensor.

Chapter 2, Getting Started, introduces the Kinect for Windows SDK, its features, and how to start working with the Kinect sensor. In this chapter, you will get to know about the requirements for preparing your development environment. This will also walk you through a step-by-step guide for downloading and installing the SDK. You will delve into the installed components to verify that everything is set up properly. This chapter will also provide you with a quick lap around the different features of the Kinect for Windows SDK as well as introduce the Kinect for Windows Developer Toolkit.

Chapter 3, Starting to Build Kinect Applications, explains the step-by-step process of building your first Kinect-based application. You will understand how applications interact with the Kinect sensor using the SDK libraries. This chapter will give you an in-depth guide on how to start building Kinect applications using the Kinect for Windows SDK and Visual Studio. You will also learn how to deal with applications when there is any change in the device status.

Chapter 4, Getting the Most Out of Kinect Camera, covers the in-depth discussion of the Kinect color camera and how to use it. In this chapter, you will learn about the different types of image streams and different approaches to retrieve them from the Kinect sensor. You will get an understanding of Color camera stream pipeline and its events. You will also explore the different features of the Kinect for Windows SDK that control the color camera and process the color data. This chapter will give you an understanding of processing color images and applying different effects to the captured images and how to save the image frames. You will also learn how you can use the Kinect camera to capture images in low light.

Chapter 5, The Depth Data – Making Things Happen, explores the fundamentals of the Kinect depth sensors and how they produce depth information. This chapter describes how to work with object distances and player indices from the captured depth data. You will also learn about the capturing of data using the near mode and also get a quick view of generating 3D depth data.

Chapter 6, Human Skeleton Tracking, describes how a Kinect sensor tracks the human skeleton and how you can leverage the features of the Kinect for Windows SDK to play around with tracked skeletons and joints. You will also learn how to change the sensor elevation angle based on the player position. This chapter also explores how skeletons can be tracked in a seated mode. You also learn about details of the skeleton joints and bone hierarchy. The sample application in this chapter will help you to understand the APIs for skeleton tracking in better ways such as using Kinect as an intrusion detector. At the end of this chapter, you will be familiar with a few debugging tips and tricks to boost your development speed.

Chapter 7, Using Kinect's Microphone Array, introduces the microphone array that captures and processes the audio signal. You will learn why Kinect uses an array of microphones rather than a single microphone. In this chapter you will get an insight into the Kinect audio processing pipeline that helps Kinect to capture good-quality audio signals and makes Kinect a highly directional audio device. This chapter provides you with information on how to capture and record audio signals using the Kinect microphone array and process the audio data for better quality. You will also learn about different concepts such as Noise Suppression, Automatic Gain Control, Echo Cancellation, and Beam forming.

Chapter 8, Speech Recognition, introduces the building of speech-enabled applications using Kinect. You will explore how speech recognition works and how Kinect's microphone array helps Kinect to recognize human speech. This chapter also shows how you can use Kinect as the default speech recognition device for your PC. You will also learn about the Microsoft Speech API and how it is integrated with Kinect for Windows SDK, which helps us to build speech-enabled applications.

Chapter 9, Building Gesture-controlled Applications, describes how to build applications that can be controlled by human gestures. You will learn different approaches for recognizing gestures and how to apply these approaches in the form of programs to build motion-sensing applications using the Kinect sensor. This chapter will also help you understand how to build some gestured-enabled controls.

Chapter 10, Developing Applications Using Multiple Kinects, explains how multiple Kinect sensors can be placed together and used to build applications. This chapter describes how to set up environments for developing applications using multiple Kinects and walks you through building applications by reading data from multiple devices. You also learn how multiple Kinects work together and different scenarios where multiple Kinects can be used, along with the challenges while developing applications using multiple devices.

Chapter 11, Putting Things Together, introduces us to more advanced developments using Kinect by integrating it with other devices such as Windows Phone, microcontrollers, and so on. This chapter addresses how we can take things up from Kinect to Windows Azure and control the Kinect sensor using Windows Phone via Windows Azure. You will also learn how Kinect can be integrated with the Netduino microcontroller and how you can use a Kinect device for face tracking.

What you need for this book

The basic requirements for this book are as follows:

Microsoft Visual Studio 2010 Express or higher editions of Visual StudioMicrosoft .NET Framework 4.0 or higherKinect for Windows Sensor or Kinect for Xbox SensorKinect for Windows SDK

Please refer Chapter 02, Getting Started , for detailed information on installation of SDK and the development environment setup.

Who this book is for

The purpose of this book is to explain how to develop applications using the Kinect for Windows SDK. If you are a beginner and looking to start developing applications using the Kinect for Windows SDK, and if you want to build motion-sensing, speech-recognizing applications with Kinect, this book is for you.

This book uses C# and WPF (Windows Presentation Foundation) in the examples, so you need to know the basics of C# and WPF. You should be familiar with the Visual Studio IDE as well. You don't have to know anything about the Kinect for Windows SDK.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "Each Kinect device represents an instance of the Microsoft.Kinect.KinectSensor class."

A block of code is set as follows:

public sealed class KinectSensorCollection : ReadOnlyCollection<KinectSensor> { public KinectSensor this[string instanceId] { get; } public event EventHandler<StatusChangedEventArgs> StatusChanged; }

When we wish to draw your attention to a particular part of a code block, the relevant lines or items are set in bold:

public partial class MainWindow : Window { KinectSensor sensor; // remaining code goes here }

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "Move to the Listen tab and select the Listen to this device checkbox and click on Apply".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book—what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Downloading the example code

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books—maybe a mistake in the text or the code—we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the errata submission form link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. Understanding the Kinect Device

Welcome to the world of motion computing with Kinect. Kinect was originally known by the code name "Project Natal". It is a motion-sensing device which was originally developed for the Xbox 360 gaming console. One of the distinguishing factors that makes this device stand out among others in this genre is that it is not a hand-controlled device, but rather detects your body position, motion, and voice. Kinect provides a Natural User Interface (NUI) for interaction using body motion and gesture as well as spoken commands. Although this concept seems straight out of a fairytale, it is very much a reality now. The controller that was once the heart of a gaming device finds itself redundant in this Kinect age. You must be wondering where its replacement is. The answer, my friend, is YOU. It's you who is the replacement for the controller, and from now on, you are the controller for your Xbox. Kinect has ushered a new revolution in the gaming world, and it has completely changed the perception of a gaming device. Since its inception it has gone on to shatter several records in the gaming hardware domain. No wonder Kinect holds the Guinness World Record for being the "fastest selling consumer electronics device". One of the key selling points of the Kinect was the idea of "hands-free control", which caught the attention of gamers and tech enthusiasts alike and catapulted the device into instant stardom. This tremendous success has caused the Kinect to shatter all boundaries and venture out as an independent and standalone, gesture-controlled device.

It has now outgrown its Xbox roots and the Kinect sensor is no longer limited to only gaming. Kinect for Windows is a specially designed PC-centric sensor that helps developers to write their own code and develop real-life applications with human gestures and body motions. With the launch of the PC-centric Kinect for Windows devices, interest in motion-sensing software development has scaled a new peak.

As Kinect blazed through the market in such a short span of time, it has also created a necessity of resources that help people learn the technology in an appropriate way. As Kinect is still a relatively new entry into the market, the resources for learning how to develop applications for this device are scant. So how does a developer understand the basics of Kinect right from scratch? Here comes the utility of this book.

This book assumes that you have basic knowledge of C# and a great enthusiasm to program for Kinect devices. This book can be enjoyed by anybody interested in knowing more about the device and learning how to interact with devices using Kinect for Windows Software Development Kit (SDK). This book will also help you explore how to process video depth and audio stream, and build applications that interact with human body motion. The book has deliberately been kept simple and concise, which will aid in the quick grasping of the concepts.

Before delving into the development process, we need a good understanding of the device and, moreover, what the different types of applications are, which we can develop using these devices. In order to develop standard applications using the Kinect for Windows SDK, it is really important for us to understand the components it interacts with.

In this chapter we will cover the following topics:

Identifying the critical components that make up KinectLooking into the functionalities of each of the componentsLearning how they interact with each otherChoosing between Kinect for Windows and Kinect for XboxExploring different application areas where we can use Kinect

Components of Kinect for Windows

Kinect is a horizontal device with depth sensors, color camera, and a set of microphones with everything secured inside a small, flat box. The flat box is attached to a small motor working as the base that enables the device to be tilted in a horizontal direction. The Kinect sensor includes the following key components:

Color cameraInfrared (IR) emitterIR depth sensorTilt motorMicrophone arrayLED

Apart from the previously mentioned components, the Kinect device also has a power adapter for external power supply and a USB adapter to connect with a computer. The following figure shows the different components of a Kinect sensor:

Inside the Kinect sensor

From the outside, the Kinect sensor appears to be a plastic case with three cameras visible, but it has very sophisticated components, circuits, and algorithms embedded. If you remove the black plastic cover from the Kinect device, what will you see? The hardware components that make the Kinect sensor work.

The following image shows a front view of a Kinect sensor that's been unwrapped from its black case. Take a look (from left to right) at its IR emitter, color camera, and IR depth sensor:

Let's move further and discuss about component.

The color camera

This color camera is responsible for capturing and streaming the color video data. Its function is to detect the red, blue, and green colors from the source. The stream of data returned by the camera is a succession of still image frames. The Kinect color stream supports a speed of 30 frames per second (FPS) at a resolution of 640 x 480 pixels, and a maximum resolution of 1280 x 960 pixels at up to 12 FPS. The value of frames per second can vary depending on the resolution used for the image frame.

The viewable range for the Kinect cameras is 43 degrees vertical by 57 degrees horizontal. The following figure shows an illustration of the viewable range of the Kinect camera:

The following image shows a color image that was captured using Kinect color sensors with a resolution of 640 x 480 pixels:

IR emitter and IR depth sensor

Kinect depth sensors consist of an IR emitter and an IR depth sensor. Both of them work together to make things happen. The IR emitter may look like a camera from the outside, but it's an IR projector that constantly emits infrared light in a "pseudo-random dot" pattern over everything in front of it. These dots are normally invisible to us, but it is possible to capture their depth information using an IR depth sensor. The dotted light reflects off different objects, and the IR depth sensor reads them from the objects and converts them into depth information by measuring the distance between the sensor and the object from where the IR dot was read. The following figure shows how the overall depth sensing looks:

Note

It is quite fun and entertaining to know that these infrared dots can be seen by you. All we need is a night vision camera or goggles.

The depth data stream supports a resolution of 640 x 480 pixels, 320 x 240 pixels, and 80 x 60 pixels, and the sensor viewable range remains the same as the color camera.

The following image shows depth images that are captured from the depth image stream:

How depth data processing works

The Kinect sensor has the ability to capture a raw, 3D view of the objects in front of it, regardless of the lighting conditions of the room. It uses an infrared (IR) emitter and an IR depth sensor that is a monochrome CMOS (Complimentary Metal-Oxide-Semiconductor) sensor. The backbone behind this technology is from PrimeSense, and the following diagram shows how this works:

The sequence explained in the diagram is as follows:

When there is a need to capture depth data, the PrimeSense chip sends a signal to the infrared emitter to turn on the infrared light (1), and sends another signal to the IR depth sensor to initiate depth data capture from the current viewable range of the sensor (2). The IR emitter meanwhile starts sending an infrared light invisible to human eyes (3) to the objects in front of the device. The IR depth sensor starts reading the inferred data from the object based on the distance of the individual light points of reflection (4) and passes it to the PrimeSense chip (5). The PrimeSense chip then analyzes the captured data, and creates a per-frame depth image and passes it to the output depth stream as a depth image (6).

Note

The IR emitter emits an electromagnetic radiation. The wavelengths of the radiations are longer than the wavelength of the visible light, which makes the sensor's IR lights invisible. The wavelengths need to be consistent to minimize the noise within the captured data. Heat generated by the laser diode when the Kinect sensor is running can impact the wavelength. The Kinect sensor has a small, inbuilt fan to normalize the temperature and ensure that the wavelengths are consistent.

Tilt motor

The base and body part of the sensor are connected by a tiny motor. It is used to change the camera and sensor's angles, to get the correct position of the human skeleton within the room. The following image shows the motor along with three gears that enable the sensor to tilt at a specified range of angles:

The motor can be tilted vertically up to 27 degrees, which means that the Kinect sensor's angles can be shifted upwards or downwards by 27 degrees. The following figure shows an illustration of the angle being changed when the motor is tilted:

Note

Do not physically force the device into a specific angle. The Kinect for Windows SDK has a few specific APIs that can help us control the sensor's motor tilting. Do not tilt the Kinect motor frequently; use this as few times as possible and only when it's required.

Microphone array

The Kinect device exhibits great support for audio with the help of a microphone array. The microphone array consists of four different microphones that are placed in a linear order (three of them are spread on the right side and the other one is placed on the left side, as shown in the following image) at the bottom of the Kinect sensor:

The purpose of the microphone array is not just to let the Kinect device capture the sound but to also locate the direction of the audio wave. The main advantages of having an array of microphones over a single microphone are that capturing and recognizing the voice is done more effectively with enhanced noise suppression, echo cancellation, and beam-forming technology. This enables Kinect to be a highly bidirectional microphone that can identify the source of the sound and recognize the voice irrespective of the noise and echo present in the environment:

LED

An LED is placed in between the camera and the IR projector. It is used for indicating the status of the Kinect device. The green color of the LED indicates that the Kinect device drivers have loaded properly. If you are plugging Kinect into a computer, the LED will start with a green light once your system detects the device; however for full functionality of your device, you need to plug the device into an external power source.

Kinect for Windows versus Kinect for Xbox

Although "Kinect for Windows" and "Kinect for Xbox" are similar in many respects, there are several subtle differences from a developer's point of view. We have to keep in mind that the main purpose of Kinect for Xbox was to enhance the gaming experience of the players. Developing applications was not its primary purpose. In contrast, Kinect for Windows is primarily a developing device and not for gaming purposes.

You can develop applications that use either the Kinect for Windows sensor or the Kinect for Xbox sensor. The Kinect for Xbox sensor was built to track players that are up to 12 feet (4.0 meters) away from the sensor. But it fails to track objects that are very close (80 cm), and we might need to track objects at a very close range for different applications. The Kinect for Windows sensor has new firmware, which enables Near Mode tracking. Using Near Mode, Kinect for Windows supports the tracking of objects as close as 40 cm in front of the device without losing accuracy or precision. In terms of range both the sensors behave the same.

Note

Kinect for Windows SDK exposes APIs that can control the mode of the sensors (Near Mode or Default Mode) using our application, however the core changes for this feature are built within the firmware of the Kinect for Windows sensor.

Both the Kinect for Windows and Kinect for Xbox sensors need additional power for the sensors to work with your PC. This might not be required when connected to the Xbox device as the Xbox port has enough power to operate the device. There is no difference between Xbox Kinect and Kinect for Windows in this respect. However in Kinect for Windows, the USB cable is small and improved to enable more reliability and portability across a wide range of computers.

And finally, the Kinect for Windows sensor is for commercial applications, which means that if you are developing a commercial application, you must use the Kinect for Windows device for production, whereas you can use Kinect for Xbox for general development, learning, and research purposes.

Where can you use Kinect

By now it has already struck you that this is something more than just gaming. The Kinect sensor for Windows and the Kinect for Windows SDK unwrap a new opportunity for the developer to build a wide range of applications. These can include:

Capturing real-time video using the color sensorTracking a human body and then responding to its movements and gestures as a natural user interfaceMeasuring the distances of objects and respondingAnalyzing 3D data and making a 3D model and measurementGenerating a depth map of the objects trackedRecognizing a human voice and developing hands-free applications that can be controlled by voice

With this you can build a number of real-world applications that fall under a different domain. The following are a few examples, which will help you understand the applicability of Kinect sensors:

Healthcare: Using the Kinect sensor, you can build different applications for healthcare, such as exercise measurement, monitoring patients, their body movements, and so onRobotics: Kinect can be used as a navigation system for robots either by tracking human gestures, voice commands, or by human body movementsEducation: You can build various applications for students and kids to educate and help them to learn subjects either by their gesture and voice commandsSecurity system: Kinect can be used for developing security systems where you can track human body movement or face and send the notificationsVirtual Reality: With the help of Kinect 3D technology and human gesture tracking, several virtual reality applications can be build using the Kinect sensorTrainer: Kinect can potentially be used as a trainer by measuring the movements of human body joints, providing live feedback to users if the joints are moving in an appropriate manner by comparing the movements with previously stored dataMilitary: Kinect can be used to build intelligent drones to spy on enemy lines

Well these were just a few specific examples of domains where you can use Kinect, but at the end of the day it's up to your imagination; where and how you want this device to work.

Summary

This chapter gave you an inside look at the different components of the Kinect sensor. You saw that the major components of a Kinect device are its color sensor, IR depth sensors, IR emitter, microphone arrays, and a stepper motor that can be tilted to change the Kinect camera angles. While the color sensor and depth sensors ensure video and depth data input, which is of prime importance for the functioning of the device, the microphone arrays on the other hand ensure that the audio quality is also at par. Also worthwhile is mentioning about how kinect processes the depth data, and the array of microphones, which is a design novelty that helps in clear voice recognition with the use of the noise suppression and echo cancelation mechanisms. Kinect for Windows is also capable of tracking humans at a close range of approximately 40 centimeters using Near Mode. It wouldn't be wrong to say that it is this combination of technological innovations that make Kinect the awe-inspiring device that it is. You have also gone through the different possibilities of applications that can be developed using Kinect. In the next chapter, we will walk you through the step-by-step installation and configuration of the development environment setup along with different troubleshooting tips and tricks that will help you to be sure about everything before beginning with development.

Chapter 2. Getting Started

The Kinect for Windows SDK is a toolkit for developing applications for Kinect devices. Developing applications using Kinect SDK is fairly easy and straightforward. The SDK provides an interface to interact with Kinect via system drivers. The SDK includes drivers for the Kinect sensor, which interact with the device, and the OS and APIs interact with the device through program. Overall, the SDK provides an opportunity to the developers to build an application using either managed code (C# and VB.NET) or unmanaged code (C++) using Visual Studio 2010 or higher versions, running on Windows 7 or Windows 8.