From 77f04c9162e3475777fbb6ce191814781b12e74f Mon Sep 17 00:00:00 2001 From: "johan.lachenal" Date: Wed, 7 Feb 2024 09:01:35 +0100 Subject: [PATCH] UPDATE(KinectUtils) --- Sources/KinectUtils/AllGesturesFactory.cs | 5 +++- Sources/KinectUtils/Gesture.cs | 7 +++-- Sources/KinectUtils/GestureManager.cs | 31 ++++++++++++++++++++--- 3 files changed, 37 insertions(+), 6 deletions(-) diff --git a/Sources/KinectUtils/AllGesturesFactory.cs b/Sources/KinectUtils/AllGesturesFactory.cs index 970478a..7ef77ae 100644 --- a/Sources/KinectUtils/AllGesturesFactory.cs +++ b/Sources/KinectUtils/AllGesturesFactory.cs @@ -10,7 +10,10 @@ namespace KinectUtils { public IEnumerable CreateGestures() { - throw new NotImplementedException(); + return new List + { + new PostureHandsOnHead() + }; } } } diff --git a/Sources/KinectUtils/Gesture.cs b/Sources/KinectUtils/Gesture.cs index f1140b3..42dd8ad 100644 --- a/Sources/KinectUtils/Gesture.cs +++ b/Sources/KinectUtils/Gesture.cs @@ -22,9 +22,12 @@ namespace KinectUtils get { return _maxNbOfFrames; } private set { _maxNbOfFrames = value; } } - public override void TestGesture(Body body) + public bool TestGesture(Body body) { - + TestInitialConditions(body); + TestPosture(body); + TestRunningGesture(body); + TestEndConditions(body); } abstract protected bool TestInitialConditions(Body body); abstract protected bool TestPosture(Body body); diff --git a/Sources/KinectUtils/GestureManager.cs b/Sources/KinectUtils/GestureManager.cs index 339375f..b1e2cce 100644 --- a/Sources/KinectUtils/GestureManager.cs +++ b/Sources/KinectUtils/GestureManager.cs @@ -1,14 +1,18 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Runtime.Remoting.Messaging; using System.Text; using System.Threading.Tasks; using Lib; +using Microsoft.Kinect; namespace KinectUtils { static class GestureManager { + static private BodyFrameReader bodyFrameReader; + static private Body[] bodies; static event EventHandler GestureRecognized; static KinectManager KinectManager { get; set; } static List KnownGestures { get; set; } @@ -30,11 +34,32 @@ namespace KinectUtils } static public void StartAcquiringFrames(KinectManager kinectManager) { - throw new NotImplementedException(); + bodyFrameReader = kinectManager.Sensor.BodyFrameSource.OpenReader(); + bodyFrameReader.FrameArrived += Reader_BodyFrameArrived; } - static public void StopAcquiringFrames() + + static private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) { - throw new NotImplementedException(); + using (var bodyframe = e.FrameReference.AcquireFrame()) + { + if (bodyframe != null) + { + bodyframe.GetAndRefreshBodyData(bodies); + foreach (var body in bodies) + { + if (body.IsTracked) + { + foreach(var gesture in KnownGestures) + { + if (gesture.TestGesture(body)) + { + + } + } + } + } + } + } } } }