Example #1
0
        public static BitmapSource ToBitmapSource(this DepthImageFrame image)
        {
            if (image == null)
            {
                return(null);
            }

            var bytes = ImageFrameCommonExtensions.ConvertDepthFrameToBitmap(image);

            return(bytes.ToBitmapSource(image.Width, image.Height));
        }
        public static byte[] ConvertDepthFrameToBitmap(DepthImageFrame depthFrame)
        {
            if (depthFrame == null)
            {
                return(null);
            }

            short[] depthData = new short[depthFrame.PixelDataLength];
            depthFrame.CopyPixelDataTo(depthData);

            Byte[] depthColors = new Byte[depthData.Length * 4];             //four colors for each pixel

            for (int colorIndex = 0, depthIndex = 0; colorIndex < depthColors.Length; colorIndex += 4, depthIndex++)
            {
                //get the depth, then calculate the intensity (0-255 based on the depth)
                //depth of -1 = dark brown

                int depth = GetDepth(depthData[depthIndex]);

                if (depth == -1)
                {
                    // dark brown
                    depthColors[colorIndex + RedIndex]   = 66;
                    depthColors[colorIndex + GreenIndex] = 66;
                    depthColors[colorIndex + BlueIndex]  = 33;
                }
                else
                {
                    var intensity = ImageFrameCommonExtensions.CalculateIntensityFromDepth(depth);

                    depthColors[colorIndex + RedIndex]   = intensity;
                    depthColors[colorIndex + GreenIndex] = intensity;
                    depthColors[colorIndex + BlueIndex]  = intensity;
                }



                //if the pixel is a player, choose a color
                int player = GetPlayerIndex(depthData[depthIndex]);
                SkeletonOverlay(
                    ref depthColors[colorIndex + RedIndex],
                    ref depthColors[colorIndex + GreenIndex],
                    ref depthColors[colorIndex + BlueIndex], player);
            }
            return(depthColors);
        }
Example #3
0
        public static BitmapSource ToBitmapSource(this short[] depthData, int width, int height, int minimumDistance, Color highlightColor)
        {
            if (depthData == null)
            {
                return(null);
            }
            //depthData must be array of distances already

            var depthColors = new byte[depthData.Length * 4];

            for (int colorIndex = 0, depthIndex = 0; colorIndex < depthColors.Length; colorIndex += 4, depthIndex++)
            {
                //get the depth, then calculate the intensity (0-255 based on the depth)
                //depth of -1 = dark brown

                if (depthData[depthIndex] == -1)
                {
                    // dark brown
                    depthColors[colorIndex + ImageFrameCommonExtensions.RedIndex]   = 66;
                    depthColors[colorIndex + ImageFrameCommonExtensions.GreenIndex] = 66;
                    depthColors[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = 33;
                }
                else
                {
                    var intensity = ImageFrameCommonExtensions.CalculateIntensityFromDepth(depthData[depthIndex]);

                    depthColors[colorIndex + ImageFrameCommonExtensions.RedIndex]   = intensity;
                    depthColors[colorIndex + ImageFrameCommonExtensions.GreenIndex] = intensity;
                    depthColors[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = intensity;

                    //change color to highlight color
                    if (depthData[depthIndex] <= minimumDistance && depthData[depthIndex] > 0)
                    {
                        var color = Color.Multiply(highlightColor, intensity / 255f);

                        depthColors[colorIndex + ImageFrameCommonExtensions.RedIndex]   = color.R;
                        depthColors[colorIndex + ImageFrameCommonExtensions.GreenIndex] = color.G;
                        depthColors[colorIndex + ImageFrameCommonExtensions.BlueIndex]  = color.B;
                    }
                }
            }

            return(depthColors.ToBitmapSource(width, height));
        }
Example #4
0
 public static int GetDistance(this DepthImageFrame image, int x, int y)
 {
     return(ImageFrameCommonExtensions.GetDistance(image, x, y));
 }
Example #5
0
 public static short[] ToDepthArray(this DepthImageFrame image)
 {
     return(ImageFrameCommonExtensions.ToDepthArray(image));
 }