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 @@
-
+
\ No newline at end of file
diff --git a/Sources/WpfApp/MainWindow.xaml.cs b/Sources/WpfApp/MainWindow.xaml.cs
index 335f798..e6b7e32 100644
--- a/Sources/WpfApp/MainWindow.xaml.cs
+++ b/Sources/WpfApp/MainWindow.xaml.cs
@@ -23,17 +23,27 @@ namespace WpfApp
///
public partial class MainWindow : Window
{
- private KinectManager kinectManager;
- private ColorFrameHandler colorFrameHandler;
+ private KinectManager _kinectManager;
+ public KinectManager kinectManager
+ {
+ get { return _kinectManager; }
+ set { _kinectManager = value; }
+ }
public MainWindow()
{
InitializeComponent();
kinectManager = new KinectManager();
+ Debug.WriteLine(kinectManager.StatusText);
+ kinectManager.ChangeToColorStream();
+ Debug.WriteLine(kinectManager.StatusText);
kinectManager.StartSensor();
+ Debug.WriteLine(kinectManager.StatusText);
+ DataContext = this;
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
+ Debug.WriteLine(kinectManager.StatusText);
kinectManager.StopSensor();
}
}