How to get the position (x,y) from a Kinect depth array?

你离开我真会死。 提交于 2019-12-05 22:12:32

Assuming depth is a byte array with 2 * width bytes per row, and height rows, try something like this:

var points = new List<Point>();
for( int y = 0; y < height; y++ )
    for( int x = 0; x < width; x++ )
    {
        int i = y * width * 2 + x * 2;
        int dist = GetDistance( depth[i], depth[i + 1] );

        if( dist < z2 && dist > z1 )
            points.Add( new Point( x, y ) );
    }

You'll obviously have to replace Point with some type to represent an int x/y pair!

You could also do it with a simple for (int i = 0; i < depth.Length; i += 2) as before, and then calculate the x/y values from i. (Hint: the modulus operator will give you the x value, and a simple integer division will get you y, more or less)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!