我知道如何以像素为单位转换从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
. 参考前面的例子,我想获得两个 3D 数组rightHandPosition
和leftHandPosition
,最后一个坐标代表深度。什么是正确的公式来转换从相应的值返回rightHand.Position.Z
的leftHand.Position.Z
值(以毫米为单位)?
编辑:上面代码中用于以像素为单位转换 X 和 Y 坐标的公式是错误的。请阅读我的以下答案。