首页 文章

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

提问于
浏览
0

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

2 回答

  • 1

    如果要将“颜色”框架映射到“深度”框架,则需要使用方法MapColorFrameToDepthSpace:

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

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

    • 完整的深度帧数据(如this) .

    • DepthSpacePoints的空数组 .

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

    否则,拉法夫的回答就是你所需要的 .

  • 1

    以下是一个示例,我已将 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:

相关问题