more gestures

exo2
lobroda 1 year ago
parent 9a8cff6915
commit ec2bff1e45

@ -3,15 +3,17 @@ using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace KinectUtils
{
public class GestureManager
public static class GestureManager
{
private static bool isAcquiringFrame;
private static bool isAcquiringFrame = false; // false by default
private static BodyFrameReader bodyFrameReader;
// Properties
@ -32,7 +34,7 @@ namespace KinectUtils
public static void AddGestures(BaseGesture[] baseGestures) // params ???
{
throw new NotImplementedException();
KnownGestures.AddRange(baseGestures);
}
public static void RemoveGesture(BaseGesture baseGesture)
@ -45,8 +47,8 @@ namespace KinectUtils
{
if (!isAcquiringFrame)
{
KinectManager.KinectSensor.Open();
bodyFrameReader = KinectManager.KinectSensor.BodyFrameSource.OpenReader();
manager.KinectSensor.Open();
bodyFrameReader = manager.KinectSensor.BodyFrameSource.OpenReader();
bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
isAcquiringFrame = true;
}
@ -56,7 +58,7 @@ namespace KinectUtils
{
if (isAcquiringFrame)
{
KinectManager.KinectSensor.Close();
manager.KinectSensor.Close();
bodyFrameReader.FrameArrived -= BodyFrameReader_FrameArrived;
isAcquiringFrame = false;
}
@ -75,7 +77,17 @@ namespace KinectUtils
{
if (body.IsTracked)
{
//postureHandUpRight.TestGesture(body);
foreach (var gesture in KnownGestures)
{
if (gesture != null)
{
gesture.TestGesture(body);
}
else
{
Console.WriteLine("gesture null");
}
}
}
}
}

@ -44,9 +44,13 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="PostureHandDownLeft.cs" />
<Compile Include="PostureHandDownRight.cs" />
<Compile Include="PostureHandUpLeft.cs" />
<Compile Include="PostureHandUpRight.cs" />
<Compile Include="PostureTwoHandsUp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="PostureTwoHandsDown.cs" />
</ItemGroup>
<ItemGroup>
<None Include="app.config" />

@ -0,0 +1,49 @@
using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MyGestureBank
{
/// <summary>
/// The right hand down posture.
/// </summary>
public class PostureHandDownLeft : Posture
{
public PostureHandDownLeft()
{
GestureName = "Hand Down Left";
}
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand down left");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary>
/// The test posture method.
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
protected override bool TestPosture(Body body)
{
// Check if the left hand is below the left hip
return body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.HipLeft].Position.Y;
}
}
}

@ -0,0 +1,49 @@
using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MyGestureBank
{
/// <summary>
/// The right hand down posture.
/// </summary>
public class PostureHandDownRight : Posture
{
public PostureHandDownRight()
{
GestureName = "Hand Down Right";
}
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand down right");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary>
/// The test posture method.
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
protected override bool TestPosture(Body body)
{
// Check if right hand is below the right hip
return body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.HipRight].Position.Y;
}
}
}

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MyGestureBank
@ -26,6 +27,9 @@ namespace MyGestureBank
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand up left");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
@ -39,7 +43,8 @@ namespace MyGestureBank
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;
return body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y;
}
}
}

@ -5,6 +5,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Kinect;
using System.Threading;
namespace MyGestureBank
{
@ -29,6 +30,8 @@ namespace MyGestureBank
{
if(TestPosture(body))
{
Console.WriteLine("Gesture recognized, hand up right");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
@ -40,7 +43,8 @@ namespace MyGestureBank
/// <returns>A boolean indicating wheter the posture was detected or not.</returns>
protected override bool TestPosture(Body body)
{
return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.ShoulderRight].Position.Y;
return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y;
}
}
}

@ -0,0 +1,51 @@
using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MyGestureBank
{
/// <summary>
/// The two in the middle.
/// </summary>
public class PostureTwoHandsDown : Posture
{
public PostureTwoHandsDown()
{
GestureName = "Both hands middle.";
}
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, both hands middle");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary>
/// The test posture method.
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
protected override bool TestPosture(Body body)
{
// Check if two hands are up
return body.Joints[JointType.HandRight].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.HipRight].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y < body.Joints[JointType.SpineShoulder].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.HipLeft].Position.Y;
}
}
}

@ -0,0 +1,50 @@
using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MyGestureBank
{
/// <summary>
/// The two hands up posture.
/// </summary>
public class PostureTwoHandsUp : Posture
{
public PostureTwoHandsUp()
{
GestureName = "Two Hands Up";
}
/// <summary>
/// The test gesture method.
/// </summary>
/// <param name="body">The body</param>
public override void TestGesture(Body body)
{
if (TestPosture(body))
{
Console.WriteLine("Gesture recognized, two hands up");
Thread.Sleep(1000);
OnGestureRecognized();
}
}
/// <summary>
/// The test posture method.
/// </summary>
/// <param name="body"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
protected override bool TestPosture(Body body)
{
// Check if two hands are up
return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.ShoulderRight].Position.Y &&
body.Joints[JointType.HandLeft].Position.Y > body.Joints[JointType.ShoulderLeft].Position.Y;
}
}
}

@ -54,6 +54,10 @@
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\KinectConnection\KinectConnection.csproj">
<Project>{E527438A-DFA2-4EC6-9891-D4956152B093}</Project>
<Name>KinectConnection</Name>
</ProjectReference>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2BC300E4-D3C1-4E17-A011-380EDB793182}</Project>
<Name>KinectUtils</Name>

@ -12,63 +12,90 @@ namespace PostureTester
{
public class Program
{
private static KinectSensor kinectSensor;
private static PostureHandUpRight postureHandUpRight = new PostureHandUpRight();
static void Main(string[] args)
{
kinectSensor = KinectSensor.GetDefault();
postureHandUpRight.GestureRecognized += PostureHandUpRight_GestureRecognized;
if (kinectSensor != null)
{
kinectSensor.Open();
// Utilisation du bloc using pour bodyFrameReader
using (var bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader())
{
if (bodyFrameReader != null)
{
// Abonnement à l'événement FrameArrived
bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
Console.WriteLine("Lecture des données du corps en cours... Appuyez sur une touche pour quitter.");
Console.ReadKey();
}
}
}
if (kinectSensor != null)
{
kinectSensor.Close();
kinectSensor = null;
}
}
PostureHandUpRight postureHandUpRight = new PostureHandUpRight();
PostureHandUpLeft postureHandUpLeft = new PostureHandUpLeft();
PostureHandDownLeft postureHandDownLeft = new PostureHandDownLeft();
PostureHandDownRight postureHandDownRight = new PostureHandDownRight();
PostureTwoHandsDown postureTwoHandsDown = new PostureTwoHandsDown();
PostureTwoHandsUp postureTwoHandsUp = new PostureTwoHandsUp();
private static void BodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
Body[] bodies = new Body[bodyFrame.BodyCount];
bodyFrame.GetAndRefreshBodyData(bodies);
foreach (Body body in bodies)
{
if (body.IsTracked)
{
postureHandUpRight.TestGesture(body);
}
}
}
}
}
private static void PostureHandUpRight_GestureRecognized(object sender, GestureRecognizedEventArgs e)
{
Console.WriteLine("Posture Hand Up Right reconnue !");
BaseGesture[] gestures = new BaseGesture[6];
gestures[0] = postureHandUpLeft;
gestures[1] = postureHandUpRight;
gestures[2] = postureHandDownLeft;
gestures[3] = postureHandDownRight;
gestures[4] = postureTwoHandsDown;
gestures[5] = postureTwoHandsUp;
GestureManager.AddGestures(gestures);
GestureManager.StartAcquiringFrames(GestureManager.KinectManager);
// Keep the program running until a key is pressed
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
}
}
/* private static KinectSensor kinectSensor;
private static PostureHandUpRight postureHandUpRight = new PostureHandUpRight();
static void Main(string[] args)
{
kinectSensor = KinectSensor.GetDefault();
postureHandUpRight.GestureRecognized += PostureHandUpRight_GestureRecognized;
if (kinectSensor != null)
{
kinectSensor.Open();
// Utilisation du bloc using pour bodyFrameReader
using (var bodyFrameReader = kinectSensor.BodyFrameSource.OpenReader())
{
if (bodyFrameReader != null)
{
// Abonnement à l'événement FrameArrived
bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
Console.WriteLine("Lecture des données du corps en cours... Appuyez sur une touche pour quitter.");
Console.ReadKey();
}
}
}
if (kinectSensor != null)
{
kinectSensor.Close();
kinectSensor = null;
}
}
private static void BodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var bodyFrame = e.FrameReference.AcquireFrame())
{
if (bodyFrame != null)
{
Body[] bodies = new Body[bodyFrame.BodyCount];
bodyFrame.GetAndRefreshBodyData(bodies);
foreach (Body body in bodies)
{
if (body.IsTracked)
{
postureHandUpRight.TestGesture(body);
}
}
}
}
}
private static void PostureHandUpRight_GestureRecognized(object sender, GestureRecognizedEventArgs e)
{
Console.WriteLine("Posture Hand Up Right reconnue !");
}*/
}
}

Loading…
Cancel
Save