0
我正在尋找解決方案來繪製最接近骨骼的骨骼。我寫了代碼來繪製第一個跟蹤骨骼的骨骼。如果第二個人比第一個人更近,我想繪製第二個骨骼的骨骼。也許有人有任何想法如何做到這一點?繪製2個跟蹤骨骼的最接近骨(肩 - 頭)Kinect SDK v1.6
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);
}
調整縮進代碼 – 2015-03-07 08:37:32