|
|
@ -69,7 +69,7 @@ namespace WpfApp
|
|
|
|
// Initialiser la Kinect
|
|
|
|
// Initialiser la Kinect
|
|
|
|
this.kinectSensor = KinectSensor.GetDefault();
|
|
|
|
this.kinectSensor = KinectSensor.GetDefault();
|
|
|
|
|
|
|
|
|
|
|
|
/* Capteur couleur
|
|
|
|
// Capteur couleur
|
|
|
|
// Ouvrir le lecteur de flux de couleur
|
|
|
|
// Ouvrir le lecteur de flux de couleur
|
|
|
|
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
|
|
|
|
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
|
|
|
|
|
|
|
|
|
|
|
@ -81,7 +81,6 @@ namespace WpfApp
|
|
|
|
|
|
|
|
|
|
|
|
// Gérer l'événement FrameArrived pour le flux de couleur
|
|
|
|
// Gérer l'événement FrameArrived pour le flux de couleur
|
|
|
|
this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
|
|
|
|
this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialisation du BodyFrameReader
|
|
|
|
// Initialisation du BodyFrameReader
|
|
|
|
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
|
|
|
|
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
|
|
|
@ -102,8 +101,8 @@ namespace WpfApp
|
|
|
|
|
|
|
|
|
|
|
|
// Initialisez depthBitmap pour afficher les données de profondeur
|
|
|
|
// Initialisez depthBitmap pour afficher les données de profondeur
|
|
|
|
this.depthBitmap = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
|
|
|
|
this.depthBitmap = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Capteur infra
|
|
|
|
// Initialisation du InfraredFrameReader
|
|
|
|
// Initialisation du InfraredFrameReader
|
|
|
|
this.infraredFrameReader = this.kinectSensor.InfraredFrameSource.OpenReader();
|
|
|
|
this.infraredFrameReader = this.kinectSensor.InfraredFrameSource.OpenReader();
|
|
|
|
this.infraredFrameReader.FrameArrived += this.Reader_InfraredFrameArrived;
|
|
|
|
this.infraredFrameReader.FrameArrived += this.Reader_InfraredFrameArrived;
|
|
|
@ -115,6 +114,7 @@ namespace WpfApp
|
|
|
|
|
|
|
|
|
|
|
|
// Initialisez infraredBitmap pour afficher les données infrarouges
|
|
|
|
// Initialisez infraredBitmap pour afficher les données infrarouges
|
|
|
|
this.infraredBitmap = new WriteableBitmap(infraredFrameDescription.Width, infraredFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
|
|
|
|
this.infraredBitmap = new WriteableBitmap(infraredFrameDescription.Width, infraredFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
this.kinectSensor.Open();
|
|
|
@ -187,25 +187,54 @@ namespace WpfApp
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawSkeleton(Body body)
|
|
|
|
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)
|
|
|
|
foreach (JointType jointType in body.Joints.Keys)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Joint joint = body.Joints[jointType];
|
|
|
|
Joint joint = body.Joints[jointType];
|
|
|
|
if (joint.TrackingState == TrackingState.Tracked)
|
|
|
|
if (joint.TrackingState == TrackingState.Tracked)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Convertir les coordonnées du joint en coordonnées de l'écran
|
|
|
|
DrawJoint(MapJointToScreen(joint));
|
|
|
|
Point point = new Point();
|
|
|
|
|
|
|
|
ColorSpacePoint colorPoint = this.kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
|
|
|
|
|
|
|
|
point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
|
|
|
|
|
|
|
|
point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Dessiner le joint
|
|
|
|
|
|
|
|
DrawJoint(point);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Dessinez les os ici si nécessaire
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawJoint(Point point)
|
|
|
|
private void DrawJoint(Point point)
|
|
|
@ -223,6 +252,42 @@ namespace WpfApp
|
|
|
|
skeletonCanvas.Children.Add(ellipse);
|
|
|
|
skeletonCanvas.Children.Add(ellipse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawBone(Body body, JointType jointType0, JointType jointType1)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Joint joint0 = body.Joints[jointType0];
|
|
|
|
|
|
|
|
Joint joint1 = body.Joints[jointType1];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Ne dessinez que si les deux joints sont suivis
|
|
|
|
|
|
|
|
if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Line bone = new Line
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Stroke = new SolidColorBrush(Colors.LightBlue),
|
|
|
|
|
|
|
|
StrokeThickness = 4,
|
|
|
|
|
|
|
|
X1 = MapJointToScreen(joint0).X,
|
|
|
|
|
|
|
|
Y1 = MapJointToScreen(joint0).Y,
|
|
|
|
|
|
|
|
X2 = MapJointToScreen(joint1).X,
|
|
|
|
|
|
|
|
Y2 = MapJointToScreen(joint1).Y
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
skeletonCanvas.Children.Add(bone);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Point MapJointToScreen(Joint joint)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ColorSpacePoint colorPoint = this.kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Gestion des coordonnées infinies
|
|
|
|
|
|
|
|
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
|
|
|
|
|
|
|
|
float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new Point(x, y);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Reader_DepthFrameArrived(object sender, DepthFrameArrivedEventArgs e)
|
|
|
|
private void Reader_DepthFrameArrived(object sender, DepthFrameArrivedEventArgs e)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
|
|
|
|
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
|
|
|
|