pull/9/head
Johan LACHENAL 1 year ago
parent 993306b1c3
commit c643193dd7

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

@ -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";
}

@ -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();
}
}
}

@ -26,6 +26,6 @@
<Button Content="Filtre 5" Margin="5"/>
</StackPanel>
<Image Grid.Row="2" Source="{Binding kinectManager.CurrentStream.BitMap}" />
<Image Grid.Row="2" Source="{Binding KinectStream.BitMap}" />
</Grid>
</Window>

@ -23,29 +23,26 @@ namespace WpfApp
/// </summary>
public partial class MainWindow : Window
{
private KinectManager _kinectManager;
public KinectManager kinectManager
private KinectStream _kinectStream;
public KinectStream KinectStream
{
get { return _kinectManager; }
set { _kinectManager = value; }
get { return _kinectStream; }
set { _kinectStream = value; }
}
public MainWindow()
{
InitializeComponent();
kinectManager = new KinectManager();
Debug.WriteLine(kinectManager.StatusText);
kinectManager.ChangeToColorStream();
Debug.WriteLine(kinectManager.StatusText);
kinectManager.StartSensor();
Debug.WriteLine(kinectManager.CurrentStream.Bitmap);
Debug.WriteLine(kinectManager.StatusText);
DataContext = this;
this.DataContext = this;
KinectStream = new ColorImageStream();
Debug.WriteLine(KinectStream.KinectManager.StatusText);
KinectStream.Start();
Debug.WriteLine(KinectStream.KinectManager.StatusText);
}
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
Debug.WriteLine(kinectManager.StatusText);
kinectManager.StopSensor();
Debug.WriteLine(KinectStream.KinectManager.StatusText);
KinectStream.Stop();
}
}
}

Loading…
Cancel
Save