【发布时间】:2015-06-17 06:28:12
【问题描述】:
我在 1920*1080 的彩色像素中有某些点 X、Y。我不知道如何在深度数据 512×424 中映射该特定点。我知道我需要使用坐标映射器,但不知道该怎么做。我是 Kinect 的初学者,我正在使用 C#。有人请帮助我
【问题讨论】:
-
只是几个点,不是所有点?
标签: c# kinect kinect-sdk
我在 1920*1080 的彩色像素中有某些点 X、Y。我不知道如何在深度数据 512×424 中映射该特定点。我知道我需要使用坐标映射器,但不知道该怎么做。我是 Kinect 的初学者,我正在使用 C#。有人请帮助我
【问题讨论】:
标签: c# kinect kinect-sdk
如果要从Color frame映射到Depth frame,需要使用MapColorFrameToDepthSpace方法:
ushort[] depthData = ... // Data from the Depth Frame
DepthSpacePoint[] result = new DepthSpacePoint[512 * 424];
_sensor.CoordinateMapper.MapColorFrameToDepthSpace(depthData, result);
您需要为该方法提供 2 个参数:
提供这些参数后,空数组将填充正确的 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:
我要将CameraSpacePoint、DepthSpacePoint、ColorSpacePoint 存储到数组中,因为CoordinateMapper 类中方法的参数是数组。更多信息,请查看CoordinateMapper Method Reference
此博客可能会对您有所帮助。 Understanding Kinect Coordinate Mapping
【讨论】: