12,701,828 members (36,008 online)

146.2K views
56 bookmarked
Posted

# Smoothing Kinect Depth Frames in Real-Time

, 24 Jan 2012 CPOL
Removing noise from the Kinect Depth Frames in real-time using pixel filters and weighted moving average techniques.
 ```﻿using System.Windows; using System.Threading.Tasks; namespace KinectDepthSmoothing { public partial class MainWindow : Window { private short[] CreateAverageDepthArray(short[] depthArray) { // This is a method of Weighted Moving Average per pixel coordinate across several frames of depth data. // This means that newer frames are linearly weighted heavier than older frames to reduce motion tails, // while still having the effect of reducing noise flickering. averageQueue.Enqueue(depthArray); CheckForDequeue(); int[] sumDepthArray = new int[depthArray.Length]; short[] averagedDepthArray = new short[depthArray.Length]; int Denominator = 0; int Count = 1; // REMEMBER!!! Queue's are FIFO (first in, first out). This means that when you iterate // over them, you will encounter the oldest frame first. // We first create a single array, summing all of the pixels of each frame on a weighted basis // and determining the denominator that we will be using later. foreach (var item in averageQueue) { Parallel.For(0, depthArray.Length, i => { sumDepthArray[i] += item[i] * Count; }); Denominator += Count; Count++; } // Once we have summed all of the information on a weighted basis, we can divide each pixel // by our calculated denominator to get a weighted average. Parallel.For(0, depthArray.Length, i => { averagedDepthArray[i] = (short)(sumDepthArray[i] / Denominator); }); return averagedDepthArray; } private void CheckForDequeue() { // We will recursively check to make sure we have Dequeued enough frames. // This is due to the fact that a user could constantly be changing the UI element // that specifies how many frames to use for averaging. if (averageQueue.Count > averageFrameCount) { averageQueue.Dequeue(); CheckForDequeue(); } } } } ```

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.

## Share

 Software Developer Open Systems Technologies United States
First learned to program in 1997 on my TI-83 and have been doing it ever since, with a foray into networking and infrastructure.

Mostly a C# junky (Win\Web Forms, WP7.5/8, WPF and MVC), though I have experience with many other technologies and products.

I have also been trying to learn and apply more in the area of AI; focusing on computer vision, natural language processing, and classification.

In my spare time, I love to tinker with electronics and various useless DIY projects.

My brain is a shark... if it stops moving, it will die. I'm always looking to learn more.