diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml
index 5e4a5e2..b0e21ad 100644
--- a/Sources/WpfApp/MainWindow.xaml
+++ b/Sources/WpfApp/MainWindow.xaml
@@ -26,7 +26,7 @@
-
+
diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs
index c3a4a84..87e47af 100644
--- a/Sources/WpfApp/MainWindow.xaml.cs
+++ b/Sources/WpfApp/MainWindow.xaml.cs
@@ -22,18 +22,31 @@ namespace WpfApp
public partial class MainWindow : Window
{
private KinectSensor kinectSensor = null;
+
+ // Attribut captor color
private ColorFrameReader colorFrameReader = null;
private WriteableBitmap colorBitmap = null;
+ // Attribut captor Body
private BodyFrameReader bodyFrameReader = 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
public WriteableBitmap ColorBitmap
{
get { return this.colorBitmap; }
}
+ public WriteableBitmap DepthBitmap
+ {
+ get { return this.depthBitmap; }
+ }
+
public MainWindow()
{
InitializeComponent();
@@ -43,7 +56,8 @@ namespace WpfApp
// Initialiser la Kinect
this.kinectSensor = KinectSensor.GetDefault();
-
+
+ /* Capteur couleur
// Ouvrir le lecteur de flux de couleur
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
@@ -55,6 +69,7 @@ namespace WpfApp
// Gérer l'événement FrameArrived pour le flux de couleur
this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
+ */
// Initialisation du BodyFrameReader
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
@@ -63,6 +78,18 @@ namespace WpfApp
// Initialiser le tableau des corps
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
this.kinectSensor.Open();
}
@@ -169,5 +196,41 @@ namespace WpfApp
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);
+ }
+ }
+
}
}