|
|
|
@ -1,6 +1,7 @@
|
|
|
|
|
using Microsoft.Kinect;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
@ -28,32 +29,39 @@ namespace WpfApp
|
|
|
|
|
public MainWindow()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
Debug.WriteLine("Initialisation de Kinect...");
|
|
|
|
|
|
|
|
|
|
// Initialiser la Kinect
|
|
|
|
|
this.kinectSensor = KinectSensor.GetDefault();
|
|
|
|
|
|
|
|
|
|
// Ouvrir le lecteur de flux de couleur
|
|
|
|
|
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
|
|
|
|
|
|
|
|
|
|
// Frame description pour les images de couleur
|
|
|
|
|
FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
|
|
|
|
|
|
|
|
|
|
// Créer le bitmap pour afficher l'image
|
|
|
|
|
this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
|
|
|
|
|
|
|
|
|
|
// Gérer l'événement FrameArrived pour le flux de couleur
|
|
|
|
|
this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
|
|
|
|
|
|
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
|
if (this.kinectSensor != null)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Kinect détecté.");
|
|
|
|
|
Debug.WriteLine("Ouverture du capteur Kinect.");
|
|
|
|
|
// Ouvrir le lecteur de flux de couleur
|
|
|
|
|
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
|
|
|
|
|
// Frame description pour les images de couleur
|
|
|
|
|
FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
|
|
|
|
|
// Créer le bitmap pour afficher l'image
|
|
|
|
|
this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
|
|
|
|
|
// Gérer l'événement FrameArrived pour le flux de couleur
|
|
|
|
|
this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
|
|
|
|
|
// Ouvrir la Kinect
|
|
|
|
|
this.kinectSensor.Open();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Aucune Kinect détectée.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Frame de couleur arrivée.");
|
|
|
|
|
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
|
|
|
|
|
{
|
|
|
|
|
if (colorFrame != null)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Traitement de la frame de couleur.");
|
|
|
|
|
FrameDescription colorFrameDescription = colorFrame.FrameDescription;
|
|
|
|
|
|
|
|
|
|
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
|
|
|
|
@ -73,6 +81,11 @@ namespace WpfApp
|
|
|
|
|
|
|
|
|
|
this.colorBitmap.Unlock();
|
|
|
|
|
}
|
|
|
|
|
Debug.WriteLine("Frame de couleur traitée.");
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Frame de couleur nulle.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -80,6 +93,7 @@ namespace WpfApp
|
|
|
|
|
// Assurez-vous de fermer correctement le lecteur et le capteur Kinect lors de la fermeture de la fenêtre
|
|
|
|
|
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Debug.WriteLine("Fermeture de l'application et libération des ressources Kinect.");
|
|
|
|
|
if (this.colorFrameReader != null)
|
|
|
|
|
{
|
|
|
|
|
this.colorFrameReader.Dispose();
|
|
|
|
@ -91,6 +105,7 @@ namespace WpfApp
|
|
|
|
|
this.kinectSensor.Close();
|
|
|
|
|
this.kinectSensor = null;
|
|
|
|
|
}
|
|
|
|
|
Debug.WriteLine("Ressources Kinect libérées.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|