c# - 如何从 Kinect 深度数组中获取位置 (x,y)?

标签 c# arrays kinect depth object-recognition

在使用 kinect 时,我发现位图及其深度信息不可靠,并且由于某种原因比来自实际字节数组的数据更受干扰。

当我尝试通过像这样访问位图来获取最小值和最大值时,我意识到了这一点

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]);

但另一方面,当我使用这种方法直接访问深度字节数组时(正如 Stackoverflow 成员 Chris 指出的,谢谢 Chris),我取得了更好的结果:

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

我的问题是:

  • 我想统计一定距离区间内的所有点。
  • 然后我想得到他们的实际位置 (x,y)。

如何获取位置或直接将这些点添加到列表中 - 以便采取进一步行动?

我的最终目标是通过计算特定区间内的像素数量来识别特定的预定义对象(例如,将球与 block 区分开来)。

for (int i = 0; i < depth.Length; i += 2)
{
  int dist = GetDistance(depth[i], depth[i + 1]);

  if (dist < z2 && dist > z1) 
    a++;
}

最佳答案

假设depth是一个带有 2 * width 的字节数组每行字节数,height行,尝试这样的事情:

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

您显然必须替换 Point用某种类型来表示一个 int x/y 对!

您也可以使用简单的 for (int i = 0; i < depth.Length; i += 2) 来做到这一点和以前一样,然后从 i 计算 x/y 值. (提示:模数运算符会给你 x 值,一个简单的整数除法会给你或多或少的 y)

关于c# - 如何从 Kinect 深度数组中获取位置 (x,y)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19933755/

相关文章:

C#如何将不同按钮的按钮文本设置到同一个文本框

c# - 为什么我的 INSERT 语句会产生重复?

c# - 如何动态加载 DLL 并在其中使用类(实现已知接口(interface))[C#]

php - 根据键拆分关联数组

background - Unity 中的 Kinect 游戏 : How to do background removal

c# - KinectColorViewer 和 SDK 1.6

matlab - 从 Kinect 接收到的深度图像是什么

c# - asp.net v4 中循环内的异步任务

arrays - Matlab:如何随机打乱矩阵的列

arrays - 从向量中获取向量矩阵