|
|
|
@ -4,12 +4,11 @@ using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows.Media.Imaging;
|
|
|
|
|
using System.Windows.Media;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
using System.Windows.Shapes;
|
|
|
|
|
using Lib;
|
|
|
|
|
using System.Windows.Controls;
|
|
|
|
|
using System.Windows;
|
|
|
|
|
|
|
|
|
|
namespace Lib
|
|
|
|
|
{
|
|
|
|
@ -22,6 +21,8 @@ namespace Lib
|
|
|
|
|
set { reader = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//private ColorFrameReader colorReader;
|
|
|
|
|
|
|
|
|
|
private Body[] bodies;
|
|
|
|
|
public Body[] Bodies
|
|
|
|
|
{
|
|
|
|
@ -30,16 +31,12 @@ namespace Lib
|
|
|
|
|
}
|
|
|
|
|
public override void Stop()
|
|
|
|
|
{
|
|
|
|
|
if (reader != null)
|
|
|
|
|
if (Reader != null)
|
|
|
|
|
{
|
|
|
|
|
reader.Dispose();
|
|
|
|
|
reader = null;
|
|
|
|
|
Reader.Dispose();
|
|
|
|
|
Reader = null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private Canvas skeletonCanvas;
|
|
|
|
|
public Canvas SkeletonCanvas {
|
|
|
|
|
get { return skeletonCanvas; }
|
|
|
|
|
private set { skeletonCanvas = value; }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ColorAndBodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
|
|
|
|
@ -50,7 +47,7 @@ namespace Lib
|
|
|
|
|
reader.FrameArrived += Reader_BodyFrameArrived;
|
|
|
|
|
// initialiser le tableau des corps
|
|
|
|
|
this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
|
|
|
|
|
SkeletonCanvas = skeletonCanvas;
|
|
|
|
|
Canvas = skeletonCanvas;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void drawbone(Body body, JointType JointType0, JointType JointType1)
|
|
|
|
@ -71,7 +68,7 @@ namespace Lib
|
|
|
|
|
Y2 = MapJointToScreen(joint1).Y
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
skeletonCanvas.Children.Add(bone);
|
|
|
|
|
Canvas.Children.Add(bone);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -87,89 +84,88 @@ namespace Lib
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void drawskeleton(Body body)
|
|
|
|
|
{
|
|
|
|
|
// tête et cou
|
|
|
|
|
drawbone(body, JointType.Head, JointType.Neck);
|
|
|
|
|
drawbone(body, JointType.Neck, JointType.SpineShoulder);
|
|
|
|
|
|
|
|
|
|
// torse
|
|
|
|
|
drawbone(body, JointType.SpineShoulder, JointType.SpineMid);
|
|
|
|
|
drawbone(body, JointType.SpineMid, JointType.SpineBase);
|
|
|
|
|
drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight);
|
|
|
|
|
drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft);
|
|
|
|
|
drawbone(body, JointType.SpineBase, JointType.HipRight);
|
|
|
|
|
drawbone(body, JointType.SpineBase, JointType.HipLeft);
|
|
|
|
|
|
|
|
|
|
// bras droit
|
|
|
|
|
drawbone(body, JointType.ShoulderRight, JointType.ElbowRight);
|
|
|
|
|
drawbone(body, JointType.ElbowRight, JointType.WristRight);
|
|
|
|
|
drawbone(body, JointType.WristRight, JointType.HandRight);
|
|
|
|
|
drawbone(body, JointType.HandRight, JointType.HandTipRight);
|
|
|
|
|
drawbone(body, JointType.WristRight, JointType.ThumbRight);
|
|
|
|
|
|
|
|
|
|
// bras gauche
|
|
|
|
|
drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft);
|
|
|
|
|
drawbone(body, JointType.ElbowLeft, JointType.WristLeft);
|
|
|
|
|
drawbone(body, JointType.WristLeft, JointType.HandLeft);
|
|
|
|
|
drawbone(body, JointType.HandLeft, JointType.HandTipLeft);
|
|
|
|
|
drawbone(body, JointType.WristLeft, JointType.ThumbLeft);
|
|
|
|
|
|
|
|
|
|
// jambe droite
|
|
|
|
|
drawbone(body, JointType.HipRight, JointType.KneeRight);
|
|
|
|
|
drawbone(body, JointType.KneeRight, JointType.AnkleRight);
|
|
|
|
|
drawbone(body, JointType.AnkleRight, JointType.FootRight);
|
|
|
|
|
|
|
|
|
|
// jambe gauche
|
|
|
|
|
drawbone(body, JointType.HipLeft, JointType.KneeLeft);
|
|
|
|
|
drawbone(body, JointType.KneeLeft, JointType.AnkleLeft);
|
|
|
|
|
drawbone(body, JointType.AnkleLeft, JointType.FootLeft);
|
|
|
|
|
|
|
|
|
|
// dessinez les joints
|
|
|
|
|
foreach (JointType JointType in body.Joints.Keys)
|
|
|
|
|
{
|
|
|
|
|
// tête et cou
|
|
|
|
|
drawbone(body, JointType.Head, JointType.Neck);
|
|
|
|
|
drawbone(body, JointType.Neck, JointType.SpineShoulder);
|
|
|
|
|
|
|
|
|
|
// torse
|
|
|
|
|
drawbone(body, JointType.SpineShoulder, JointType.SpineMid);
|
|
|
|
|
drawbone(body, JointType.SpineMid, JointType.SpineBase);
|
|
|
|
|
drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight);
|
|
|
|
|
drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft);
|
|
|
|
|
drawbone(body, JointType.SpineBase, JointType.HipRight);
|
|
|
|
|
drawbone(body, JointType.SpineBase, JointType.HipLeft);
|
|
|
|
|
|
|
|
|
|
// bras droit
|
|
|
|
|
drawbone(body, JointType.ShoulderRight, JointType.ElbowRight);
|
|
|
|
|
drawbone(body, JointType.ElbowRight, JointType.WristRight);
|
|
|
|
|
drawbone(body, JointType.WristRight, JointType.HandRight);
|
|
|
|
|
drawbone(body, JointType.HandRight, JointType.HandTipRight);
|
|
|
|
|
drawbone(body, JointType.WristRight, JointType.ThumbRight);
|
|
|
|
|
|
|
|
|
|
// bras gauche
|
|
|
|
|
drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft);
|
|
|
|
|
drawbone(body, JointType.ElbowLeft, JointType.WristLeft);
|
|
|
|
|
drawbone(body, JointType.WristLeft, JointType.HandLeft);
|
|
|
|
|
drawbone(body, JointType.HandLeft, JointType.HandTipLeft);
|
|
|
|
|
drawbone(body, JointType.WristLeft, JointType.ThumbLeft);
|
|
|
|
|
|
|
|
|
|
// jambe droite
|
|
|
|
|
drawbone(body, JointType.HipRight, JointType.KneeRight);
|
|
|
|
|
drawbone(body, JointType.KneeRight, JointType.AnkleRight);
|
|
|
|
|
drawbone(body, JointType.AnkleRight, JointType.FootRight);
|
|
|
|
|
|
|
|
|
|
// jambe gauche
|
|
|
|
|
drawbone(body, JointType.HipLeft, JointType.KneeLeft);
|
|
|
|
|
drawbone(body, JointType.KneeLeft, JointType.AnkleLeft);
|
|
|
|
|
drawbone(body, JointType.AnkleLeft, JointType.FootLeft);
|
|
|
|
|
|
|
|
|
|
// dessinez les joints
|
|
|
|
|
foreach (JointType JointType in body.Joints.Keys)
|
|
|
|
|
Joint joint = body.Joints[JointType];
|
|
|
|
|
if (joint.TrackingState == TrackingState.Tracked)
|
|
|
|
|
{
|
|
|
|
|
Joint joint = body.Joints[JointType];
|
|
|
|
|
if (joint.TrackingState == TrackingState.Tracked)
|
|
|
|
|
{
|
|
|
|
|
DrawJoint(MapJointToScreen(joint));
|
|
|
|
|
}
|
|
|
|
|
DrawJoint(MapJointToScreen(joint));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DrawJoint(Point point)
|
|
|
|
|
private void DrawJoint(Point point)
|
|
|
|
|
{
|
|
|
|
|
Ellipse ellipse = new Ellipse
|
|
|
|
|
{
|
|
|
|
|
Ellipse ellipse = new Ellipse
|
|
|
|
|
{
|
|
|
|
|
Width = 10,
|
|
|
|
|
Height = 10,
|
|
|
|
|
Fill = new SolidColorBrush(Colors.Red)
|
|
|
|
|
};
|
|
|
|
|
Width = 10,
|
|
|
|
|
Height = 10,
|
|
|
|
|
Fill = new SolidColorBrush(Colors.Red)
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
|
|
|
|
|
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
|
|
|
|
|
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
|
|
|
|
|
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
|
|
|
|
|
|
|
|
|
|
skeletonCanvas.Children.Add(ellipse);
|
|
|
|
|
}
|
|
|
|
|
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
|
|
|
|
|
Canvas.Children.Add(ellipse);
|
|
|
|
|
}
|
|
|
|
|
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
using (var bodyframe = e.FrameReference.AcquireFrame())
|
|
|
|
|
{
|
|
|
|
|
using (var bodyframe = e.FrameReference.AcquireFrame())
|
|
|
|
|
if (bodyframe != null)
|
|
|
|
|
{
|
|
|
|
|
if (bodyframe != null)
|
|
|
|
|
{
|
|
|
|
|
bodyframe.GetAndRefreshBodyData(this.bodies);
|
|
|
|
|
bodyframe.GetAndRefreshBodyData(this.bodies);
|
|
|
|
|
|
|
|
|
|
SkeletonCanvas.Children.Clear(); // nettoyer le Canvas avant de dessiner
|
|
|
|
|
Canvas.Children.Clear(); // nettoyer le Canvas avant de dessiner
|
|
|
|
|
|
|
|
|
|
foreach (var body in this.bodies)
|
|
|
|
|
foreach (var body in this.bodies)
|
|
|
|
|
{
|
|
|
|
|
if (body.IsTracked)
|
|
|
|
|
{
|
|
|
|
|
if (body.IsTracked)
|
|
|
|
|
{
|
|
|
|
|
// dessiner le squelette
|
|
|
|
|
drawskeleton(body);
|
|
|
|
|
}
|
|
|
|
|
// dessiner le squelette
|
|
|
|
|
drawskeleton(body);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|