Let’s get directly Into the Core of this Blog post,
1st Get a Kinect For windows unit.
2nd Download the SDK and the Toolkit which you will find here.
3rd Play Around with the toolkit where you will find a lot of helpful resources and demo`s.
Then let’s make a simple application to display the data from the RGB camera.
- Create a new WPF Project.
- Add reference to the Kinect Library
- add “using Microsoft.Kinect; “
- initialize sensor :
KinectSensor Kinect;
privatevoid Window_Loaded_1(object sender, RoutedEventArgs e)
{
if (KinectSensor.KinectSensors.Count < 1)
{
MessageBox.Show("No Kinect Sensor Attached");
}
else
{
startkinect();
}
}
privatevoid startkinect()
{
//Link The 1st Kinect
Kinect = KinectSensor.KinectSensors.FirstOrDefault();
//Enable Color Stream
Kinect.ColorStream.Enable();
//Start Sensor
Kinect.Start();
Kinect.AllFramesReady += Kinect_AllFramesReady;
}
- At MainWindows.xaml add Image with width=320 Height=240 and Name = RGB .
- Now lets link the RGB Data To the Image frame.
void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e) { colorFrame(e); }privatevoid colorFrame(AllFramesReadyEventArgs e) {using (ColorImageFrame ColorFrame = e.OpenColorImageFrame()) {if (ColorFrame == null) {return; }byte [] Pixels = newbyte[ColorFrame.PixelDataLength] ; ColorFrame.CopyPixelDataTo(Pixels);int stride = ColorFrame.Width*4; RGB.Source = BitmapSource.Create(ColorFrame.Width ,ColorFrame.Height,96,96,PixelFormats.Bgr32,null,Pixels ,stride); } }
- One last thing don’t forget to close the Kinect When You are Done :)
privatevoid Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
{
Kinect.Stop();
Kinect = null;
}
- Now You are all done,lets run It.
- You should be seeing a Video for what ever in front of the Kinect.
And that’s all you are Done with your 1st application , If you have any questions don’t hesitate To ask me