From 28c8bb6b1f6d7464ae50e8a3e727be14a79d9c0a Mon Sep 17 00:00:00 2001 From: Nicolas FRANCO Date: Wed, 31 Jan 2024 19:16:52 +0100 Subject: [PATCH] started posture --- KinectUtils/BaseGesture.cs | 28 ++++++++++++-- KinectUtils/GestureRecognizedEventArgs.cs | 25 +++++++++++++ KinectUtils/KinectUtils.csproj | 1 + KinectUtils/Posture.cs | 8 ++++ MyGestureBank/MyGestureBank.csproj | 1 + MyGestureBank/PostureHandUpLeft.cs | 45 +++++++++++++++++++++++ MyGestureBank/PostureHandUpRight.cs | 24 ++++++++++-- 7 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 KinectUtils/GestureRecognizedEventArgs.cs create mode 100644 MyGestureBank/PostureHandUpLeft.cs diff --git a/KinectUtils/BaseGesture.cs b/KinectUtils/BaseGesture.cs index 78e2959..722b4b7 100644 --- a/KinectUtils/BaseGesture.cs +++ b/KinectUtils/BaseGesture.cs @@ -7,17 +7,39 @@ using Microsoft.Kinect; namespace KinectUtils { + /// + /// The base gesture. + /// public abstract class BaseGesture { + /// + /// The base gesture initializer. + /// public BaseGesture() { } + /// + /// The gesture name. + /// public string GestureName { get; set; } - // a faire nous mêmes - public EventHandler GestureRecognized { get; set; } + /// + /// The gesture recognized event. + /// + public EventHandler GestureRecognized { get; set; } + /// + /// The test gesture. + /// + /// public abstract void TestGesture(Body body); - protected void OnGestureRecognized() { } + + /// + /// The on gesture recognized method. + /// + protected void OnGestureRecognized() + { + GestureRecognized?.Invoke(this, new GestureRecognizedEventArgs(GestureName)); + } } } diff --git a/KinectUtils/GestureRecognizedEventArgs.cs b/KinectUtils/GestureRecognizedEventArgs.cs new file mode 100644 index 0000000..f1bec57 --- /dev/null +++ b/KinectUtils/GestureRecognizedEventArgs.cs @@ -0,0 +1,25 @@ +using Microsoft.Kinect; + +namespace KinectUtils +{ + /// + /// The gesture recognized event args. + /// + public class GestureRecognizedEventArgs + { + /// + /// The gesture name. + /// + public string GestureName { get; set; } + + /// + /// Initializes a new instance of the class. + /// + /// + /// + public GestureRecognizedEventArgs(string gestureName) + { + GestureName = gestureName; + } + } +} \ No newline at end of file diff --git a/KinectUtils/KinectUtils.csproj b/KinectUtils/KinectUtils.csproj index fae58af..79bf911 100644 --- a/KinectUtils/KinectUtils.csproj +++ b/KinectUtils/KinectUtils.csproj @@ -46,6 +46,7 @@ + diff --git a/KinectUtils/Posture.cs b/KinectUtils/Posture.cs index 5d86ede..7bb5e6a 100644 --- a/KinectUtils/Posture.cs +++ b/KinectUtils/Posture.cs @@ -7,8 +7,16 @@ using System.Threading.Tasks; namespace KinectUtils { + /// + /// The posture class. + /// public abstract class Posture : BaseGesture { + /// + /// Tests the posture. + /// + /// The body + /// protected abstract bool TestPosture(Body body); } } diff --git a/MyGestureBank/MyGestureBank.csproj b/MyGestureBank/MyGestureBank.csproj index fe715e5..6dca24d 100644 --- a/MyGestureBank/MyGestureBank.csproj +++ b/MyGestureBank/MyGestureBank.csproj @@ -44,6 +44,7 @@ + diff --git a/MyGestureBank/PostureHandUpLeft.cs b/MyGestureBank/PostureHandUpLeft.cs new file mode 100644 index 0000000..348eaa1 --- /dev/null +++ b/MyGestureBank/PostureHandUpLeft.cs @@ -0,0 +1,45 @@ +using KinectUtils; +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MyGestureBank +{ + /// + /// The left hand up posture. + /// + public class PostureHandUpLeft : Posture + { + public PostureHandUpLeft() + { + GestureName = "HandUpLeft"; + } + + /// + /// The test gesture method. + /// + /// The body + public override void TestGesture(Body body) + { + if (TestPosture(body)) + { + OnGestureRecognized(); + } + } + + /// + /// The test posture method. + /// + /// + /// + /// + protected override bool TestPosture(Body body) + { + // Check if the left hand is above the left shoulder + return body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.ShoulderLeft].Position.Y; + } + } +} diff --git a/MyGestureBank/PostureHandUpRight.cs b/MyGestureBank/PostureHandUpRight.cs index bb43f57..347e97e 100644 --- a/MyGestureBank/PostureHandUpRight.cs +++ b/MyGestureBank/PostureHandUpRight.cs @@ -8,16 +8,34 @@ using Microsoft.Kinect; namespace MyGestureBank { - public class PostureHandUpRight : Posture + /// + /// The hand up right posture. + /// + public class PostureHandUpRight : Posture { + /// + /// PostureHandUpRight constructor. + /// + public PostureHandUpRight() + { + GestureName = "HandUpRight"; + } + + /// + /// The test gesture method. + /// + /// public override void TestGesture(Body body) { - throw new NotImplementedException(); + if(TestPosture(body)) + { + OnGestureRecognized(); + } } protected override bool TestPosture(Body body) { - throw new NotImplementedException(); + return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.ShoulderRight].Position.Y; } } }