Merge pull request 'dev' (#18) from dev into master

Reviewed-on: #18
pull/21/head
Louis DUFOUR 1 year ago
commit 0239229d2c

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

@ -0,0 +1,63 @@
<?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>{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp</RootNamespace>
<AssemblyName>ConsoleApp</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<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="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" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.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>

@ -0,0 +1,53 @@
using Lib;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
// KinectManager kinectManager = new KinectManager();
// if (kinectManager.StartSensor())
// {
// Console.WriteLine("Kinect n'est pas connecté ou non reconnu.");
// return;
// }
// // Créez les instances de vos postures
// PostureHandUp handUpPosture = new PostureHandUp();
// PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead();
// // Abonnez-vous aux événements de reconnaissance de posture
// handUpPosture.GestureRecognized += (sender, e) =>
// {
// Console.WriteLine("Posture Hand Up reconnue !");
// };
// handsOnHeadPosture.GestureRecognized += (sender, e) =>
// {
// Console.WriteLine("Posture Hands On Head reconnue !");
// };
// // Boucle pour tester les postures
// while (true)
// {
// Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps
// if (body != null)
// {
// handUpPosture.TestGesture(body);
// handsOnHeadPosture.TestGesture(body);
// }
// Thread.Sleep(50); // Une petite pause pour ne pas surcharger le CPU
// }
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("ConsoleApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("27d9c879-52bb-4bd7-b08d-63a534ac6d7e")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

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

@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp", "WpfApp\WpfApp.csp
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib", "Lib\Lib.csproj", "{0751C83E-7845-4E5F-A5D3-E11ABA393ACA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyGesturesBank", "LibMyGesturesBank\MyGesturesBank.csproj", "{2496DFB1-EB55-47A1-A780-211E079B289D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KinectUtils", "KinectUtils\KinectUtils.csproj", "{2D44487E-F514-4063-9494-2AF1E8C9E9C8}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@ -21,6 +27,18 @@ Global
{0751C83E-7845-4E5F-A5D3-E11ABA393ACA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0751C83E-7845-4E5F-A5D3-E11ABA393ACA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0751C83E-7845-4E5F-A5D3-E11ABA393ACA}.Release|Any CPU.Build.0 = Release|Any CPU
{2496DFB1-EB55-47A1-A780-211E079B289D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2496DFB1-EB55-47A1-A780-211E079B289D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2496DFB1-EB55-47A1-A780-211E079B289D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2496DFB1-EB55-47A1-A780-211E079B289D}.Release|Any CPU.Build.0 = Release|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Release|Any CPU.Build.0 = Release|Any CPU
{2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE

@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KinectUtils
{
public class AllGesturesFactory : IGestureFactory
{
public IEnumerable<BaseGesture> CreateGestures()
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,36 @@
using System;
using Microsoft.Kinect;
namespace KinectUtils
{
public abstract class BaseGesture
{
// Événement déclenché lorsque le geste est reconnu
public event EventHandler GestureRecognized;
// Nom du geste - marqué comme virtual pour permettre la substitution
public string GestureName { get; protected set; }
// Méthode abstraite pour tester le geste
public abstract void TestGesture(Body body);
// Méthode protégée pour déclencher l'événement GestureRecognized
protected virtual void OnGestureRecognized(Body body)
{
GestureRecognized?.Invoke(this, new GestureRecognizedEventArgs(body, GestureName));
}
}
public class GestureRecognizedEventArgs : EventArgs
{
public Body Body { get; private set; }
public string GestureName { get; private set; }
public GestureRecognizedEventArgs(Body body, string gestureName)
{
Body = body;
GestureName = gestureName;
}
}
}

@ -0,0 +1,33 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KinectUtils
{
class BaseMapping<T>
{
public void SubscribeToStartGesture(BaseGesture gesture)
{
throw new NotImplementedException();
}
public void SubscribeToEndGesture(BaseGesture gesture)
{
throw new NotImplementedException();
}
public void SubscribeToToggleGesture(BaseGesture gesture)
{
throw new NotImplementedException();
}
protected T Mapping(Body body)
{
throw new NotImplementedException();
}
public bool TestMapping(Body body, out T output)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,49 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KinectUtils
{
abstract class Gesture : BaseGesture
{
public bool IsTesting { get; protected set; }
protected int MinNbOfFrames = 10; // Exemple de valeur, ajustez selon le geste
protected int MaxNbOfFrames = 50; // Exemple de valeur, ajustez selon le geste
private int mCurrentFrameCount = 0;
// public bool isRecognitionRunning { get; set; }
public override void TestGesture(Body body)
{
if (!IsTesting)
{
if (TestInitialConditions(body))
{
IsTesting = true;
mCurrentFrameCount = 0;
}
}
else
{
mCurrentFrameCount++;
if (!TestPosture(body) || !TestRunningGesture(body) || mCurrentFrameCount > MaxNbOfFrames)
{
IsTesting = false;
}
else if (TestEndConditions(body) && mCurrentFrameCount >= MinNbOfFrames)
{
OnGestureRecognized(body);
IsTesting = false;
}
}
}
abstract protected bool TestInitialConditions(Body body);
abstract protected bool TestPosture(Body body);
abstract protected bool TestRunningGesture(Body body);
abstract protected bool TestEndConditions(Body body);
}
}

@ -0,0 +1,36 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Lib;
namespace KinectUtils
{
static class GestureManager
{
static event EventHandler GestureRecognized;
static KinectManager KinectManager { get; set; }
static List<BaseGesture> KnownGestures { get; set; }
static public void AddGestures(IGestureFactory factory)
{
KnownGestures = (List<BaseGesture>)factory.CreateGestures();
}
static public void AddGestures(params BaseGesture[] gestures)
{
foreach (var gesture in gestures)
{
KnownGestures.Add(gesture);
}
}
static public void RemoveGesture(BaseGesture gesture)
{
KnownGestures.Remove(gesture);
}
static public void StartAcquiringFrames(KinectManager kinectManager)
{
throw new NotImplementedException();
}
}
}

@ -0,0 +1,13 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KinectUtils
{
interface IGestureFactory
{
IEnumerable<BaseGesture> CreateGestures();
}
}

@ -0,0 +1,61 @@
<?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>{2D44487E-F514-4063-9494-2AF1E8C9E9C8}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>KinectUtils</RootNamespace>
<AssemblyName>KinectUtils</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
<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" />
</ItemGroup>
<ItemGroup>
<Compile Include="AllGesturesFactory.cs" />
<Compile Include="BaseGesture.cs" />
<Compile Include="BaseMapping.cs" />
<Compile Include="Gesture.cs" />
<Compile Include="GestureManager.cs" />
<Compile Include="IGestureFactory.cs" />
<Compile Include="Posture.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</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>

@ -0,0 +1,24 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace KinectUtils
{
public abstract class Posture : BaseGesture
{
protected abstract bool TestPosture(Body body);
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
// Posture is recognized
OnGestureRecognized();
}
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("KinectUtils")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("KinectUtils")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("2d44487e-f514-4063-9494-2af1e8c9e9c8")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,172 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows;
using System.Windows.Shapes;
using Lib;
using System.Windows.Controls;
namespace Lib
{
public class BodyImageStream : KinectStream
{
private BodyFrameReader reader;
public BodyFrameReader Reader
{
get { return reader; }
set { reader = value; }
}
private Body[] bodies;
public Body[] Bodies
{
get { return bodies; }
private set { bodies = value; }
}
public override void Stop()
{
if (Reader != null)
{
Reader.Dispose();
Reader = null;
}
}
public BodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
{
var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived;
// initialiser le tableau des corps
this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
Canvas = skeletonCanvas;
}
private void drawbone(Body body, JointType JointType0, JointType JointType1)
{
Joint joint0 = body.Joints[JointType0];
Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis
if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
{
Line bone = new Line
{
Stroke = new SolidColorBrush(Colors.LightBlue),
StrokeThickness = 4,
X1 = MapJointToScreen(joint0).X,
Y1 = MapJointToScreen(joint0).Y,
X2 = MapJointToScreen(joint1).X,
Y2 = MapJointToScreen(joint1).Y
};
Canvas.Children.Add(bone);
}
}
private Point MapJointToScreen(Joint joint)
{
ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
// Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
return new Point(x, y);
}
private void drawskeleton(Body body)
{
// tête et cou
drawbone(body, JointType.Head, JointType.Neck);
drawbone(body, JointType.Neck, JointType.SpineShoulder);
// torse
drawbone(body, JointType.SpineShoulder, JointType.SpineMid);
drawbone(body, JointType.SpineMid, JointType.SpineBase);
drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight);
drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft);
drawbone(body, JointType.SpineBase, JointType.HipRight);
drawbone(body, JointType.SpineBase, JointType.HipLeft);
// bras droit
drawbone(body, JointType.ShoulderRight, JointType.ElbowRight);
drawbone(body, JointType.ElbowRight, JointType.WristRight);
drawbone(body, JointType.WristRight, JointType.HandRight);
drawbone(body, JointType.HandRight, JointType.HandTipRight);
drawbone(body, JointType.WristRight, JointType.ThumbRight);
// bras gauche
drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft);
drawbone(body, JointType.ElbowLeft, JointType.WristLeft);
drawbone(body, JointType.WristLeft, JointType.HandLeft);
drawbone(body, JointType.HandLeft, JointType.HandTipLeft);
drawbone(body, JointType.WristLeft, JointType.ThumbLeft);
// jambe droite
drawbone(body, JointType.HipRight, JointType.KneeRight);
drawbone(body, JointType.KneeRight, JointType.AnkleRight);
drawbone(body, JointType.AnkleRight, JointType.FootRight);
// jambe gauche
drawbone(body, JointType.HipLeft, JointType.KneeLeft);
drawbone(body, JointType.KneeLeft, JointType.AnkleLeft);
drawbone(body, JointType.AnkleLeft, JointType.FootLeft);
// dessinez les joints
foreach (JointType JointType in body.Joints.Keys)
{
Joint joint = body.Joints[JointType];
if (joint.TrackingState == TrackingState.Tracked)
{
DrawJoint(MapJointToScreen(joint));
}
}
}
private void DrawJoint(Point point)
{
Ellipse ellipse = new Ellipse
{
Width = 10,
Height = 10,
Fill = new SolidColorBrush(Colors.Red)
};
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
Canvas.Children.Add(ellipse);
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyframe = e.FrameReference.AcquireFrame())
{
if (bodyframe != null)
{
bodyframe.GetAndRefreshBodyData(this.bodies);
Canvas.Children.Clear(); // nettoyer le Canvas avant de dessiner
foreach (var body in this.bodies)
{
if (body.IsTracked)
{
// dessiner le squelette
drawskeleton(body);
}
}
}
}
}
}
}

@ -0,0 +1,213 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows;
namespace Lib
{
public class ColorAndBodyImageStream : KinectStream
{
private BodyFrameReader reader;
public BodyFrameReader Reader
{
get { return reader; }
private set { reader = value; }
}
private ColorFrameReader _colorReader;
public ColorFrameReader ColorReader {
get { return _colorReader; }
private set { _colorReader = value; }
}
private Body[] bodies;
public Body[] Bodies
{
get { return bodies; }
private set { bodies = value; }
}
public override void Stop()
{
if (Reader != null)
{
Reader.Dispose();
Reader = null;
}
if(ColorReader != null)
{
ColorReader.Dispose();
ColorReader = null;
}
}
public ColorAndBodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager)
{
var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
reader = kinectmanager.Sensor.BodyFrameSource.OpenReader();
reader.FrameArrived += Reader_BodyFrameArrived;
ColorReader = KinectManager.Sensor.ColorFrameSource.OpenReader();
ColorReader.FrameArrived += Reader_ColorFrameArrived;
// initialiser le tableau des corps
this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount];
Canvas = skeletonCanvas;
}
private void drawbone(Body body, JointType JointType0, JointType JointType1)
{
Joint joint0 = body.Joints[JointType0];
Joint joint1 = body.Joints[JointType1];
// ne dessinez que si les deux joints sont suivis
if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked)
{
Line bone = new Line
{
Stroke = new SolidColorBrush(Colors.LightBlue),
StrokeThickness = 4,
X1 = MapJointToScreen(joint0).X,
Y1 = MapJointToScreen(joint0).Y,
X2 = MapJointToScreen(joint1).X,
Y2 = MapJointToScreen(joint1).Y
};
Canvas.Children.Add(bone);
}
}
private Point MapJointToScreen(Joint joint)
{
ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
// Gestion des coordonnées infinies
float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
return new Point(x, y);
}
private void drawskeleton(Body body)
{
// tête et cou
drawbone(body, JointType.Head, JointType.Neck);
drawbone(body, JointType.Neck, JointType.SpineShoulder);
// torse
drawbone(body, JointType.SpineShoulder, JointType.SpineMid);
drawbone(body, JointType.SpineMid, JointType.SpineBase);
drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight);
drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft);
drawbone(body, JointType.SpineBase, JointType.HipRight);
drawbone(body, JointType.SpineBase, JointType.HipLeft);
// bras droit
drawbone(body, JointType.ShoulderRight, JointType.ElbowRight);
drawbone(body, JointType.ElbowRight, JointType.WristRight);
drawbone(body, JointType.WristRight, JointType.HandRight);
drawbone(body, JointType.HandRight, JointType.HandTipRight);
drawbone(body, JointType.WristRight, JointType.ThumbRight);
// bras gauche
drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft);
drawbone(body, JointType.ElbowLeft, JointType.WristLeft);
drawbone(body, JointType.WristLeft, JointType.HandLeft);
drawbone(body, JointType.HandLeft, JointType.HandTipLeft);
drawbone(body, JointType.WristLeft, JointType.ThumbLeft);
// jambe droite
drawbone(body, JointType.HipRight, JointType.KneeRight);
drawbone(body, JointType.KneeRight, JointType.AnkleRight);
drawbone(body, JointType.AnkleRight, JointType.FootRight);
// jambe gauche
drawbone(body, JointType.HipLeft, JointType.KneeLeft);
drawbone(body, JointType.KneeLeft, JointType.AnkleLeft);
drawbone(body, JointType.AnkleLeft, JointType.FootLeft);
// dessinez les joints
foreach (JointType JointType in body.Joints.Keys)
{
Joint joint = body.Joints[JointType];
if (joint.TrackingState == TrackingState.Tracked)
{
DrawJoint(MapJointToScreen(joint));
}
}
}
private void DrawJoint(Point point)
{
Ellipse ellipse = new Ellipse
{
Width = 10,
Height = 10,
Fill = new SolidColorBrush(Colors.Red)
};
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
Canvas.Children.Add(ellipse);
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyframe = e.FrameReference.AcquireFrame())
{
if (bodyframe != null)
{
bodyframe.GetAndRefreshBodyData(this.bodies);
Canvas.Children.Clear(); // nettoyer le Canvas avant de dessiner
foreach (var body in this.bodies)
{
if (body.IsTracked)
{
// dessiner le squelette
drawskeleton(body);
}
}
}
}
}
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (ColorFrame 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,70 @@
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(KinectManager kinectManager) : base(kinectManager)
{
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_ColorFrameArrived;
}
public override void Stop()
{
if (reader != null)
{
reader.Dispose();
reader = null;
}
}
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (ColorFrame 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,90 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows;
namespace Lib
{
class DepthImageStream : KinectStream
{
private DepthFrameReader reader;
public DepthFrameReader Reader
{
get
{
return reader;
}
set
{
reader = value;
}
}
private byte[] depthPixels;
public byte[] DepthPixels {
get {
return depthPixels;
}
set
{
depthPixels = value;
}
}
public DepthImageStream(KinectManager kinectManager) : base(kinectManager)
{
var frameDescription = KinectManager.Sensor.DepthFrameSource.FrameDescription;
this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
reader = KinectManager.Sensor.DepthFrameSource.OpenReader();
reader.FrameArrived += Reader_DepthFrameArrived;
DepthPixels = new byte[frameDescription.Width * frameDescription.Height];
}
private void Reader_DepthFrameArrived(object sender, DepthFrameArrivedEventArgs e)
{
using (DepthFrame depthFrame = e.FrameReference.AcquireFrame())
{
if (depthFrame != null)
{
FrameDescription depthFrameDescription = depthFrame.FrameDescription;
// Créez un tableau pour stocker les données de profondeur
ushort[] depthData = new ushort[depthFrameDescription.LengthInPixels];
depthFrame.CopyFrameDataToArray(depthData);
// Traitez les données de profondeur
ProcessDepthFrameData(depthData, depthFrameDescription.LengthInPixels, depthFrame.DepthMinReliableDistance, depthFrame.DepthMaxReliableDistance);
// Mettez à jour le bitmap de profondeur
this.Bitmap.WritePixels(
new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height),
this.depthPixels,
depthFrameDescription.Width,
0);
}
}
}
public override void Stop()
{
if (reader != null)
{
reader.Dispose();
reader = null;
}
}
private void ProcessDepthFrameData(ushort[] depthData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth)
{
// Convertir les données de profondeur en niveaux de gris
for (int i = 0; i < depthFrameDataSize; ++i)
{
ushort depth = depthData[i];
DepthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth % 256) : 0);
}
}
}
}

@ -0,0 +1,92 @@
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
using System.Windows.Media;
using System.Windows;
namespace Lib
{
class InfraredImageStream : KinectStream
{
private InfraredFrameReader reader;
private byte[] infraredPixels;
public byte[] InfraredPixels
{
get
{
return infraredPixels;
}
private set
{
infraredPixels = value;
}
}
public InfraredFrameReader Reader
{
get
{
return reader;
}
private set
{
reader = value;
}
}
public InfraredImageStream(KinectManager kinectManager) : base(kinectManager)
{
var frameDescription = KinectManager.Sensor.InfraredFrameSource.FrameDescription;
this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null);
reader = KinectManager.Sensor.InfraredFrameSource.OpenReader();
reader.FrameArrived += Reader_InfraredFrameArrived;
infraredPixels = new byte[frameDescription.Width * frameDescription.Height];
}
public override void Stop()
{
if (reader != null)
{
reader.Dispose();
reader = null;
}
}
private void ProcessInfraredFrameData(ushort[] frameData, uint frameDataSize)
{
// Convertir les données infrarouges en niveaux de gris
for (int i = 0; i < frameDataSize; ++i)
{
// Convertir la valeur infrarouge en une intensité lumineuse
byte intensity = (byte)(frameData[i] >> 8);
InfraredPixels[i] = intensity;
}
}
private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e)
{
using (InfraredFrame infraredFrame = e.FrameReference.AcquireFrame())
{
if (infraredFrame != null)
{
FrameDescription infraredFrameDescription = infraredFrame.FrameDescription;
// Créez un tableau pour stocker les données infrarouges
ushort[] infraredData = new ushort[infraredFrameDescription.LengthInPixels];
infraredFrame.CopyFrameDataToArray(infraredData);
// Traitez les données infrarouges
ProcessInfraredFrameData(infraredData, infraredFrameDescription.LengthInPixels);
// Mettez à jour le bitmap infrarouge
this.Bitmap.WritePixels(
new Int32Rect(0, 0, infraredFrameDescription.Width, infraredFrameDescription.Height),
this.infraredPixels,
infraredFrameDescription.Width,
0);
}
}
}
}
}

@ -0,0 +1,113 @@
using Microsoft.Kinect;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows.Media;
namespace Lib
{
public class KinectManager : INotifyPropertyChanged
{
private KinectSensor sensor;
public KinectSensor Sensor {
get {
return sensor;
}
set
{
sensor = value;
OnPropertyChanged(nameof(Sensor));
}
}
private SolidColorBrush _kinectStatusColor = new SolidColorBrush(Colors.Red); // Couleur rouge par défaut, signifiant inactive
public SolidColorBrush KinectStatusColor
{
get { return _kinectStatusColor; }
set
{
_kinectStatusColor = value;
OnPropertyChanged(nameof(KinectStatusColor));
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public KinectManager()
{
sensor = KinectSensor.GetDefault();
UpdateStatusProperties();
// Abonnez-vous à l'événement IsAvailableChanged
if (sensor != null)
{
sensor.IsAvailableChanged += KinectSensor_IsAvailableChanged;
}
}
public void StartSensor()
{
if (sensor != null && !sensor.IsOpen) {
sensor.Open();
}
else {
sensor = KinectSensor.GetDefault();
sensor.Open();
}
}
public void StopSensor()
{
if (sensor != null)
{
sensor.Close();
sensor = null;
}
}
public bool Status
{
get { return Sensor != null && Sensor.IsAvailable; }
}
private string _statusText;
public string StatusText
{
get { return _statusText; }
set {
_statusText = value;
if(this.PropertyChanged != null)
{
this.PropertyChanged(this, new PropertyChangedEventArgs("StatusText"));
}
}
}
private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e)
{
UpdateStatusProperties();
}
private void UpdateStatusProperties()
{
if (Sensor == null)
{
StatusText = "Kinect n'est pas connecté";
KinectStatusColor = new SolidColorBrush(Colors.Red);
}
else if (!Sensor.IsOpen)
{
StatusText = "Kinect n'est pas ouvert";
KinectStatusColor = new SolidColorBrush(Colors.Yellow);
}
else if (Sensor.IsAvailable)
{
StatusText = "Kinect est disponible";
KinectStatusColor = new SolidColorBrush(Colors.Green);
}
else
{
StatusText = "Kinect n'est pas disponible";
KinectStatusColor = new SolidColorBrush(Colors.Orange);
}
}
}
}

@ -0,0 +1,65 @@
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.Controls;
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));
}
}
}
private Canvas _canvas;
public Canvas Canvas
{
get { return _canvas; }
protected set
{
_canvas = value;
OnPropertyChanged(nameof(Canvas));
}
}
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public KinectStream(KinectManager kinectManager)
{
KinectManager = kinectManager;
Canvas = null;
if (kinectManager.Sensor == null)
{
KinectManager.StartSensor();
}
}
public virtual void Start()
{
KinectManager.StartSensor();
}
public abstract void Stop();
}
}

@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lib
{
public enum KinectStreams
{
None,
Color,
Depth,
IR,
Body,
ColorAndBody
}
}

@ -0,0 +1,54 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
namespace Lib
{
public class KinectStreamsFactory
{
private KinectManager _kinectManager;
public KinectManager KinectManager {
get { return _kinectManager; }
private set { _kinectManager = value; }
}
private Dictionary<KinectStreams, Func<KinectStream>> _streamFactory;
public Dictionary<KinectStreams, Func<KinectStream>> StreamFactory
{
get { return _streamFactory; }
private set { _streamFactory = value; }
}
public KinectStreamsFactory(KinectManager kinect,Canvas SkeletonCanvas)
{
_kinectManager = kinect;
// Initialisation de la fabrique avec les fonctions de création pour chaque type de flux.
StreamFactory = new Dictionary<KinectStreams, Func<KinectStream>>
{
{ KinectStreams.Color, () => new ColorImageStream(KinectManager) },
{ KinectStreams.Depth, () => new DepthImageStream(KinectManager) },
{ KinectStreams.IR, () => new InfraredImageStream(KinectManager) },
{ KinectStreams.Body, () => new BodyImageStream(KinectManager,SkeletonCanvas) },
{ KinectStreams.ColorAndBody, () => new ColorAndBodyImageStream(KinectManager,SkeletonCanvas) }
};
}
public KinectStream this[KinectStreams stream]
{
get
{
if (StreamFactory.ContainsKey(stream))
{
return StreamFactory[stream]();
}
else
{
throw new ArgumentException("Invalid stream type.");
}
}
}
}
}

@ -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,35 @@
<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="PresentationFramework" />
<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="BodyImageStream.cs" />
<Compile Include="ColorAndBodyImageStream.cs" />
<Compile Include="ColorImageStream.cs" />
<Compile Include="DepthImageStream.cs" />
<Compile Include="InfraredImageStream.cs" />
<Compile Include="KinectManager.cs" />
<Compile Include="KinectStream.cs" />
<Compile Include="KinectStreams.cs" />
<Compile Include="KinectStreamsFactory.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>

@ -0,0 +1,67 @@
<?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>{2496DFB1-EB55-47A1-A780-211E079B289D}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>LibMyGesturesBank</RootNamespace>
<AssemblyName>MyGesturesBank</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<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="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" />
</ItemGroup>
<ItemGroup>
<Compile Include="PostureHandsOnHead .cs" />
<Compile Include="PostureHandUp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RightHandUp.cs" />
<Compile Include="TwoHandsDragon.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2d44487e-f514-4063-9494-2af1e8c9e9c8}</Project>
<Name>KinectUtils</Name>
</ProjectReference>
<ProjectReference Include="..\Lib\Lib.csproj">
<Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project>
<Name>Lib</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,17 @@
using Microsoft.Kinect;
using KinectUtils;
namespace MyGesturesBank
{
public class PostureHandUp : Posture
{
protected override bool TestPosture(Body body)
{
// Exemple de condition : la main droite est plus haute que l'épaule droite
return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.ShoulderRight].Position.Y;
}
public override string GestureName => "Hand Up";
}
}

@ -0,0 +1,34 @@
using Microsoft.Kinect;
using System;
using KinectUtils;
namespace MyGesturesBank
{
public class PostureHandsOnHead : Posture
{
protected override bool TestPosture(Body body)
{
// Condition pour la main droite proche de la tête
bool rightHandNearHead = IsHandNearHead(body.Joints[JointType.HandRight], body.Joints[JointType.Head]);
// Condition pour la main gauche proche de la tête
bool leftHandNearHead = IsHandNearHead(body.Joints[JointType.HandLeft], body.Joints[JointType.Head]);
return rightHandNearHead && leftHandNearHead;
}
private bool IsHandNearHead(Joint hand, Joint head)
{
// Exemple de condition : la main est à moins de 30 cm de la tête
return Math.Sqrt(
Math.Pow(hand.Position.X - head.Position.X, 2) +
Math.Pow(hand.Position.Y - head.Position.Y, 2) +
Math.Pow(hand.Position.Z - head.Position.Z, 2)) < 0.3;
}
public override string GestureName => "Hands On Head";
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("MyGesturesBank")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MyGesturesBank")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("2496dfb1-eb55-47a1-a780-211e079b289d")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -4,9 +4,9 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Lib
namespace LibMyGesturesBank
{
public class Class1
internal class RightHandUp
{
}
}

@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibMyGesturesBank
{
internal class TwoHandsDragon
{
}
}

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

@ -0,0 +1,55 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media;
namespace WpfApp
{
public class Bone : INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propName)
{
if(PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propName));
}
}
private double _top;
public double Top
{
get { return _top; }
set {
_top = value;
OnPropertyChanged(nameof(Top));
}
}
public double Left
{
get;
set;
}
public double Diameter
{
get
{
return _diameter;
}
set
{
_diameter = value;
OnPropertyChanged(nameof(Diameter));
}
}
private double _diameter;
public SolidColorBrush ColorBrush {
get;
set;
}
}
}

@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace WpfApp
{
class Bones : Collection<Bone>
{
public Bones() {
Add(new Bone { });
}
}
}

@ -14,20 +14,23 @@
</Grid.RowDefinitions>
<StackPanel Grid.Row="0" Orientation="Horizontal" VerticalAlignment="Top">
<Ellipse Width="20" Height="20" Fill="Green" />
<TextBlock Text="Statut" VerticalAlignment="Center" Margin="5,0,0,0"/>
<Ellipse Width="20" Height="20" Fill="{Binding CurrentKinectStream.KinectManager.KinectStatusColor}" />
<TextBlock Text="{Binding CurrentKinectStream.KinectManager.StatusText}" VerticalAlignment="Center" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Grid.Row="1" Orientation="Horizontal" VerticalAlignment="Top">
<Button Content="Filtre 1" Margin="5"/>
<Button Content="Filtre 2" Margin="5"/>
<Button Content="Filtre 3" Margin="5"/>
<Button Content="Filtre 4" Margin="5"/>
<Button Content="Filtre 5" Margin="5"/>
<Button Content="Color" Margin="5" Click="ToColorImageStream"/>
<Button Content="Depth" Margin="5" Click="ToDepthImageStream"/>
<Button Content="Infrared" Margin="5" Click="ToInfraredImageStream"/>
<Button Content="Body" Margin="5" Click="ToBodyImageStream"/>
<Button Content="BodyAndColor" Margin="5" Click="ToColorAndBodyImageStream"/>
</StackPanel>
<Image Grid.Row="2" Source="{Binding ColorBitmap}" />
<Viewbox Grid.Row="2" Stretch="Uniform">
<Grid>
<Image Grid.Row="2" Source="{Binding CurrentKinectStream.Bitmap}" />
<Canvas Grid.Row="2" x:Name="skeletonCanvas" />
</Grid>
</Viewbox>
</Grid>
</Window>

@ -1,6 +1,9 @@
using Microsoft.Kinect;
using Lib;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -19,155 +22,94 @@ namespace WpfApp
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
public partial class MainWindow : Window,INotifyPropertyChanged
{
private KinectSensor kinectSensor = null;
private ColorFrameReader colorFrameReader = null;
private WriteableBitmap colorBitmap = null;
private BodyFrameReader bodyFrameReader = null;
private Body[] bodies = null;
// Propriété publique pour le binding
public WriteableBitmap ColorBitmap
private KinectManager kinectManager;
public KinectManager KinectManager
{
get { return this.colorBitmap; }
get { return kinectManager; }
set { kinectManager = value; }
}
public MainWindow()
private KinectStream _currentKinectStream;
public KinectStream CurrentKinectStream
{
InitializeComponent();
// Définir le DataContext pour le binding
this.DataContext = this;
// Initialiser la Kinect
this.kinectSensor = KinectSensor.GetDefault();
// Ouvrir le lecteur de flux de couleur
this.colorFrameReader = this.kinectSensor.ColorFrameSource.OpenReader();
// Frame description pour les images de couleur
FrameDescription colorFrameDescription = this.kinectSensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra);
// Créer le bitmap pour afficher l'image
this.colorBitmap = new WriteableBitmap(colorFrameDescription.Width, colorFrameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null);
// Gérer l'événement FrameArrived pour le flux de couleur
this.colorFrameReader.FrameArrived += this.Reader_ColorFrameArrived;
// Initialisation du BodyFrameReader
this.bodyFrameReader = this.kinectSensor.BodyFrameSource.OpenReader();
this.bodyFrameReader.FrameArrived += this.Reader_BodyFrameArrived;
// Initialiser le tableau des corps
this.bodies = new Body[this.kinectSensor.BodyFrameSource.BodyCount];
// Ouvrir la Kinect
this.kinectSensor.Open();
get { return _currentKinectStream; }
set {
_currentKinectStream = value;
OnPropertyChanged(nameof(CurrentKinectStream));
}
}
public event PropertyChangedEventHandler PropertyChanged;
private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e)
{
using (ColorFrame colorFrame = e.FrameReference.AcquireFrame())
{
if (colorFrame != null)
public void OnPropertyChanged(string propertyName)
{
FrameDescription colorFrameDescription = colorFrame.FrameDescription;
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer())
private KinectStreamsFactory _factory;
public KinectStreamsFactory Factory
{
this.colorBitmap.Lock();
get { return _factory; }
set { _factory = value; }
}
// Vérifier si la taille de l'image a changé
if ((colorFrameDescription.Width == this.colorBitmap.PixelWidth) && (colorFrameDescription.Height == this.colorBitmap.PixelHeight))
public MainWindow()
{
colorFrame.CopyConvertedFrameDataToIntPtr(
this.colorBitmap.BackBuffer,
(uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4),
ColorImageFormat.Bgra);
InitializeComponent();
this.DataContext = this;
KinectManager = new KinectManager();
Factory = new KinectStreamsFactory(KinectManager, skeletonCanvas);
CurrentKinectStream = Factory[KinectStreams.Color];
Debug.WriteLine(CurrentKinectStream.KinectManager.StatusText);
CurrentKinectStream.Start();
Debug.WriteLine(CurrentKinectStream.KinectManager.StatusText);
this.colorBitmap.AddDirtyRect(new Int32Rect(0, 0, this.colorBitmap.PixelWidth, this.colorBitmap.PixelHeight));
}
this.colorBitmap.Unlock();
}
}
}
}
// Assurez-vous de fermer correctement le lecteur et le capteur Kinect lors de la fermeture de la fenêtre
private void MainWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
if (this.colorFrameReader != null)
{
this.colorFrameReader.Dispose();
this.colorFrameReader = null;
Debug.WriteLine(CurrentKinectStream.KinectManager.StatusText);
CurrentKinectStream.Stop();
}
if (this.kinectSensor != null)
private void ToColorImageStream(object sender, RoutedEventArgs e)
{
this.kinectSensor.Close();
this.kinectSensor = null;
}
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.Color];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
bodyFrame.GetAndRefreshBodyData(this.bodies);
skeletonCanvas.Children.Clear(); // Nettoyer le canvas avant de dessiner
foreach (var body in this.bodies)
{
if (body.IsTracked)
private void ToDepthImageStream(object sender, RoutedEventArgs e)
{
// Dessiner le squelette
DrawSkeleton(body);
}
}
}
}
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.Depth];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
private void DrawSkeleton(Body body)
private void ToInfraredImageStream(object sender, RoutedEventArgs e)
{
foreach (JointType jointType in body.Joints.Keys)
{
Joint joint = body.Joints[jointType];
if (joint.TrackingState == TrackingState.Tracked)
{
// Convertir les coordonnées du joint en coordonnées de l'écran
Point point = new Point();
ColorSpacePoint colorPoint = this.kinectSensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position);
point.X = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X;
point.Y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y;
// Dessiner le joint
DrawJoint(point);
}
}
// Dessinez les os ici si nécessaire
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.IR];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
private void DrawJoint(Point point)
private void ToBodyImageStream(object sender, RoutedEventArgs e)
{
Ellipse ellipse = new Ellipse
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.Body];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
private void ToColorAndBodyImageStream(object sender, RoutedEventArgs e)
{
Width = 10,
Height = 10,
Fill = new SolidColorBrush(Colors.Red)
};
Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2);
Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2);
skeletonCanvas.Children.Add(ellipse);
CurrentKinectStream.Stop();
CurrentKinectStream = Factory[KinectStreams.ColorAndBody];
Debug.WriteLine(CurrentKinectStream.GetType().Name);
CurrentKinectStream.Start();
}
}
}

@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using Lib;
namespace WpfApp
{
class StreamTemplateSelector : DataTemplateSelector
{
public DataTemplate ColorAndBodyImageStreamTemplate { get; set; }
public DataTemplate OtherStreamTemplate { get; set; }
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
if (item is BodyImageStream) return ColorAndBodyImageStreamTemplate;
else return OtherStreamTemplate;
}
}
}

@ -58,6 +58,9 @@
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="Bone.cs" />
<Compile Include="Bones.cs" />
<Compile Include="StreamTemplateSelector.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
@ -98,5 +101,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