void ColorImageReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage planarImage = e.ImageFrame.Image;

            //An interopBitmap is a WPF construct that enables resetting the Bits of the image.
            //This is more efficient than doing a BitmapSource.Create call every frame.
            if (imageHelper == null)
            {
                imageHelper = new InteropBitmapHelper(planarImage.Width, planarImage.Height, planarImage.Bits);
                kinectColorImage.Source = imageHelper.InteropBitmap;
            }
            else
            {
                imageHelper.UpdateBits(planarImage.Bits);
            }
        }
        void ColorImageReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage planarImage = e.ImageFrame.Image;

            //An interopBitmap is a WPF construct that enables resetting the Bits of the image.
            //This is more efficient than doing a BitmapSource.Create call every frame.
            if (imageHelper == null)
            {
                imageHelper             = new InteropBitmapHelper(planarImage.Width, planarImage.Height, planarImage.Bits);
                kinectColorImage.Source = imageHelper.InteropBitmap;
            }
            else
            {
                imageHelper.UpdateBits(planarImage.Bits);
            }
        }
        private void DepthImageReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage planarImage = e.ImageFrame.Image;
            byte[] convertedDepthBits = convertDepthFrame(planarImage.Bits);

            //An interopBitmap is a WPF construct that enables resetting the Bits of the image.
            //This is more efficient than doing a BitmapSource.Create call every frame.
            if (imageHelper == null)
            {
                imageHelper = new InteropBitmapHelper(planarImage.Width, planarImage.Height, convertedDepthBits);
                kinectDepthImage.Source = imageHelper.InteropBitmap;
            }
            else
            {
                imageHelper.UpdateBits(convertedDepthBits);
            }

            calculateFrameRate();
        }
        private void DepthImageReady(object sender, ImageFrameReadyEventArgs e)
        {
            PlanarImage planarImage = e.ImageFrame.Image;

            byte[] convertedDepthBits = convertDepthFrame(planarImage.Bits);

            //An interopBitmap is a WPF construct that enables resetting the Bits of the image.
            //This is more efficient than doing a BitmapSource.Create call every frame.
            if (imageHelper == null)
            {
                imageHelper             = new InteropBitmapHelper(planarImage.Width, planarImage.Height, convertedDepthBits);
                kinectDepthImage.Source = imageHelper.InteropBitmap;
            }
            else
            {
                imageHelper.UpdateBits(convertedDepthBits);
            }

            calculateFrameRate();
        }
Example #5
0
        private void DepthImageReady(object sender, DepthImageFrameReadyEventArgs e)
        {
            using (DepthImageFrame imageFrame = e.OpenDepthImageFrame())
            {
                if (imageFrame != null)
                {
                    // We need to initialize if colorDataNeedsInitialization is true or if the format has changed.
                    depthDataNeedsInitialization |= (lastImageFormat != imageFrame.Format);

                    if (depthDataNeedsInitialization)
                    {
                        pixelData    = new short[imageFrame.PixelDataLength];
                        depthFrame32 = new byte[imageFrame.Width * imageFrame.Height * 4];
                    }

                    imageFrame.CopyPixelDataTo(pixelData);

                    byte[] convertedDepthBits = convertDepthFrame(pixelData, ((KinectSensor)sender).DepthStream.TooFarDepth);

                    //An interopBitmap is a WPF construct that enables resetting the Bits of the image.
                    //This is more efficient than doing a BitmapSource.Create call every frame.
                    if (depthDataNeedsInitialization)
                    {
                        imageHelper             = new InteropBitmapHelper(imageFrame.Width, imageFrame.Height, convertedDepthBits);
                        kinectDepthImage.Source = imageHelper.InteropBitmap;
                    }
                    else
                    {
                        imageHelper.UpdateBits(convertedDepthBits);
                    }

                    // If we succeeded, we can mark the depth data as successfully initialized
                    depthDataNeedsInitialization = false;
                    lastImageFormat = imageFrame.Format;

                    UpdateFrameRate();
                }
            }
        }
        void ColorImageReady(object sender, ColorImageFrameReadyEventArgs e)
        {
            using (ColorImageFrame imageFrame = e.OpenColorImageFrame())
            {
                if (imageFrame != null)
                {
                    // We need to initialize if colorDataNeedsInitialization is true or if the format has changed.
                    colorDataNeedsInitialization |= (lastImageFormat != imageFrame.Format);

                    if (colorDataNeedsInitialization)
                    {
                        lastImageFormat = imageFrame.Format;
                        pixelData       = new byte[imageFrame.PixelDataLength];
                    }

                    imageFrame.CopyPixelDataTo(pixelData);

                    //An interopBitmap is a WPF construct that enables resetting the Bits of the image.
                    //This is more efficient than doing a BitmapSource.Create call every frame.
                    if (colorDataNeedsInitialization)
                    {
                        kinectColorImage.Visibility = Visibility.Visible;
                        imageHelper             = new InteropBitmapHelper(imageFrame.Width, imageFrame.Height, pixelData);
                        kinectColorImage.Source = imageHelper.InteropBitmap;
                    }
                    else
                    {
                        imageHelper.UpdateBits(pixelData);
                    }

                    // If we succeeded, we can mark the color data as successfully initialized
                    colorDataNeedsInitialization = false;
                    lastImageFormat = imageFrame.Format;

                    UpdateFrameRate();
                }
            }
        }
Example #7
0
        void OnKinectVideoReady(object sender, KinectNui.ImageFrameReadyEventArgs e)
        {
            _timer.Start();

            _bitmap = BitmapSource.Create(e.ImageFrame.Image.Width,
                e.ImageFrame.Image.Height,
                96,
                96,
                PixelFormats.Bgr32,
                null,
                e.ImageFrame.Image.Bits,
                e.ImageFrame.Image.Width * e.ImageFrame.Image.BytesPerPixel
                );

            var planarImage = e.ImageFrame.Image;

            if (imageHelper == null)
            {
                imageHelper = new InteropBitmapHelper(planarImage.Width, planarImage.Height, planarImage.Bits);
                kinectVideo.Source = imageHelper.InteropBitmap;
            }
            else
            {
                imageHelper.UpdateBits(planarImage.Bits);
            }
        }