From 50a988422c21e04868d4ffb40af2ff9f13a301b5 Mon Sep 17 00:00:00 2001 From: "louis.dufour" Date: Thu, 25 Jan 2024 16:36:57 +0100 Subject: [PATCH 1/2] Update(Gesture): Body frame avec les os --- Sources/KinectSolution.sln | 6 ++ Sources/LibMyGesturesBank/BaseGesture.cs | 30 ++++++ .../LibMyGesturesBank.csproj | 63 +++++++++++++ Sources/LibMyGesturesBank/Posture.cs | 27 ++++++ Sources/LibMyGesturesBank/PostureHandUp.cs | 21 +++++ .../LibMyGesturesBank/PostureHandsOnHead .cs | 37 ++++++++ .../Properties/AssemblyInfo.cs | 36 +++++++ Sources/LibMyGesturesBank/packages.config | 4 + Sources/WpfApp/MainWindow.xaml | 8 +- Sources/WpfApp/MainWindow.xaml.cs | 93 ++++++++++++++++--- 10 files changed, 309 insertions(+), 16 deletions(-) create mode 100644 Sources/LibMyGesturesBank/BaseGesture.cs create mode 100644 Sources/LibMyGesturesBank/LibMyGesturesBank.csproj create mode 100644 Sources/LibMyGesturesBank/Posture.cs create mode 100644 Sources/LibMyGesturesBank/PostureHandUp.cs create mode 100644 Sources/LibMyGesturesBank/PostureHandsOnHead .cs create mode 100644 Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs create mode 100644 Sources/LibMyGesturesBank/packages.config diff --git a/Sources/KinectSolution.sln b/Sources/KinectSolution.sln index d187b5e..26c77a6 100644 --- a/Sources/KinectSolution.sln +++ b/Sources/KinectSolution.sln @@ -7,6 +7,8 @@ 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}") = "LibMyGesturesBank", "LibMyGesturesBank\LibMyGesturesBank.csproj", "{2496DFB1-EB55-47A1-A780-211E079B289D}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +23,10 @@ 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 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/LibMyGesturesBank/BaseGesture.cs b/Sources/LibMyGesturesBank/BaseGesture.cs new file mode 100644 index 0000000..7ba9866 --- /dev/null +++ b/Sources/LibMyGesturesBank/BaseGesture.cs @@ -0,0 +1,30 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System; +using Microsoft.Kinect; + +namespace LibMyGesturesBank +{ + 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 virtual 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() + { + GestureRecognized?.Invoke(this, EventArgs.Empty); + } + } + + +} diff --git a/Sources/LibMyGesturesBank/LibMyGesturesBank.csproj b/Sources/LibMyGesturesBank/LibMyGesturesBank.csproj new file mode 100644 index 0000000..805bf1d --- /dev/null +++ b/Sources/LibMyGesturesBank/LibMyGesturesBank.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {2496DFB1-EB55-47A1-A780-211E079B289D} + Library + Properties + LibMyGesturesBank + LibMyGesturesBank + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll + + + + + + + + + + + + + + + + + + + + {0751c83e-7845-4e5f-a5d3-e11aba393aca} + Lib + + + + + + + \ No newline at end of file diff --git a/Sources/LibMyGesturesBank/Posture.cs b/Sources/LibMyGesturesBank/Posture.cs new file mode 100644 index 0000000..de00509 --- /dev/null +++ b/Sources/LibMyGesturesBank/Posture.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using Microsoft.Kinect; +using System.Threading.Tasks; + +namespace LibMyGesturesBank +{ + + public abstract class Posture : BaseGesture + { + protected abstract bool TestPosture(Body body); + + public override void TestGesture(Body body) + { + if (TestPosture(body)) + { + // Posture is recognized + OnGestureRecognized(); + } + } + + // Ajoutez ici d'autres méthodes ou propriétés nécessaires + } + +} diff --git a/Sources/LibMyGesturesBank/PostureHandUp.cs b/Sources/LibMyGesturesBank/PostureHandUp.cs new file mode 100644 index 0000000..970f01e --- /dev/null +++ b/Sources/LibMyGesturesBank/PostureHandUp.cs @@ -0,0 +1,21 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibMyGesturesBank +{ + 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"; + } + +} diff --git a/Sources/LibMyGesturesBank/PostureHandsOnHead .cs b/Sources/LibMyGesturesBank/PostureHandsOnHead .cs new file mode 100644 index 0000000..34ea5b1 --- /dev/null +++ b/Sources/LibMyGesturesBank/PostureHandsOnHead .cs @@ -0,0 +1,37 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibMyGesturesBank +{ + 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"; + + } + + +} diff --git a/Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs b/Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..4138d3e --- /dev/null +++ b/Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs @@ -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("LibMyGesturesBank")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("LibMyGesturesBank")] +[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")] diff --git a/Sources/LibMyGesturesBank/packages.config b/Sources/LibMyGesturesBank/packages.config new file mode 100644 index 0000000..f7f19c3 --- /dev/null +++ b/Sources/LibMyGesturesBank/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml index d2f7fdc..5d50914 100644 --- a/Sources/WpfApp/MainWindow.xaml +++ b/Sources/WpfApp/MainWindow.xaml @@ -26,8 +26,12 @@