From 70b52ba6ea163b10443a2f9ddc79795137e17222 Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Thu, 11 Jan 2024 11:34:23 +0100 Subject: [PATCH 1/8] Ajout de lignes pour comprendre comment cela fonctionne --- Sources/WpfApp/MainWindow.xaml.cs | 45 ++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs index a7b8165..a6536c3 100644 --- a/Sources/WpfApp/MainWindow.xaml.cs +++ b/Sources/WpfApp/MainWindow.xaml.cs @@ -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."); } } } -- 2.36.3 From 22f5e83dee90e286a8a7b23a926297bd325de80a Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Thu, 11 Jan 2024 12:10:17 +0100 Subject: [PATCH 2/8] Add kinect Manager --- Sources/Lib/Class1.cs | 12 --------- Sources/Lib/KinectManager.cs | 42 +++++++++++++++++++++++++++++++ Sources/Lib/Lib.csproj | 36 +++++++++++++------------- Sources/Lib/packages.config | 4 +++ Sources/WpfApp/MainWindow.xaml.cs | 6 ++--- 5 files changed, 67 insertions(+), 33 deletions(-) delete mode 100644 Sources/Lib/Class1.cs create mode 100644 Sources/Lib/KinectManager.cs create mode 100644 Sources/Lib/packages.config diff --git a/Sources/Lib/Class1.cs b/Sources/Lib/Class1.cs deleted file mode 100644 index dfbc46b..0000000 --- a/Sources/Lib/Class1.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Lib -{ - public class Class1 - { - } -} diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs new file mode 100644 index 0000000..58289b4 --- /dev/null +++ b/Sources/Lib/KinectManager.cs @@ -0,0 +1,42 @@ +using System; +using Microsoft.Kinect; + +namespace Lib +{ + public class KinectManager + { + private static KinectSensor kinectSensor; + public static bool Status + { + get { return kinectSensor != null && kinectSensor.IsAvailable; } + } + public static string StatusText + { + get { return Status ? "Kinect est disponible" : "Kinect n'est pas disponible"; } + } + public static void StartSensor() + { + if (kinectSensor == null) + { + kinectSensor = KinectSensor.GetDefault(); + if (kinectSensor != null) + { + kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; + kinectSensor.Open(); + } + } + } + public static void StopSensor() + { + if (kinectSensor != null) + { + kinectSensor.Close(); + kinectSensor = null; + } + } + private static void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args) + { + // Vous pouvez ajouter ici une logique supplémentaire si nécessaire + } + } +} diff --git a/Sources/Lib/Lib.csproj b/Sources/Lib/Lib.csproj index 12682ba..2c53495 100644 --- a/Sources/Lib/Lib.csproj +++ b/Sources/Lib/Lib.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - 0751c83e-7845-4e5f-a5d3-e11aba393aca + {0751C83E-7845-4E5F-A5D3-E11ABA393ACA} Library Properties Lib @@ -31,24 +31,24 @@ 4 - - - - - - - - - - - - - - + + ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll + + + + + + + + + - + + + + - + \ No newline at end of file diff --git a/Sources/Lib/packages.config b/Sources/Lib/packages.config new file mode 100644 index 0000000..f7f19c3 --- /dev/null +++ b/Sources/Lib/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs index 3fabe8c..2e8edd9 100644 --- a/Sources/WpfApp/MainWindow.xaml.cs +++ b/Sources/WpfApp/MainWindow.xaml.cs @@ -65,12 +65,12 @@ namespace WpfApp private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e) { - Debug.WriteLine("Frame de couleur arrivé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."); + //Debug.WriteLine("Traitement de la frame de couleur."); FrameDescription colorFrameDescription = colorFrame.FrameDescription; using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) @@ -90,7 +90,7 @@ namespace WpfApp this.colorBitmap.Unlock(); } - Debug.WriteLine("Frame de couleur traitée."); + //Debug.WriteLine("Frame de couleur traitée."); } else { -- 2.36.3 From 3a9797a3c42b90794cc05deb62e0151974eb241c Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Sat, 13 Jan 2024 14:27:22 +0100 Subject: [PATCH 3/8] 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 } -- 2.36.3 From 846f87306dff9caf1de06881a2581cd249189924 Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Sat, 13 Jan 2024 15:00:23 +0100 Subject: [PATCH 4/8] add KinectManager and a colorFrame Handler classes to manage the sensor --- Sources/Lib/ColorFrameHandler.cs | 31 ++++++++-- Sources/Lib/KinectManager.cs | 5 +- Sources/Lib/Lib.csproj | 3 + Sources/WpfApp/MainWindow.xaml.cs | 94 +++---------------------------- Sources/WpfApp/WpfApp.csproj | 6 ++ 5 files changed, 43 insertions(+), 96 deletions(-) diff --git a/Sources/Lib/ColorFrameHandler.cs b/Sources/Lib/ColorFrameHandler.cs index c734d16..ba6dec2 100644 --- a/Sources/Lib/ColorFrameHandler.cs +++ b/Sources/Lib/ColorFrameHandler.cs @@ -1,9 +1,7 @@ using Microsoft.Kinect; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; namespace Lib { @@ -28,7 +26,28 @@ namespace Lib { if (colorFrame != null) { - // ... Logique existante pour traiter la frame ... + // ... Logique existante pour traiter la frame + //Debug.WriteLine("Traitement de la frame de couleur."); + FrameDescription colorFrameDescription = colorFrame.FrameDescription; + + using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) + { + this.colorBitmap.Lock(); + + // Vérifier si la taille de l'image a changé + if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight)) + { + colorFrame.CopyConvertedFrameDataToIntPtr( + this.colorBitmap.BackBuffer, + (uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4), + ColorImageFormat.Bgra); + + this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight)); + } + + this.colorBitmap.Unlock(); + } + //Debug.WriteLine("Frame de couleur traitée."); } } } diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs index 26b9ba9..b7dd29b 100644 --- a/Sources/Lib/KinectManager.cs +++ b/Sources/Lib/KinectManager.cs @@ -1,11 +1,10 @@ -using System; -using Microsoft.Kinect; +using Microsoft.Kinect; namespace Lib { public class KinectManager { - private KinectSensor kinectSensor; + public KinectSensor kinectSensor { get; private set; } public KinectManager() { diff --git a/Sources/Lib/Lib.csproj b/Sources/Lib/Lib.csproj index 2c53495..b22ede6 100644 --- a/Sources/Lib/Lib.csproj +++ b/Sources/Lib/Lib.csproj @@ -34,6 +34,7 @@ ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll + @@ -42,8 +43,10 @@ + + diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs index 2e8edd9..335f798 100644 --- a/Sources/WpfApp/MainWindow.xaml.cs +++ b/Sources/WpfApp/MainWindow.xaml.cs @@ -1,4 +1,5 @@ -using Microsoft.Kinect; +using Lib; +using Microsoft.Kinect; using System; using System.Collections.Generic; using System.Diagnostics; @@ -22,99 +23,18 @@ namespace WpfApp /// public partial class MainWindow : Window { - private KinectSensor kinectSensor = null; - private ColorFrameReader colorFrameReader = null; - private WriteableBitmap colorBitmap = null; - - // Propriété publique pour le binding - public WriteableBitmap ColorBitmap - { - get { return this.colorBitmap; } - } - + private KinectManager kinectManager; + private ColorFrameHandler colorFrameHandler; public MainWindow() { InitializeComponent(); - Debug.WriteLine("Initialisation de Kinect..."); - - // Définir le DataContext pour le binding - this.DataContext = this; - - // Initialiser la Kinect - this.kinectSensor = KinectSensor.GetDefault(); - 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."); - } + kinectManager = new KinectManager(); + kinectManager.StartSensor(); } - 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()) - { - this.colorBitmap.Lock(); - - // Vérifier si la taille de l'image a changé - if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight)) - { - colorFrame.CopyConvertedFrameDataToIntPtr( - this.colorBitmap.BackBuffer, - (uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4), - ColorImageFormat.Bgra); - - this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight)); - } - - this.colorBitmap.Unlock(); - } - //Debug.WriteLine("Frame de couleur traitée."); - } - else - { - Debug.WriteLine("Frame de couleur nulle."); - } - } - } - - // 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(); - this.colorFrameReader = null; - } - - if (this.kinectSensor != null) - { - this.kinectSensor.Close(); - this.kinectSensor = null; - } - Debug.WriteLine("Ressources Kinect libérées."); + kinectManager.StopSensor(); } } } diff --git a/Sources/WpfApp/WpfApp.csproj b/Sources/WpfApp/WpfApp.csproj index 950c7f9..766b946 100644 --- a/Sources/WpfApp/WpfApp.csproj +++ b/Sources/WpfApp/WpfApp.csproj @@ -98,5 +98,11 @@ + + + {0751c83e-7845-4e5f-a5d3-e11aba393aca} + Lib + + \ No newline at end of file -- 2.36.3 From 4e88d2ffa18f70d1a315ff0ff82de62bdf9c6827 Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Wed, 17 Jan 2024 09:56:34 +0100 Subject: [PATCH 5/8] Create(FilterButtonsBinding): create branch --- ...lorFrameHandler.cs => ColorImageStream.cs} | 4 +- Sources/Lib/KinectManager.cs | 85 ++++++++++++------- Sources/Lib/KinectStream.cs | 34 ++++++++ Sources/Lib/Lib.csproj | 3 +- Sources/WpfApp/MainWindow.xaml | 2 +- Sources/WpfApp/MainWindow.xaml.cs | 14 ++- 6 files changed, 105 insertions(+), 37 deletions(-) rename Sources/Lib/{ColorFrameHandler.cs => ColorImageStream.cs} (94%) create mode 100644 Sources/Lib/KinectStream.cs diff --git a/Sources/Lib/ColorFrameHandler.cs b/Sources/Lib/ColorImageStream.cs similarity index 94% rename from Sources/Lib/ColorFrameHandler.cs rename to Sources/Lib/ColorImageStream.cs index ba6dec2..541d407 100644 --- a/Sources/Lib/ColorFrameHandler.cs +++ b/Sources/Lib/ColorImageStream.cs @@ -5,14 +5,14 @@ using System.Windows.Media.Imaging; namespace Lib { - public class ColorFrameHandler + public class ColorImageStream : KinectStream { private ColorFrameReader reader; private WriteableBitmap colorBitmap; public WriteableBitmap ColorBitmap => colorBitmap; - public ColorFrameHandler(KinectSensor sensor) + public ColorImageStream(KinectSensor sensor) : base(sensor) { reader = sensor.ColorFrameSource.OpenReader(); var frameDescription = sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs index b7dd29b..f57ca47 100644 --- a/Sources/Lib/KinectManager.cs +++ b/Sources/Lib/KinectManager.cs @@ -1,36 +1,79 @@ using Microsoft.Kinect; +using System.ComponentModel; +using System.Diagnostics; namespace Lib { - public class KinectManager + public class KinectManager : INotifyPropertyChanged { - public KinectSensor kinectSensor { get; private set; } - - public KinectManager() + private KinectStream currentStream; + public KinectStream CurrentStream { - kinectSensor = KinectSensor.GetDefault(); - if (kinectSensor != null) + get { return currentStream; } + set { - kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; + if (currentStream != value) + { + if (currentStream != null) + { + currentStream.Stop(); + } + currentStream = value; + currentStream.Start(); + OnPropertyChanged(nameof(CurrentStream)); + } } } + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public KinectManager() + { + CurrentStream = new ColorImageStream(KinectSensor.GetDefault()); + } + + public void ChangeToColorStream() + { + CurrentStream = new ColorImageStream(KinectSensor.GetDefault()); + } + //public void ChangeToDepthStream() + //{ + // KinectSensor sensor = KinectSensor.GetDefault(); + // CurrentStream = new DepthImageStream(sensor); + //} + //public void ChangeToInfraredStream() + //{ + // KinectSensor sensor = KinectSensor.GetDefault(); + // CurrentStream = new InfraredImageStream(sensor); + //} + public void StartSensor() + { + currentStream.Start(); + } + public void StopSensor() + { + currentStream.Stop(); + } public bool Status { - get { return kinectSensor != null && kinectSensor.IsAvailable; } + get { return currentStream.Sensor != null && currentStream.Sensor.IsAvailable; } } public string StatusText { get { - if (kinectSensor == null) + if (currentStream.Sensor == null) { return "Kinect n'est pas connecté"; } - else if (!kinectSensor.IsOpen) + else if (!currentStream.Sensor.IsOpen) { return "Kinect n'est pas ouvert"; } - else if (kinectSensor.IsAvailable) + else if (currentStream.Sensor.IsAvailable) { return "Kinect est disponible"; } @@ -40,26 +83,6 @@ namespace Lib } } } - public void StartSensor() - { - if (kinectSensor == null) - { - kinectSensor = KinectSensor.GetDefault(); - if (kinectSensor != null) - { - kinectSensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; - kinectSensor.Open(); - } - } - } - public void StopSensor() - { - if (kinectSensor != null) - { - kinectSensor.Close(); - kinectSensor = null; - } - } private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args) { // Vous pouvez ajouter ici une logique supplémentaire si nécessaire diff --git a/Sources/Lib/KinectStream.cs b/Sources/Lib/KinectStream.cs new file mode 100644 index 0000000..7d0b5ab --- /dev/null +++ b/Sources/Lib/KinectStream.cs @@ -0,0 +1,34 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; + +namespace Lib +{ + public abstract class KinectStream + { + public KinectSensor Sensor { get; protected set; } + + protected KinectStream(KinectSensor sensor) + { + Sensor = sensor; + } + + public virtual void Start() + { + if (Sensor != null) { + Sensor.Open(); + } + } + + public virtual void Stop() + { + if (Sensor != null) { + Sensor.Close(); + } + } + } +} diff --git a/Sources/Lib/Lib.csproj b/Sources/Lib/Lib.csproj index b22ede6..dd258d7 100644 --- a/Sources/Lib/Lib.csproj +++ b/Sources/Lib/Lib.csproj @@ -46,8 +46,9 @@ - + + diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml index 4ebe115..29ca91e 100644 --- a/Sources/WpfApp/MainWindow.xaml +++ b/Sources/WpfApp/MainWindow.xaml @@ -26,6 +26,6 @@