KinectDepthSmoothingBin.zip
KinectDepthSmoothing.exe
KinectDepthSmoothingBin3.zip
KinectDepthSmoothing.exe
KinectDepthSmoothingSrc.zip
KinectDepthSmoothing
Properties
Settings.settings
KinectDepthSmoothingSrc3.zip
Settings.settings
KinectDepthSmoothing_bin_.zip
KinectDepthSmoothing.exe
KinectDepthSmoothing_src_.zip
Settings.settings
|
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)
{
// Process each row in parallel
Parallel.For(0,240, depthArrayRowIndex =>
{
// Process each pixel in the row
for (int depthArrayColumnIndex = 0; depthArrayColumnIndex < 320; depthArrayColumnIndex++)
{
var index = depthArrayColumnIndex + (depthArrayRowIndex * 320);
sumDepthArray[index] += item[index] * 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.
// Process each row in parallel
Parallel.For(0,240, depthArrayRowIndex =>
{
// Process each pixel in the row
for (int depthArrayColumnIndex = 0; depthArrayColumnIndex < 320; depthArrayColumnIndex++)
{
var index = depthArrayColumnIndex + (depthArrayRowIndex *320);
averagedDepthArray[index] = (short)(sumDepthArray[index] / 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();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of use 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.
Karl Sanford
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.