The Kinect SDK is a developer toolkit for developing applications. This SDK provides a fantastic interface to interact with Kinect programmatically. The Kinect for Windows SDK beta includes drivers that interact with H/W and provides an interface to interact with device, APIs for interacting with Camera, Sensors, microphone and Motor. The SDK provides capabilities to the developers who build applications with C#, VB or C++ with Visual Studio 2010 which is running on Windows 7. I started developing application with Kinect SDK almost 2 months back, from the day when I received my Kinect Device. I tweeted about my first application over here and I am still learning about the Kinect SDK API’s and how to use them in different ways. Let’s share the learning over here. I will keep posting as step by step to allow you to understand the API’s and get inside Kinect development. I will write a series of post where I will discuss about fundamentals of Kinect SDK API and developing Application using it and yes Step by Step and obviously with Demo Project
So what are the thing we are going to learn today ? Well, we will learn about the system requirements and the installation of the Kinect device, which will ensure that our device setup properly and we are good to start with development.
Get Ready with Your Development Environment
The current version of Kinect for Windows SDK beta 1 needs below requirements to start
Hardware
- Kinect for Xbox 360 sensor
- Computer with a dual-core, 2.66-GHz or faster processor
- Windows 7–compatible graphics card that supports DirectX® 9.0c capabilities
- 2-GB RAM (4-GB RAM recommended)
Software
- Windows 7 (x86 or x64)
- Visual Studio 2010 Express (or other 2010 edition)
- Microsoft .NET Framework 4.0
Download and Install Kinect for Windows SDK beta
Download the SDK Beta, Once you have the development environment setup ready. Please make sure you are downloading the SDK Version based on 64bit or 32bit Operating System. Once done with download, install it. You really do not need to plugin your Kinect devices during the installation of SDK.
Know your Kinect Device
Before checking out Driver installation, let’s have a quick look into the basic H/W elements of Kinect. This contains 3d Depth Sensors, RGB Camera which is used for Video Capturing , Array of MIC and TILT.
Kinect SDK provides some API to interact with motorized tilt to enables the camera up or down 27 degrees . This API is the part of Kinect Camera.
I will be talking details about each and everything in my upcoming post while exploring the API’s for each every section.
Checkout your Installation of Device Driver
Plug in your Kinect USB cable with Computer. Once Windows detects the devices, you will get the LED Indicator blinking ( Yeah, this one is mine) .
Wait for Windows to recognize the sponsor’s. You can check it out from Control Panel > Device Manager for the installed device driver. By default with only USB connection, Windows will detect only the device, as shown in below picture.
But, Camera , Sensors and Audio is yet to detect. Here is a point, To detect all Kinect elements, device need some high power supply. For that you need to plug the power supply to your Kinect Device from external Power Source. This will enables windows to detect all the components of Kinect Devices.
Here is the Quick Video for the Device detection.
Test Your Device
You have done with setup and installation. Let have a quick test your device. Kinect SDK installs few sample application , Sample Skeletal Viewer is one of them. Just run that application, you will able to see your view in Depth View Skeletal View and Camera View.
If all of them are coming up. Your are all set to start development.
What else Kinect SDK installed for Developers ?
Yes, Kinect SDK also installed a best resource to learn Kinect SDK Development and Explore the APIs. This installation contains, Kinect SDK API Reference file. I learned most of the things from here itself.
How Application Interacts with Kinect
You have already installed SDK and Kinect Setup properly . So before start with development, let have a look how Application interacts with Kinect Devices. Kinect SDK Installed set of API to interact with Devices, You application will talk to those APIs and APIs will talk to Devices. Below images shows the same flow.
Staring With Application Development :
Finally all the setup are done. Let’s have start some development with Visual Studio 2010 and create a small application which will Initialize Kinect Sensor and display the Unique device name
Fire a new instance of Visual Studio, Select New Project Option from file Menu and Select “WPF Application” Template , Give the name as “MyFirstKinectDemo”
Click on OK, It will create a blank WPF Application for you. Before going ahead, first lets design the UI as show in below
Below code snippet is the XAML markup for the above design. Well, its very simple.
Now it’s time to interact with Kinect SDK API’s. To start with, you need to first add the reference of Kinect SDK assemblies. Navigate to solution explorer, Right Click on the Project and Select “Add Reference”
The assembly you need to add is “Microsoft.Research.Kinect.dll” , You can search for Kinect keyword in the Assembly search text box to get it faster.
This will add Microsoft.Research.Kinect.dll as reference to your project. The top level view of this assembly in Object Explorer given as below. These two are the different segment of Kinect APIs.
If you want to interact with NUI ( Natural User Interface) API like camera, sensors, Skeleton viewer you have to use the below namespaces.
If you want to interact with Kinect Audio Array, you have to include
For this application, we will be using NUI API hence we will be adding below namespaces with our code.
using Microsoft.Research.Kinect.Nui;
First of all you need to define the runtime of Kinect as shown in below, this represents the instance of Kinect Sensor.
After that, initialize the runtime with the options you want to use. Below are this Runtime options which Kinect Supports
In the next article I will discuss more about the runtime options. For this example, use RuntimeOptions.UseColor to use the RGB camera.
Below is complete Code snippet for Initialize and Uninitialized the Kinect Device.
/// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { /// <summary> /// /// </summary> Runtime nuiRuntime = new Runtime(); /// <summary> /// Initializes a new instance of the <see cref="MainWindow"/> class. /// </summary> public MainWindow() { InitializeComponent(); } /// <summary> /// Handles the Click event of the buttonInitialize control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void buttonInitialize_Click(object sender, RoutedEventArgs e) { // Intialize Kinect Device with UseColor Runtime Option nuiRuntime.Initialize(RuntimeOptions.UseColor); MessageBox.Show("Device Runtime Initialized"); //Get the Camera Device Name labelDeviceName.Content = nuiRuntime.NuiCamera.UniqueDeviceName; } /// <summary> /// Handles the Click event of the buttonUnInitialize control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Windows.RoutedEventArgs"/> instance containing the event data.</param> private void buttonUnInitialize_Click(object sender, RoutedEventArgs e) { // Uninitilize Runtime nuiRuntime.Uninitialize(); MessageBox.Show("Device Runtime UnInitialized"); } }
That’s all, Run the Application and Click on “Initialize Kinect Runtime” , your application will initialize a runtime of Kinect device via SDK APIs and you will get below message as written in code.
After the acceptance of the initialize message, you will get the Unique Camera device name.
Clicking on “Uninitialized Kinect Runtime, button will execute the below code to uninitialized device
Download Sample
Well, That’s all . To Summarize the stuff what I have discussed till now is, setting up your development environment, installing Kinect SDK, Detecting the devices and a small application to initialize the Kinect devices. This is only the beginning, we will talk a lot more about API and will start with something new in my next post.
Thanks !
Abhijit
Filed under: .NET 4.0, Kinect, Visual Studio 2010