Limited Area Depth data

# Limited Area Depth data

• Friday, May 04, 2012 4:14 PM

I had a area limited by RightHand position (X,Y) and +- reference distance, for X and Y is the same calcule.

I just want to obtain distance in that area.

The depth data is obtained How??

I tryed:

```short[] rawDepthData = new short[depth.PixelDataLength];
depth.CopyPixelDataTo(rawDepthData);

for (int depthIndexX = (int)Math.Round(RightHandPX) - RefDistance; depthIndexX < (int)Math.Round(RightHandPX) + RefDistance; depthIndexX++)
{
for (int depthIndexY = (int)Math.Round(RightHandPY) - RefDistance; depthIndexY < (int)Math.Round(RightHandPY) + RefDistance; depthIndexY++)
{

int dist = rawDepthData[(depthIndexY + depthIndexX)] >> DepthImageFrame.PlayerIndexBitmaskWidth;

...```
RightHandPX is the position of right hand in pixel. RightHandPY is the same but for Y.

### All Replies

• Friday, May 04, 2012 5:41 PM
Owner

I think the formula you want is:

int dist = rawDepthData[(depthIndexY * depth.Width) + depthIndexX] >> DepthImageFrame.PlayerIndexBitmaskWidth;

John
K4W Dev

• Friday, May 04, 2012 5:49 PM
Owner

since you are dealing with an area of pixels, you need to average the range of all the pixels. Keep in mind to make sure your ranges don't go past the bounds of the array.

int totalDistance = 0;

int counter = 0;

for(int y = refY - 5; y < refY + 5; y++)

if( y < 0 || y > DepthImageHeight )
continue;

for(int x = refX - 5; x < refX + 5; x++)

if (x < 0 || x > DepthImageWidth )
continue;

(if we are here the x,y is valid)
totalDistance += rawDepthData[(y * (Width of Depthframe) + x)] >> DepthImageFrame.PlayerIndexBitmaskWidth;
counter++;

}

}

// calculate the average of the distances

double avgDist = totalDistance / counter;

• Monday, May 07, 2012 4:36 PM

Thanks was it that i searching for.