Create(FilterButtonsBinding): create branch

pull/9/head
Johan LACHENAL 1 year ago
parent 846f87306d
commit 4e88d2ffa1

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

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

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

@ -46,8 +46,9 @@
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="ColorFrameHandler.cs" />
<Compile Include="ColorImageStream.cs" />
<Compile Include="KinectManager.cs" />
<Compile Include="KinectStream.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>

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

@ -23,17 +23,27 @@ namespace WpfApp
/// </summary>
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();
}
}

Loading…
Cancel
Save