Beispiel #1
0
        /*
         * Event which triggers when all frames are ready from the kinect
         * (will operate at the speed of the slowest camera)
         **/
        private void sensor_AllFramesReady(object sender, AllFramesReadyEventArgs e)
        {
            using (ColorImageFrame colorFrame = e.OpenColorImageFrame())
            {
                using (DepthImageFrame depthFrame = e.OpenDepthImageFrame())
                {
                    if (depthFrame != null)
                    {
                        // Display an actual slice
                        // (smaller range should only display things within that range)
                        //Range can be tweaked via sliders on application
                        depthFrame.depthSlice(sliceBitmap, (int)minSlider.Value, (int)maxSlider.Value);
                    }

                    if (colorFrame != null)
                    {
                        //Initializes a byte array to the size
                        //of colorFrame's pixelDataLength
                        byte[] colorPixels = new byte[colorFrame.PixelDataLength];
                        colorFrame.CopyPixelDataTo(colorPixels);
                        //Number of pixels in a row (based on bgr32 format)
                        int stride = colorFrame.Width * 4;

                        /*
                         * Creates a bitmapsource based on the colorFrame coming
                         * from the kinect (in bgr32 using our calculated stride)
                         * and displays it to the image frame named colorDisplay
                         **/
                        colorDisplay.Source =
                            BitmapSource.Create
                                (colorFrame.Width, colorFrame.Height,
                                96, 96, PixelFormats.Bgr32, null, colorPixels, stride);
                    }
                }
            }
        }