Click here to Skip to main content
15,879,348 members
Articles / Desktop Programming / WPF

Smoothing Kinect Depth Frames in Real-Time

Rate me:
Please Sign up or sign in to vote.
4.91/5 (39 votes)
24 Jan 2012CPOL11 min read 281.6K   8.2K   58  
Removing noise from the Kinect Depth Frames in real-time using pixel filters and weighted moving average techniques.
using System.Threading.Tasks;
using System.Windows;
using Microsoft.Research.Kinect.Nui;

namespace KinectDepthSmoothing
{
    public partial class MainWindow : Window
    {
        private short[] CreateDepthArray(ImageFrame image)
        {
            // When creating a depth array, it will have half the number of indexes than the original depth image
            // This is because the depth image uses two bytes to represent depth.  These values must then be 
            // transformed to a single value per pixel of the final image that represents depth
            // for purposes of smoothing prior to rendering.

            short[] returnArray = new short[image.Image.Width * image.Image.Height];
            byte[] depthFrame = image.Image.Bits;

            Parallel.For(0, returnArray.Length, index =>
            {
                var depthIndex = index * 2;
                returnArray[index] = CalculateDistanceFromDepth(depthFrame[depthIndex], depthFrame[depthIndex + 1]);
            });

            return returnArray;
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Open Systems Technologies
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions