如何从一个超高动力学深度阵列的位置(x,y)的? [英] How to get the position (x,y) from a Kinect depth array?

查看:229
本文介绍了如何从一个超高动力学深度阵列的位置(x,y)的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

虽然与Kinect的工作,我发现,位图和深度信息是不可靠的,由于某种原因不是从实际的字节数组的数据更加不安。

我意识到这一点时,我试图通过访问这样的位图得到最小值和最大值

 为(VAR Y = 0; Y<高度; Y ++)
{
  VAR heightOffset = Y *宽度;
  为(变量X = 0; X&下;宽度; X ++)
  {
    VAR指数=((宽 - X - 1)+ heightOffset)* 4;
    VAR距离= getDistance的(深度[depthIndex]深度[depthIndex + 1]);

但在另一方面,我取得更好的结果,当我直接访问深度字节数组(作为成员#1克里斯指出,谢谢你,克里斯),用这种方法:

  INT MIN2 = int.MaxValue,MAX2 = int.MinValue;
的for(int i = 0; I< depth.Length;我+ = 2)
{
  INT DIST = getDistance的(深度[I]中,深度第[i + 1]);
  如果(DIST< MIN2和放大器;&安培; DIST大于0)
    MIN2 = DIST;  如果(DIST> MAX2)
    MAX2 = DIST;
}

我的问题是:


  • 我要在一定距离范围内INTERVALL指望所有的点。

  • 然后,我希望得到他们的实际位置(X,Y)。

我怎样才能得到的位置,或直接这些点添加到列表 - 采取进一步行动。

我的最终目标是通过(例如从一个块到不同球)计数一定INTERVALL内的像素的数目,以确定某些predefined对象

 的for(int i = 0; I< depth.Length;我+ = 2)
{
  INT DIST = getDistance的(深度[I]中,深度第[i + 1]);  如果(DIST< Z2和放大器;&安培; DIST> Z1)
    一个++;
}


解决方案

假设深度字节数组2 *宽每行的字节,而高度行,尝试这样的事情:

  VAR点=新的List<点和GT;();
对于(INT Y = 0; Y<高度; Y ++)
    对于(INT X = 0; X<宽度; X ++)
    {
        INT I = Y *宽* 2 + X * 2;
        INT DIST = getDistance的(深度[I]中,深度第[i + 1]);        如果(DIST< Z2和放大器;&安培; DIST> Z1)
            points.Add(新点(X,Y));
    }

您会明显地必须更换某种类型的重新present一个int x / y的对!

您也可以用一个简单的做​​的for(int i = 0; I< depth.Length;我+ = 2)和以前一样,然后计算从 X / Y值我。 (提示:模运算会给你的x值,和一个简单的整数除法将让你Y,或多或少)

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++;
}

解决方案

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)

这篇关于如何从一个超高动力学深度阵列的位置(x,y)的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆