From 083f08a901f0ec34b97925c54dda9cc4fe38bf19 Mon Sep 17 00:00:00 2001 From: "louis.dufour" Date: Wed, 7 Feb 2024 08:00:24 +0100 Subject: [PATCH] Add(dev): testgesture and basegesture --- Sources/KinectUtils/BaseGesture.cs | 17 +++++++++--- Sources/KinectUtils/Gesture.cs | 43 ++++++++++++++++++++---------- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Sources/KinectUtils/BaseGesture.cs b/Sources/KinectUtils/BaseGesture.cs index c12223a..c414db6 100644 --- a/Sources/KinectUtils/BaseGesture.cs +++ b/Sources/KinectUtils/BaseGesture.cs @@ -9,17 +9,28 @@ namespace KinectUtils public event EventHandler GestureRecognized; // Nom du geste - marqué comme virtual pour permettre la substitution - public virtual string GestureName { get; protected set; } + 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() + protected virtual void OnGestureRecognized(Body body) { - GestureRecognized?.Invoke(this, EventArgs.Empty); + 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; + } + } } diff --git a/Sources/KinectUtils/Gesture.cs b/Sources/KinectUtils/Gesture.cs index f1140b3..1315626 100644 --- a/Sources/KinectUtils/Gesture.cs +++ b/Sources/KinectUtils/Gesture.cs @@ -9,23 +9,38 @@ namespace KinectUtils { abstract class Gesture : BaseGesture { - protected int _maxNbOfFrames; - protected int _minNbOfFrames; - private int currentFrameCount; - public bool isRecognitionRunning { get; set; } - public int MinNbOfFrames { - get { return _minNbOfFrames; } - private set { _minNbOfFrames = value; } - } - public int MaxNbOfFrames - { - get { return _maxNbOfFrames; } - private set { _maxNbOfFrames = value; } - } + 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);