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

本文关键字:深度 像素 颜色 Kinect 查找 | 更新日期: 2023-09-27 17:56:34

我在1920*1080的彩色像素中有一些点X,Y。我不知道如何在深度数据 512×424 中映射该特定点。我知道我需要使用坐标映射器,但无法弄清楚如何做到这一点。我是 Kinect 的初学者,我使用的是 C#。有人请帮我

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

如果要将FROM Color frame映射到Depthframe,则需要使用方法MapColorFrameToDepthSpace:

ushort[] depthData = ... // Data from the Depth Frame
DepthSpacePoint[] result = new DepthSpacePoint[512 * 424];
_sensor.CoordinateMapper.MapColorFrameToDepthSpace(depthData, result);

您需要为此方法提供 2 个参数:

  1. 完整的深度帧数据(如下所示)。
  2. DepthSpacePoints的空数组。

提供这些参数,空数组将使用正确的 DepthSpacePoint 值填充。

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

下面是一个例子,我将一个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类中方法的参数是数组。有关更多信息,请查看 坐标映射器方法参考

  2. 这个博客可能会对你有所帮助。了解 Kinect 坐标映射