FiilterButtonsBinding #9

Merged
louis.dufour merged 10 commits from FiilterButtonsBinding into dev 1 year ago

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lib
{
public class Class1
{
}
}

@ -0,0 +1,61 @@
using Microsoft.Kinect;
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Lib
{
public class ColorImageStream : KinectStream
{
private ColorFrameReader reader;
public ColorFrameReader Reader {
get {
return reader;
}
set
{
reader = value;
}
}
public ColorImageStream() : base()
{
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;
}
private void Reader_FrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (var colorFrame = e.FrameReference.AcquireFrame())
{
if (colorFrame != null)
{
// ... Logique existante pour traiter la frame
//Debug.WriteLine("Traitement de la frame de couleur.");
FrameDescription colorFrameDescription = colorFrame.FrameDescription;
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
{
this.Bitmap.Lock();
// Vérifier si la taille de l'image a changé
if ((colorFrameDescription.Width == this.Bitmap.PixelWidth) && (colorFrameDescription.Height == this.Bitmap.PixelHeight))
{
colorFrame.CopyConvertedFrameDataToIntPtr(
this.Bitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
ColorImageFormat.Bgra);
this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight));
}
this.Bitmap.Unlock();
}
//Debug.WriteLine("Frame de couleur traitée.");
}
}
}
}
}

@ -0,0 +1,75 @@
using Microsoft.Kinect;
using System.ComponentModel;
using System.Diagnostics;
namespace Lib
{
public class KinectManager : INotifyPropertyChanged
{
private KinectSensor sensor;
public KinectSensor Sensor {
get {
return sensor;
}
set
{
sensor = value;
OnPropertyChanged(nameof(Sensor));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public KinectManager()
{
sensor = KinectSensor.GetDefault();
}
public void StartSensor()
{
if (sensor != null) {
sensor.Open();
}
}
public void StopSensor()
{
if (sensor != null)
{
sensor.Close();
}
}
public bool Status
{
get { return Sensor != null && Sensor.IsAvailable; }
}
public string StatusText
{
get
{
if (Sensor == null)
{
return "Kinect n'est pas connecté";
}
else if (!Sensor.IsOpen)
{
return "Kinect n'est pas ouvert";
}
else if (Sensor.IsAvailable)
{
return "Kinect est disponible";
}
else
{
return "Kinect n'est pas disponible";
}
}
}
private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs args)
{
// Vous pouvez ajouter ici une logique supplémentaire si nécessaire
}
}
}

@ -0,0 +1,51 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
using System.Windows.Media.Imaging;
namespace Lib
{
public abstract class KinectStream : INotifyPropertyChanged
{
public KinectManager KinectManager { get; private set; }
private WriteableBitmap bitmap;
public WriteableBitmap Bitmap
{
get { return bitmap; }
protected set
{
if (bitmap != value)
{
bitmap = value;
OnPropertyChanged(nameof(bitmap));
}
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public KinectStream()
{
KinectManager = new KinectManager();
}
public virtual void Start()
{
KinectManager.StartSensor();
}
public virtual void Stop()
{
KinectManager.StopSensor();
}
}
}

@ -1,10 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>0751c83e-7845-4e5f-a5d3-e11aba393aca</ProjectGuid>
<ProjectGuid>{0751C83E-7845-4E5F-A5D3-E11ABA393ACA}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Lib</RootNamespace>
@ -31,24 +31,28 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System"/>
<Reference Include="System.Core"/>
<Reference Include="System.Xml.Linq"/>
<Reference Include="System.Data.DataSetExtensions"/>
<Reference Include="Microsoft.CSharp"/>
<Reference Include="System.Data"/>
<Reference Include="System.Net.Http"/>
<Reference Include="System.Xml"/>
<Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll</HintPath>
</Reference>
<Reference Include="PresentationCore" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="WindowsBase" />
</ItemGroup>
<ItemGroup>
<Compile Include="Class1.cs" />
<Compile Include="ColorImageStream.cs" />
<Compile Include="KinectManager.cs" />
<Compile Include="KinectStream.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
</Project>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Kinect" version="2.0.1410.19000" targetFramework="net472" />
</packages>

@ -1,6 +1,8 @@
using Microsoft.Kinect;
using Lib;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -62,8 +64,6 @@ namespace WpfApp
public MainWindow()
{
InitializeComponent();
// Définir le DataContext pour le binding
this.DataContext = this;
// Initialiser la Kinect

@ -98,5 +98,11 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Lib\Lib.csproj">
<Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project>
<Name>Lib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
Loading…
Cancel
Save