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.

  1. Create a new WPF Project.
  2. Add reference to the Kinect Library
    image
  3. add “using Microsoft.Kinect; “
  4. initialize sensor :
            KinectSensor Kinect;
     
            private void Window_Loaded_1(object sender, RoutedEventArgs e)
            {
                if (KinectSensor.KinectSensors.Count < 1)
                {
                    MessageBox.Show("No Kinect Sensor Attached");
                }
                else
                {
                    startkinect();
                }
            }
     
            private void startkinect()
            {
                //Link The 1st Kinect 
                Kinect = KinectSensor.KinectSensors.FirstOrDefault();
                //Enable Color Stream
                Kinect.ColorStream.Enable();
                //Start Sensor
                Kinect.Start();
                Kinect.AllFramesReady += Kinect_AllFramesReady;
            }
  5. At MainWindows.xaml add Image with width=320 Height=240 and Name = RGB .
    image
  6. Now lets link the RGB Data To the Image frame.
            void Kinect_AllFramesReady(object sender, AllFramesReadyEventArgs e)
            {
                colorFrame(e);
            }
    
            private void colorFrame(AllFramesReadyEventArgs e)
            {
                using (ColorImageFrame ColorFrame = e.OpenColorImageFrame())
                {
                    if (ColorFrame == null)
                    {
                        return;
                    }
                    byte [] Pixels = new byte[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);
                }
            }
  7. One last thing don’t forget to close the Kinect When You are Done :)
    private void Window_Closing_1(object sender, System.ComponentModel.CancelEventArgs e)
            {
                Kinect.Stop();
                Kinect = null;
            }
  8. Now You are all done,lets run It.
  9. 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 Smile