I am working with the Kinect SDK and I am trying to filter the depth image data in two ways:
- Remove all depths that are not associated with a player
- Remove all depths that are greater than a given depth (calculated form the position of a players wrists)
The result of which is essentially to show only the parts of a players body which are less than a certain depth from the sensor.
Whilst the code below does what i want it to do, its not proving very good when i run performance analysis, so I am looking for ways in which it could be improved.
The basic issue is that the array contains 307200 values (as the depth image size is 640x480), and I am trying to get this method called around 30 times a second.
Does anyone have any pointers as to how this could be done more efficiently? The code also uses EmguCV libraries in other parts and I have tinkered with using the cvInvokeThreshold method but it didn't seeem to work as well as this code...
If you need any more information, let me know.
Many Thanks,
Dave McB
public static byte[] GetDepths(byte[] depths, DepthImagePixel[] depthPixels, int width, int height, int threshold)
{
Parallel.For(0, width, i =>
{
for (int j = 0; j < height; j++)
{
//Have to calculate the index we are working on using i and j
int rawDepthDataIndex = i * height + j;
//gets the depth and player values
short depth = depthPixels[rawDepthDataIndex].Depth;
short player = depthPixels[rawDepthDataIndex].PlayerIndex;
if (player > 0 && depth < threshold)
depths[rawDepthDataIndex] = (byte)depth;
else
depths[rawDepthDataIndex] = 0;
}
});
return depths;
}
Parallel.For(0, height, i => { for (int j = 0; j < width; j++) { int rawDepthDataIndex = i * height + j;? - Julia Schwarz