From 3a9797a3c42b90794cc05deb62e0151974eb241c Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Sat, 13 Jan 2024 14:27:22 +0100 Subject: [PATCH] Add KinectManger and ColorFrameHandler --- Sources/Lib/ColorFrameHandler.cs | 36 ++++++++++++++++++++++++++++ Sources/Lib/KinectManager.cs | 41 ++++++++++++++++++++++++++------ 2 files changed, 70 insertions(+), 7 deletions(-) create mode 100644 Sources/Lib/ColorFrameHandler.cs diff --git a/Sources/Lib/ColorFrameHandler.cs b/Sources/Lib/ColorFrameHandler.cs new file mode 100644 index 0000000..c734d16 --- /dev/null +++ b/Sources/Lib/ColorFrameHandler.cs @@ -0,0 +1,36 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lib +{ + public class ColorFrameHandler + { + private ColorFrameReader reader; + private WriteableBitmap colorBitmap; + + public WriteableBitmap ColorBitmap => colorBitmap; + + public ColorFrameHandler(KinectSensor sensor) + { + reader = sensor.ColorFrameSource.OpenReader(); + var frameDescription = sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); + colorBitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); + reader.FrameArrived += Reader_FrameArrived; + } + + private void Reader_FrameArrived(object sender, ColorFrameArrivedEventArgs e) + { + using (var colorFrame = e.FrameReference.AcquireFrame()) + { + if (colorFrame != null) + { + // ... Logique existante pour traiter la frame ... + } + } + } + } +} diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs index 58289b4..26b9ba9 100644 --- a/Sources/Lib/KinectManager.cs +++ b/Sources/Lib/KinectManager.cs @@ -5,16 +5,43 @@ namespace Lib { public class KinectManager { - private static KinectSensor kinectSensor; - public static bool Status + private KinectSensor kinectSensor; + + public KinectManager() + { + kinectSensor = KinectSensor.GetDefault(); + if (kinectSensor != null) + { + kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; + } + } + public bool Status { get { return kinectSensor != null && kinectSensor.IsAvailable; } } - public static string StatusText + public string StatusText { - get { return Status ? "Kinect est disponible" : "Kinect n'est pas disponible"; } + get + { + if (kinectSensor == null) + { + return "Kinect n'est pas connecté"; + } + else if (!kinectSensor.IsOpen) + { + return "Kinect n'est pas ouvert"; + } + else if (kinectSensor.IsAvailable) + { + return "Kinect est disponible"; + } + else + { + return "Kinect n'est pas disponible"; + } + } } - public static void StartSensor() + public void StartSensor() { if (kinectSensor == null) { @@ -26,7 +53,7 @@ namespace Lib } } } - public static void StopSensor() + public void StopSensor() { if (kinectSensor != null) { @@ -34,7 +61,7 @@ namespace Lib kinectSensor = null; } } - private static void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args) + private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args) { // Vous pouvez ajouter ici une logique supplémentaire si nécessaire }