Vous êtes sur la page 1sur 5


Enumerate Kinect sensors

Enumerate the Kinects that are connected to your computer using the KinectSensor class. When you
declare the private sensor member, the static KinectSensors property is filled with the collection of
Kinects that are on your system. Because the property is static, the collection of Kinects is available
as long as your application is running.
private KinectSensor sensor;
foreach (var potentialSensor in KinectSensor.KinectSensors)
if (potentialSensor.Status == KinectStatus.Connected)
this.sensor = potentialSensor;
Use a foreach statement to loop through the collection and test each Kinect to see if it is connected
using the KinectStatus enumeration. Once you find a sensor whose status is Connected, store the
Kinect in the sensor member so that you can use the sensor in the code below.

Enable Data Streaming

After enumerating the available sensors and finding one that is connected and ready, the next step
is to enable the Kinect to stream out data. There are several types of data that can be streamed out:
color, depth, skeleton, and infrared. This example demonstrates how to enable each of the data
if (this.sensor != null)

Start the Kinect

Once you have chosen a connected sensor, and initialized the data streams that you need in your
application, call the Start method to start streaming data out.
if (this.sensor != null)

A Kinect is required
When a Kinect is required but can't be detected, the UI displays this notification:

The notification remains visible until the user plugs in a Kinect.

Figure 1. A Kinect has been plugged in

During initialization, Windows performs the appropriate device discovery and enumeration to
initialize the Kinect drivers.

The Kinect sensor is ready

When the driver installation completes, the UI displays this notification, which then fades out:
Figure 2. The sensor is initialized and ready for use

Once the notification fades out, the sensor is ready for use by any Kinect-enabled application.

Natural User Interface for

Kinect for Windows
The Natural User Interface (NUI) is the core of the Kinect for Windows API. Through it you can
access the following sensor data in your application:

Audio data streamed out by the audio stream.

Color image data and depth image data streamed out by the color and depth streams.

Data Streams
If enabled, a Kinect can capture audio, color, and depth data, and process the depth data to
generate skeleton data. The sensor provides the data to your application in the form of a data
stream. The NUI API lets you programmatically control and access all four of the data streams.
To avoid dropping frames, ensure that your application processes and releases each frame in a
timely fashion. When initializing the NUI API, the application needs to:

Identify which streams are needed

Open each stream
Preallocate buffers to hold sensor data
Get the new data for each stream each frame
Release the buffer so that the runtime can fill it with the next frame

Audio Stream
The Kinect sensor includes a four-element, linear microphone array, shown here in purple.

The microphone array captures audio data at a 24-bit resolution, which allows accuracy across a
wide dynamic range of voice data, from normal speech at three or more meters to a person yelling.

What Can You Do with Audio?

The sensor (microphone array) enables several user scenarios, such as:

High-quality audio capture

Focus on audio coming from a particular direction with beamforming
Identification of the direction of audio sources
Improved speech recognition as a result of audio capture and beamforming
Raw voice data Access

How to enable skeletal tracking in C#

To enable skeletal tracking, call the SkeletonStream.Enable method; you can access
the KinectSensor.SkeletonStream property from the KinectSensor class. To receive information
about the recognized users, subscribe to the KinectSensor.SkeletonFrameReady event or
the KinectSensor.AllFramesReady event managed by the KinectSensor class.
KinectSensor kinect = null;
void StartKinectST()
kinect = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status ==
KinectStatus.Connected); // Get first Kinect Sensor
kinect.SkeletonStream.Enable(); // Enable skeletal tracking

skeletonData = new
Skeleton[kinect.SkeletonStream.FrameSkeletonArrayLength]; // Allocate ST
kinect.SkeletonFrameReady += new
EventHandler<SkeletonFrameReadyEventArgs>(kinect_SkeletonFrameReady); //
Get Ready for Skeleton Ready Events
kinect.Start(); // Start Kinect sensor