|
|
|
@ -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
|
|
|
|
|