|Getting started with Microsoft Kinect SDK|
|Friday, 17 June 2011|
Page 3 of 3
If you want to do the same job in WPF then simply change function to:
I'm not going to explain this in detail because it is a simple application of the BitmapSource class. See the references at the end of the article for more information on how WPF works with bitmap data.
Now with this function we can complete the event handler with the single line:
Bitmap bmap = PImageToBitmap(Image);
The Bitmap that results can now be used in a PictureBox to display the image. So place a PictureBox control on the form and add the final line:
pictureBox1.Image = bmap;
To make the WPF version work place an Image control on the form and set its source to the BitmapSource returned by the WPF version of the function.
Finally we need to clean up by calling the Uniitialize method when the program closes or when we have finished using the Kinect:
private void Form1_FormClosing(
If you now run the program - with the Kinect plugged in of course - you will see a video displayed in the PictureBox.
From here you can start to investigate the additional features of the video sensor, add a video capture facility for example. You can control the video camera's angle by setting the tilt of the entire Kinect. Add two buttons, label one Up and the other Down and enter:
private void button1_Click(
private void button2_Click(
Also take care when using the motor driven elevation control - you can burn the motor out if you make it move to often. The code for the buttons given above doesn't check to make sure that you haven't attempted to move it beyond its allowed range - so you can crash the program.
Notice that in general no error handling is included in any of the code so that you can see how it works more easily and in practice you would need to add Try-Catch statements to make sure that the application didn't crash.
The complete listing of the finished program is:
Going Deeper - literally because we explore the depth field
The Player Index - working with processed data
You can download the code for both the Windows Forms version and the WPF version in a single ZIP file from the CodeBin (note you have to register first).
Other Articles in this Series
Getting Started with PC Kinect using the open source drivers
Kinect goes self aware - a warning well we think it's funny and something every Kinect programmer should view before proceding to create something they regret!
On WPF Bitmap handling:
|Last Updated ( Monday, 06 February 2012 )|