我正在寻找一种能够画出最近骨骼骨骼的解决方案。我编写了代码来绘制第一个跟踪骨架的骨骼。如果第二个人比第一个人更接近我想画第二个骨架的骨头。也许有人知道该怎么做?
void sensor_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e)
{
using (SkeletonFrame skeletonFrame = e.OpenSkeletonFrame())
{
// check for frame drop.
if (skeletonFrame == null)
{
return;
}
// copy the frame data in to the collection
skeletonFrame.CopySkeletonDataTo(totalSkeleton);
// get the first Tracked skeleton
skeleton = (from trackskeleton in totalSkeleton
where trackskeleton.TrackingState == SkeletonTrackingState.Tracked
select trackskeleton).FirstOrDefault();
if (skeleton != null)
{
if (skeleton.Joints[JointType.ShoulderCenter].TrackingState == JointTrackingState.Tracked && skeleton.Joints[JointType.Head].TrackingState == JointTrackingState.Tracked)
{
myCanvas.Children.Clear();
this.DrawHead();
}
}
}
}
// Draws the head.
private void DrawHead()
{
if (skeleton != null)
{
drawBone(skeleton.Joints[JointType.ShoulderCenter], skeleton.Joints[JointType.Head]);
}
}
// Draws the bone.
void drawBone(Joint trackedJoint1, Joint trackedJoint2)
{
Line skeletonBone = new Line();
skeletonBone.Stroke = Brushes.Black;
skeletonBone.StrokeThickness = 3;
Point joint1 = this.ScalePosition(trackedJoint1.Position);
skeletonBone.X1 = joint1.X;
skeletonBone.Y1 = joint1.Y;
Point joint2 = this.ScalePosition(trackedJoint2.Position);
skeletonBone.X2 = joint2.X;
skeletonBone.Y2 = joint2.Y;
myCanvas.Children.Add(skeletonBone);
}
/// <summary>
/// Scales the position.
/// </summary>
/// <param name="skeletonPoint">The skeltonpoint.</param>
/// <returns></returns>
private Point ScalePosition(SkeletonPoint skeletonPoint)
{
// return the depth points from the skeleton point
DepthImagePoint depthPoint = this.sensor.CoordinateMapper.MapSkeletonPointToDepthPoint(skeletonPoint, DepthImageFormat.Resolution640x480Fps30);
return new Point(depthPoint.X, depthPoint.Y);
}
答案 0 :(得分:0)
定义一个特定的阈值,如果骨骼在该阈值之后,则在画布上绘制连接x,y坐标。您必须添加代码以相应地更新精灵的位置。