/// <summary> /// Converts a color frame to a System.Media.ImageSource with its background removed. /// </summary> /// <param name="frame">A BackgroundRemovedColorFrame generated from a Kinect sensor.</param> /// <param name="format">The pixel format.</param> /// <returns>The specified frame in a System.media.ImageSource format.</returns> public static ImageSource ToBitmap(this BackgroundRemovedColorFrame frame, System.Windows.Media.PixelFormat format) { byte[] pixels = new byte[frame.PixelDataLength]; frame.CopyPixelDataTo(pixels); return pixels.ToBitmap(frame.Width, frame.Height, format); }
public static int GetDistance(this DepthImageFrame depthFrame, int x, int y) { var width = depthFrame.Width; if (x > width) throw new ArgumentOutOfRangeException("x", "x is larger than the width"); if (y > depthFrame.Height) throw new ArgumentOutOfRangeException("y", "y is larger than the height"); if (x < 0) throw new ArgumentOutOfRangeException("x", "x is smaller than zero"); if (y < 0) throw new ArgumentOutOfRangeException("y", "y is smaller than zero"); var index = (width * y) + x; short[] allData = new short[depthFrame.PixelDataLength]; depthFrame.CopyPixelDataTo(allData); return GetDepth(allData[index]); }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="format">Pixel format of the depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static ImageSource ToBitmap(this DepthImageFrame frame, PixelFormat format, DepthImageMode mode) { short[] pixelData = new short[frame.PixelDataLength]; frame.CopyPixelDataTo(pixelData); byte[] pixels; switch (mode) { case DepthImageMode.Raw: pixels = GenerateRawFrame(frame, pixelData); break; case DepthImageMode.Dark: pixels = GenerateDarkFrame(frame, pixelData); break; case DepthImageMode.Colors: pixels = GenerateColoredFrame(frame, pixelData); break; case DepthImageMode.Player: pixels = GeneratePlayerFrame(frame, pixelData); break; default: pixels = GenerateRawFrame(frame, pixelData); break; } return pixels.ToBitmap(frame.Width, frame.Height, format); }
/// <summary> /// Converts a color frame to a System.Drawing.Bitmap. /// </summary> /// <param name="frame">A ColorImageFrame generated from a Kinect sensor.</param> /// <param name="format">Image format.</param> /// <returns>The specified frame in a System.Drawing.Bitmap format.</returns> public static Bitmap ToBitmap(this ColorImageFrame frame, PixelFormat format) { byte[] pixels = new byte[frame.PixelDataLength]; frame.CopyPixelDataTo(pixels); return pixels.ToBitmap(frame.Width, frame.Height, format); }
public static Bitmap ToBitmap(this DepthImageFrame image, PixelFormat format) { if (image == null || image.PixelDataLength == 0) return null; var data = new short[image.PixelDataLength]; image.CopyPixelDataTo(data); return data.ToBitmap(image.Width, image.Height , format); }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.Imaging.BitmapSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <returns>The corresponding System.Windows.Media.Imaging.BitmapSource representation of the depth frame.</returns> public static BitmapSource ToBitmap(this DepthImageFrame frame) { int minDepth = frame.MinDepth; int maxDepth = frame.MaxDepth; if (_bitmap == null) { _width = frame.Width; _height = frame.Height; _depthData = new short[_width * _height]; _pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL]; _bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null); } frame.CopyPixelDataTo(_depthData); // Convert the depth to RGB. int colorIndex = 0; for (int depthIndex = 0; depthIndex < _depthData.Length; ++depthIndex) { // Get the depth for this pixel short depth = _depthData[depthIndex]; // To convert to a byte, we're discarding the most-significant // rather than least-significant bits. // We're preserving detail, although the intensity will "wrap." // Values outside the reliable depth range are mapped to 0 (black). byte intensity = (byte)(depth >= minDepth && depth <= maxDepth ? depth : 0); _pixels[colorIndex++] = intensity; // Blue _pixels[colorIndex++] = intensity; // Green _pixels[colorIndex++] = intensity; // Red // We're outputting BGR, the last byte in the 32 bits is unused so skip it // If we were outputting BGRA, we would write alpha here. ++colorIndex; } _bitmap.Lock(); Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length); _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height)); _bitmap.Unlock(); return _bitmap; }
/// <summary> /// Converts a depth frame to the corresponding System.Windows.Media.ImageSource. /// </summary> /// <param name="frame">The specified depth frame.</param> /// <param name="mode">Depth frame mode.</param> /// <returns>The corresponding System.Windows.Media.ImageSource representation of the depth frame.</returns> public static BitmapSource ToBitmap(this DepthImageFrame frame, DepthImageMode mode) { if (_bitmap == null) { _width = frame.Width; _height = frame.Height; _depthData = new short[frame.PixelDataLength]; _pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL]; _bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null); } frame.CopyPixelDataTo(_depthData); switch (mode) { case DepthImageMode.Raw: GenerateRawFrame(); break; case DepthImageMode.Dark: GenerateDarkFrame(); break; case DepthImageMode.Colors: GenerateColoredFrame(); break; case DepthImageMode.Player: GeneratePlayerFrame(); break; default: GenerateRawFrame(); break; } _bitmap.Lock(); Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length); _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height)); _bitmap.Unlock(); return _bitmap; }
/// <summary> /// Converts a color frame to a System.Media.ImageSource. /// </summary> /// <param name="frame">A ColorImageFrame generated from a Kinect sensor.</param> /// <returns>The specified frame in a System.media.ImageSource format.</returns> public static BitmapSource ToBitmap(this ColorImageFrame frame) { if (_bitmap == null) { _width = frame.Width; _height = frame.Height; _pixels = new byte[_width * _height * Constants.BYTES_PER_PIXEL]; _bitmap = new WriteableBitmap(_width, _height, Constants.DPI, Constants.DPI, Constants.FORMAT, null); } frame.CopyPixelDataTo(_pixels); _bitmap.Lock(); Marshal.Copy(_pixels, 0, _bitmap.BackBuffer, _pixels.Length); _bitmap.AddDirtyRect(new Int32Rect(0, 0, _width, _height)); _bitmap.Unlock(); return _bitmap; }
public static Bitmap SliceDepthImage(this DepthImageFrame image, int min = 20, int max = 1000) { int width = image.Width; int height = image.Height; //var depthFrame = image.Image.Bits; short[] rawDepthData = new short[image.PixelDataLength]; image.CopyPixelDataTo(rawDepthData); byte[] pixels = new byte[height * width * 4]; const int BlueIndex = 0; const int GreenIndex = 1; const int RedIndex = 2; for (int depthIndex = 0, colorIndex = 0; depthIndex < rawDepthData.Length && colorIndex < pixels.Length; depthIndex++, colorIndex += 4) { // Calculate the distance represented by the two depth bytes int depth = rawDepthData[depthIndex] >> DepthImageFrame.PlayerIndexBitmaskWidth; // Map the distance to an intesity that can be represented in RGB var intensity = ImageHelpers.CalculateIntensityFromDistance(depth); if (depth > min && depth < max) { // Apply the intensity to the color channels pixels[colorIndex + BlueIndex] = intensity; //blue pixels[colorIndex + GreenIndex] = intensity; //green pixels[colorIndex + RedIndex] = intensity; //red } } return BitmapManipulator.ByteArrayToBitmap(pixels, width, height, PixelFormat.Format32bppArgb); }
public static BitmapSource ToBitmapSource(this ColorImageFrame image) { if (image == null) { return null; } byte[] colorData = new byte[image.PixelDataLength]; image.CopyPixelDataTo(colorData); return colorData.ToBitmapSource(image.Width, image.Height); }
public static Bitmap ToBitmap(this DepthImageFrame image) { short[] rawDepth = new short[image.PixelDataLength]; image.CopyPixelDataTo(rawDepth); return ImageFrameCommonExtensions.ConvertDepthFrameToBitmap(image).ToBitmap(image.Width, image.Height); //return ImageFrameCommonExtensions.ConvertDepthFrameDataToBitmapData(image.Image.Bits, image.Image.Width, image.Image.Height).ToBitmap(image.Image.Width, image.Image.Height); }
public static short[] ToPixelData( this DepthImageFrame depthFrame ) { short[] depth = new short[depthFrame.PixelDataLength]; depthFrame.CopyPixelDataTo( depth ); return depth; }
/// <summary> /// 距離データをshort列に変換する /// </summary> /// <param name="frame"></param> /// <returns></returns> public static short[] ToPixelData( this DepthImageFrame depthFrame ) { short[] pixels = new short[depthFrame.PixelDataLength]; depthFrame.CopyPixelDataTo( pixels ); return pixels; }
public static Media.Imaging.BitmapSource ToBitmapSource(this DepthImageFrame image) { if (image == null || image.PixelDataLength == 0) return null; var data = new short[image.PixelDataLength]; image.CopyPixelDataTo(data); return data.ToBitmapSource(Media.PixelFormats.Bgr555, image.Width, image.Height); }
public static short[] ToDepthArray(this DepthImageFrame image) { if (image == null) throw new ArgumentNullException("image"); var width = image.Width; var height = image.Height; //var depthArray = new short[width * image.Height]; short[] rawDepthData = new short[image.PixelDataLength]; image.CopyPixelDataTo(rawDepthData); short[] allPoints = new short[image.PixelDataLength]; for (int i = 0; i < rawDepthData.Length; i++) { allPoints[i] = (short) GetDepth(rawDepthData[i]); } return allPoints; }
/// <summary> /// 画素のバイト列を取得する /// </summary> /// <param name="colorFrame"></param> /// <returns></returns> public static byte[] ToPixelData(this ColorImageFrame colorFrame) { byte[] pixels = new byte[colorFrame.PixelDataLength]; colorFrame.CopyPixelDataTo(pixels); return pixels; }
public static Bitmap ToBitmap(this ColorImageFrame image) { byte[] colorData = new byte[image.PixelDataLength]; image.CopyPixelDataTo(colorData); return colorData.ToBitmap(image.Width, image.Height); }