在 Kinect 中查找颜色像素的深度值

Finding Depth value for Color Pixels in Kinect

我在 1920*1080 的颜色像素中有某些点 X,Y。我不知道如何在深度数据 512×424 中映射那个特定点。我知道我需要使用坐标映射器,但不知道该怎么做。我是 Kinect 的初学者,我正在使用 C#。有人请帮助我

下面是一个示例,我将 CameraSpacePoint 转换为 ColorSpacePoint 并将相同的 CameraSpacePoint 转换为 DepthSpacePoint

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kinect;

namespace Coordinate_Mapper
{
    class Program
    {
        public static KinectSensor ks;
        public static MultiSourceFrameReader msfr;
        public static Body[] bodies;
        public static CameraSpacePoint[] cameraSpacePoints;
        public static DepthSpacePoint[] depthSpacePoints;
        public static ColorSpacePoint[] colorSpacePoints;

        static void Main(string[] args)
        {
            ks = KinectSensor.GetDefault();
            ks.Open();
            bodies = new Body[ks.BodyFrameSource.BodyCount];
            cameraSpacePoints = new CameraSpacePoint[1];
            colorSpacePoints = new ColorSpacePoint[1];
            depthSpacePoints = new DepthSpacePoint[1];

            msfr = ks.OpenMultiSourceFrameReader(FrameSourceTypes.Depth | FrameSourceTypes.Color | FrameSourceTypes.Body);
            msfr.MultiSourceFrameArrived += msfr_MultiSourceFrameArrived;

            Console.ReadKey();
        }

        static void msfr_MultiSourceFrameArrived(object sender, MultiSourceFrameArrivedEventArgs e)
        {
            if (e.FrameReference == null) return;
            MultiSourceFrame multiframe = e.FrameReference.AcquireFrame();
            if (multiframe == null) return;

            if (multiframe.BodyFrameReference != null)
            {
                using (var bf = multiframe.BodyFrameReference.AcquireFrame())
                {
                    bf.GetAndRefreshBodyData(bodies);
                    foreach (var body in bodies)
                    {
                        if (!body.IsTracked) continue;
                        // CameraSpacePoint
                        cameraSpacePoints[0] = body.Joints[0].Position;
                        Console.WriteLine("{0} {1} {2}", cameraSpacePoints[0].X, cameraSpacePoints[0].Y, cameraSpacePoints[0].Z);

                        // CameraSpacePoints => ColorSpacePoints
                        ks.CoordinateMapper.MapCameraPointsToColorSpace(cameraSpacePoints, colorSpacePoints);
                        Console.WriteLine("ColorSpacePoint : {0} {1}", colorSpacePoints[0].X, colorSpacePoints[0].Y);

                        // CameraSpacePoints => DepthSpacePoints
                        ks.CoordinateMapper.MapCameraPointsToDepthSpace(cameraSpacePoints, depthSpacePoints);
                        Console.WriteLine("DepthSpacePoint : {0} {1}", depthSpacePoints[0].X, depthSpacePoints[0].Y);
                    }
                }
            }
        }
    }
}

N:B:

  1. 我想把CameraSpacePointDepthSpacePointColorSpacePoint存储到数组中,因为CoordinateMapper[=35=中方法的参数] 是数组。更多内容,请查看CoordinateMapper Method Reference

  2. 这篇博客可能会对您有所帮助。 Understanding Kinect Coordinate Mapping

如果要从颜色框映射到深度框,需要使用方法 MapColorFrameToDepthSpace:

ushort[] depthData = ... // Data from the Depth Frame
DepthSpacePoint[] result = new DepthSpacePoint[512 * 424];

_sensor.CoordinateMapper.MapColorFrameToDepthSpace(depthData, result);

您需要为该方法提供两个参数:

  1. 完整的深度帧数据(如this)。
  2. 一个空的 DepthSpacePoints 数组。

提供这些参数,空数组将填充适当的 DepthSpacePoint 值。

否则,拉法夫的答案就是您所需要的。