|
|
@ -25,6 +25,9 @@ namespace WpfApp
|
|
|
|
private ColorFrameReader colorFrameReader = null;
|
|
|
|
private ColorFrameReader colorFrameReader = null;
|
|
|
|
private WriteableBitmap colorBitmap = null;
|
|
|
|
private WriteableBitmap colorBitmap = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private BodyFrameReader bodyFrameReader = null;
|
|
|
|
|
|
|
|
private Body[] bodies = null;
|
|
|
|
|
|
|
|
|
|
|
|
// Propriété publique pour le binding
|
|
|
|
// Propriété publique pour le binding
|
|
|
|
public WriteableBitmap ColorBitmap
|
|
|
|
public WriteableBitmap ColorBitmap
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -53,6 +56,13 @@ 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
|
|
|
|
|
|
|
|
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
|
|
|
|
|
|
|
|
this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialiser le tableau des corps
|
|
|
|
|
|
|
|
this.bodies = new Body[this.kinectSensor.BodyFrameSource.BodyCount];
|
|
|
|
|
|
|
|
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -101,5 +111,63 @@ namespace WpfApp
|
|
|
|
this.kinectSensor = null;
|
|
|
|
this.kinectSensor = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (var bodyFrame = e.FrameReference.AcquireFrame())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (bodyFrame != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bodyFrame.GetAndRefreshBodyData(this.bodies);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
skeletonCanvas.Children.Clear(); // Nettoyer le canvas avant de dessiner
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var body in this.bodies)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (body.IsTracked)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Dessiner le squelette
|
|
|
|
|
|
|
|
DrawSkeleton(body);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void DrawSkeleton(Body body)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
foreach (JointType jointType in body.Joints.Keys)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Joint joint = body.Joints[jointType];
|
|
|
|
|
|
|
|
if (joint.TrackingState == TrackingState.Tracked)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Convertir les coordonnées du joint en coordonnées de l'écran
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Ellipse ellipse = new Ellipse
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
skeletonCanvas.Children.Add(ellipse);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|