Microsoft Kinect SDK深度数据到真实世界的坐标

时间:2012-01-09 23:29:29

标签: kinect

我正在使用Microsoft Kinect SDK从Kinect获取深度和颜色信息,然后将该信息转换为点云。我需要深度信息在真实世界坐标中,以相机中心为原点。

我见过很多转换函数,但这些函数显然适用于OpenNI和非Microsoft驱动程序。我已经读过来自Kinect的深度信息已经以毫米为单位,并且包含在11位......或其他内容中。

如何将此位信息转换为我可以使用的真实世界坐标?

提前致谢!

1 个答案:

答案 0 :(得分:10)

使用 Microsoft.Research.Kinect.Nui.SkeletonEngine类以及以下方法在Kinect for Windows库中进行此操作:

public Vector DepthImageToSkeleton (
    float depthX,
    float depthY,
    short depthValue
)

此方法将基于真实世界的测量结果将Kinect生成的深度图像映射到矢量可缩放的深度图像。

从那里(当我在过去创建网格时),在枚举由Kinect深度图像创建的位图中的字节数组之后,您创建一个类似于以下的Vector点的新列表:

        var width = image.Image.Width;
        var height = image.Image.Height;
        var greyIndex = 0;

        var points = new List<Vector>();

        for (var y = 0; y < height; y++)
        {
            for (var x = 0; x < width; x++)
            {
                short depth;
                switch (image.Type)
                {
                    case ImageType.DepthAndPlayerIndex:
                        depth = (short)((image.Image.Bits[greyIndex] >> 3) | (image.Image.Bits[greyIndex + 1] << 5));
                        if (depth <= maximumDepth)
                        {
                            points.Add(nui.SkeletonEngine.DepthImageToSkeleton(((float)x / image.Image.Width), ((float)y / image.Image.Height), (short)(depth << 3)));
                        }
                        break;
                    case ImageType.Depth: // depth comes back mirrored
                        depth = (short)((image.Image.Bits[greyIndex] | image.Image.Bits[greyIndex + 1] << 8));
                        if (depth <= maximumDepth)
                        {
                            points.Add(nui.SkeletonEngine.DepthImageToSkeleton(((float)(width - x - 1) / image.Image.Width), ((float)y / image.Image.Height), (short)(depth << 3)));
                        }
                        break;
                }

                greyIndex += 2;
            }
        }

通过这样做,最终结果是以毫米为单位存储的向量列表,如果你想要厘米乘以100(等等)。

相关问题