|
|
@ -22,18 +22,31 @@ namespace WpfApp
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
public partial class MainWindow : Window
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private KinectSensor kinectSensor = null;
|
|
|
|
private KinectSensor kinectSensor = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Attribut captor color
|
|
|
|
private ColorFrameReader colorFrameReader = null;
|
|
|
|
private ColorFrameReader colorFrameReader = null;
|
|
|
|
private WriteableBitmap colorBitmap = null;
|
|
|
|
private WriteableBitmap colorBitmap = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Attribut captor Body
|
|
|
|
private BodyFrameReader bodyFrameReader = null;
|
|
|
|
private BodyFrameReader bodyFrameReader = null;
|
|
|
|
private Body[] bodies = null;
|
|
|
|
private Body[] bodies = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Attribut captor Depth
|
|
|
|
|
|
|
|
private DepthFrameReader depthFrameReader = null;
|
|
|
|
|
|
|
|
private WriteableBitmap depthBitmap = null;
|
|
|
|
|
|
|
|
private byte[] depthPixels;
|
|
|
|
|
|
|
|
|
|
|
|
// Propriété publique pour le binding
|
|
|
|
// Propriété publique pour le binding
|
|
|
|
public WriteableBitmap ColorBitmap
|
|
|
|
public WriteableBitmap ColorBitmap
|
|
|
|
{
|
|
|
|
{
|
|
|
|
get { return this.colorBitmap; }
|
|
|
|
get { return this.colorBitmap; }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public WriteableBitmap DepthBitmap
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get { return this.depthBitmap; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public MainWindow()
|
|
|
|
public MainWindow()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
InitializeComponent();
|
|
|
|
InitializeComponent();
|
|
|
@ -44,6 +57,7 @@ namespace WpfApp
|
|
|
|
// Initialiser la Kinect
|
|
|
|
// Initialiser la Kinect
|
|
|
|
this.kinectSensor = KinectSensor.GetDefault();
|
|
|
|
this.kinectSensor = KinectSensor.GetDefault();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* 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();
|
|
|
|
|
|
|
|
|
|
|
@ -55,6 +69,7 @@ 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();
|
|
|
@ -63,6 +78,18 @@ namespace WpfApp
|
|
|
|
// Initialiser le tableau des corps
|
|
|
|
// Initialiser le tableau des corps
|
|
|
|
this.bodies = new Body[this.kinectSensor.BodyFrameSource.BodyCount];
|
|
|
|
this.bodies = new Body[this.kinectSensor.BodyFrameSource.BodyCount];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialisation du DepthFrameReader
|
|
|
|
|
|
|
|
this.depthFrameReader = this.kinectSensor.DepthFrameSource.OpenReader();
|
|
|
|
|
|
|
|
this.depthFrameReader.FrameArrived += this.Reader_DepthFrameArrived;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
FrameDescription depthFrameDescription = this.kinectSensor.DepthFrameSource.FrameDescription;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialisez depthPixels pour stocker les données de chaque pixel
|
|
|
|
|
|
|
|
this.depthPixels = new byte[depthFrameDescription.Width * depthFrameDescription.Height];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Initialisez depthBitmap pour afficher les données de profondeur
|
|
|
|
|
|
|
|
this.depthBitmap = new WriteableBitmap(depthFrameDescription.Width, depthFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
|
|
|
|
|
|
|
|
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -169,5 +196,41 @@ namespace WpfApp
|
|
|
|
|
|
|
|
|
|
|
|
skeletonCanvas.Children.Add(ellipse);
|
|
|
|
skeletonCanvas.Children.Add(ellipse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void Reader_DepthFrameArrived(object sender, DepthFrameArrivedEventArgs e)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (depthFrame != null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
FrameDescription depthFrameDescription = depthFrame.FrameDescription;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Créez un tableau pour stocker les données de profondeur
|
|
|
|
|
|
|
|
ushort[] depthData = new ushort[depthFrameDescription.LengthInPixels];
|
|
|
|
|
|
|
|
depthFrame.CopyFrameDataToArray(depthData);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Traitez les données de profondeur
|
|
|
|
|
|
|
|
ProcessDepthFrameData(depthData, depthFrameDescription.LengthInPixels, depthFrame.DepthMinReliableDistance, depthFrame.DepthMaxReliableDistance);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Mettez à jour le bitmap de profondeur
|
|
|
|
|
|
|
|
this.depthBitmap.WritePixels(
|
|
|
|
|
|
|
|
new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height),
|
|
|
|
|
|
|
|
this.depthPixels,
|
|
|
|
|
|
|
|
depthFrameDescription.Width,
|
|
|
|
|
|
|
|
0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void ProcessDepthFrameData(ushort[] depthData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
// Convertir les données de profondeur en niveaux de gris
|
|
|
|
|
|
|
|
for (int i = 0; i < depthFrameDataSize; ++i)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
ushort depth = depthData[i];
|
|
|
|
|
|
|
|
this.depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth % 256) : 0);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|