My Kinect will be mounted on the ceiling looking downwards directly to the ground (should be paralell to ground). For object recognition i want to get the distance to the ground(maxDistance) and the distance to the object (minDistance). I wrote a loop that adds all distance values of each pixel to a list and then tried to get the Maximum int and the minimun of that list.

Unfortunately the result (that i am writing to a textbox, to check it) for zMIN and zMAX are always equally the same - which definetly is wrong.

QUESTION: What am i doing wrong? :)

List<int> tiefe = new List<int>();

        for (var y = 0; y < height; y++)  
        {  

            for (var x = 0; x < width; x++)
            { 

                var distance = GetDistance(depthdata[depthIndex], depthdata[depthIndex + 1]);
                tiefe.Add(distance); 
                depthIndex += 2;
            }
        }
        var zMAX = tiefe.Max();
        var zMin = tiefe.Min();
有帮助吗?

解决方案

If you just need the min/max, and depthData is a byte array of 16 bit depth values, this would be easier and faster:

int min = int.MaxValue, max = int.MinValue;
for( int i = 0; i < depthData.Length; i += 2 )
{
    int dist = GetDistance( depthData[i], depthData[i + 1] );
    if( dist < min ) min = dist;
    if( dist > max ) max = dist;
}

Using that depthIndex variable that seems to be declared somewhere else looks dangerous. And the list is just redundant!

其他提示

In order to compute the zMax you can search for the largest value in the depth data array, however to compute zMin you have to search for the smallest value which is larger than FLT_EPSILON (=1.192092896e-07f). The code that implements exactly what you need using the J4K Java for Kinect library is below:

public void onDepthFrameEvent(short[] packed_depth, int[] U, int V[]) {
    DepthMap map=new DepthMap(depthWidth(),depthHeight(),packed_depth);
    float zMIN=4;//The largest possible value
    float zMAX=0;//The smallest possible value
    for(int i=0;i<map.realZ.length;i++)
    {
        if(zMAX<map.realZ[i]) zMAX=map.realZ[i];
        if(map.realZ[i]>DepthMap.FLT_EPSILON && zMIN>map.realZ[i]) zMIN=map.realZ[i];
    }

}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top