While working with the kinect I found out, that the bitmap and its depth information are unreliable and for some reason much more disturbed than the data from the actual byte array.
I realised this when I tried get the min and max by accessing the bitmap like this
for (var y = 0; y < height; y++)
{
var heightOffset = y * width;
for (var x = 0; x < width; x++)
{
var index = ((width - x - 1) + heightOffset) * 4;
var distance = GetDistance(depth[depthIndex], depth[depthIndex + 1]);
But on the other hand I achieved much better results when I directly accessed the depth byte array (as a Stackoverflow member Chris pointed out, thank you, Chris) with this method:
int min2 = int.MaxValue, max2 = int.MinValue;
for (int i = 0; i < depth.Length; i += 2)
{
int dist = GetDistance(depth[i], depth[i + 1]);
if (dist < min2 && dist > 0)
min2 = dist;
if (dist > max2)
max2 = dist;
}
My question is:
- I want to count all the points within a certain distance intervall.
- Then I want to get their actual position (x,y).
How can I get the position or directly add those points to a list - for further action?
My ultimate goal is to identify certain predefined objects by counting the number of pixels within certain intervall (to distinct a ball from a block for example).
for (int i = 0; i < depth.Length; i += 2)
{
int dist = GetDistance(depth[i], depth[i + 1]);
if (dist < z2 && dist > z1)
a++;
}