我知道如何将从 Joint.Position.X
和 Joint.Position.Y
获取到的值转换为像素。以下是一个示例:
void kinectSensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
if (skeletonFrame != null)
{
Skeleton[] skeletonData = new Skeleton[skeletonFrame.SkeletonArrayLength]; //conterrà tutti gli skeleton
skeletonFrame.CopySkeletonDataTo(skeletonData);
Skeleton playerSkeleton = (from s in skeletonData where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault();
if (playerSkeleton != null)
{
Joint rightHand = playerSkeleton.Joints[JointType.HandRight];
Joint leftHand = playerSkeleton.Joints[JointType.HandLeft];
//EDIT: The following formulas used to convert X and Y coordinates in pixels are wrong.
//Please, see the answer for details
rightHandPosition = new float[] { (((0.5f * rightHand.Position.X) + 0.5f) * (640)), (((-0.5f * rightHand.Position.Y) + 0.5f) * (480)) };
leftHandPosition = new float[] { (((0.5f * leftHand.Position.X) + 0.5f) * (640)), (((-0.5f * leftHand.Position.Y) + 0.5f) * (480)), leftHand.Position.Z };
}
}
}
}
现在,我想要做的是使用
Joint.Depth.Z
获得真实的深度(以毫米为单位)。参考之前的示例,我想要获取rightHandPosition
和leftHandPosition
的两个3D数组,其中最后一个坐标表示深度。为了将从rightHand.Position.Z
和leftHand.Position.Z
返回的值转换为相应的毫米值,正确的公式是什么?编辑:上面代码中用于转换X和Y像素坐标的公式是错误的,请阅读我下面的回答。
Position.Z
返回的数值单位为米。 - Nicholas Pappas