From c643193dd7a764ab265eb70adf93a0c76bd7bd16 Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Wed, 24 Jan 2024 09:30:41 +0100 Subject: [PATCH] push --- Sources/Lib/ColorImageStream.cs | 16 +++++++-- Sources/Lib/KinectManager.cs | 56 +++++++++++-------------------- Sources/Lib/KinectStream.cs | 17 +++------- Sources/WpfApp/MainWindow.xaml | 2 +- Sources/WpfApp/MainWindow.xaml.cs | 25 ++++++-------- 5 files changed, 51 insertions(+), 65 deletions(-) diff --git a/Sources/Lib/ColorImageStream.cs b/Sources/Lib/ColorImageStream.cs index 3a8a3f0..8bdd2a2 100644 --- a/Sources/Lib/ColorImageStream.cs +++ b/Sources/Lib/ColorImageStream.cs @@ -1,4 +1,5 @@ using Microsoft.Kinect; +using System.ComponentModel; using System.Windows; using System.Windows.Media; using System.Windows.Media.Imaging; @@ -8,9 +9,20 @@ namespace Lib public class ColorImageStream : KinectStream { private ColorFrameReader reader; - public ColorImageStream(KinectSensor sensor) : base(sensor) + public ColorFrameReader Reader { + get { + return reader; + } + set + { + reader = value; + } + } + public ColorImageStream() : base() { - reader = sensor.ColorFrameSource.OpenReader(); + var frameDescription = KinectManager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); + this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); + reader = KinectManager.Sensor.ColorFrameSource.OpenReader(); reader.FrameArrived += Reader_FrameArrived; } diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs index f57ca47..bf9ce2b 100644 --- a/Sources/Lib/KinectManager.cs +++ b/Sources/Lib/KinectManager.cs @@ -6,24 +6,18 @@ namespace Lib { public class KinectManager : INotifyPropertyChanged { - private KinectStream currentStream; - public KinectStream CurrentStream - { - get { return currentStream; } + private KinectSensor sensor; + public KinectSensor Sensor { + get { + return sensor; + } set { - if (currentStream != value) - { - if (currentStream != null) - { - currentStream.Stop(); - } - currentStream = value; - currentStream.Start(); - OnPropertyChanged(nameof(CurrentStream)); - } + sensor = value; + OnPropertyChanged(nameof(Sensor)); } } + public event PropertyChangedEventHandler PropertyChanged; protected virtual void OnPropertyChanged(string propertyName) { @@ -32,48 +26,38 @@ namespace Lib public KinectManager() { - CurrentStream = new ColorImageStream(KinectSensor.GetDefault()); + sensor = 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(); + if (sensor != null) { + sensor.Open(); + } } public void StopSensor() { - currentStream.Stop(); + if (sensor != null) + { + sensor.Close(); + } } public bool Status { - get { return currentStream.Sensor != null && currentStream.Sensor.IsAvailable; } + get { return Sensor != null && Sensor.IsAvailable; } } public string StatusText { get { - if (currentStream.Sensor == null) + if (Sensor == null) { return "Kinect n'est pas connecté"; } - else if (!currentStream.Sensor.IsOpen) + else if (!Sensor.IsOpen) { return "Kinect n'est pas ouvert"; } - else if (currentStream.Sensor.IsAvailable) + else if (Sensor.IsAvailable) { return "Kinect est disponible"; } diff --git a/Sources/Lib/KinectStream.cs b/Sources/Lib/KinectStream.cs index c88c8eb..61d2fdf 100644 --- a/Sources/Lib/KinectStream.cs +++ b/Sources/Lib/KinectStream.cs @@ -12,7 +12,7 @@ namespace Lib { public abstract class KinectStream : INotifyPropertyChanged { - public KinectSensor Sensor { get; protected set; } + public KinectManager KinectManager { get; private set; } private WriteableBitmap bitmap; public WriteableBitmap Bitmap { @@ -33,26 +33,19 @@ namespace Lib PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - - public KinectStream(KinectSensor sensor) + public KinectStream() { - Sensor = sensor; - var frameDescription = sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); - Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); + KinectManager = new KinectManager(); } public virtual void Start() { - if (Sensor != null) { - Sensor.Open(); - } + KinectManager.StartSensor(); } public virtual void Stop() { - if (Sensor != null) { - Sensor.Close(); - } + KinectManager.StopSensor(); } } } diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml index 709437d..2418690 100644 --- a/Sources/WpfApp/MainWindow.xaml +++ b/Sources/WpfApp/MainWindow.xaml @@ -26,6 +26,6 @@