Louis DUFOUR 1 year ago
commit 53f080b7cf

@ -36,6 +36,7 @@
<Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.Kinect, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll</HintPath> <HintPath>..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll</HintPath>
</Reference> </Reference>
<Reference Include="PresentationFramework" />
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" /> <Reference Include="System.Xml.Linq" />
@ -54,6 +55,14 @@
<None Include="packages.config" /> <None Include="packages.config" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2d44487e-f514-4063-9494-2af1e8c9e9c8}</Project>
<Name>KinectUtils</Name>
</ProjectReference>
<ProjectReference Include="..\LibMyGesturesBank\MyGesturesBank.csproj">
<Project>{2496DFB1-EB55-47A1-A780-211E079B289D}</Project>
<Name>MyGesturesBank</Name>
</ProjectReference>
<ProjectReference Include="..\Lib\Lib.csproj"> <ProjectReference Include="..\Lib\Lib.csproj">
<Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project> <Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project>
<Name>Lib</Name> <Name>Lib</Name>

@ -1,11 +1,14 @@
using Lib; using Lib;
using Microsoft.Kinect; using Microsoft.Kinect;
using MyGesturesBank;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Controls;
namespace ConsoleApp namespace ConsoleApp
{ {
@ -13,6 +16,32 @@ namespace ConsoleApp
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
KinectManager kinectManager = new KinectManager();
Canvas skeletonCanvas = null;
KinectStreamsFactory Factory = new KinectStreamsFactory(kinectManager, skeletonCanvas);
BodyImageStream CurrentKinectStream = (BodyImageStream)Factory[KinectStreams.Body];
CurrentKinectStream.Start();
PostureHandUp handUpPosture = new PostureHandUp();
PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead();
handUpPosture.GestureRecognized += (sender, e) =>
{
Console.WriteLine("Posture Hand Up reconnue !");
};
handsOnHeadPosture.GestureRecognized += (sender, e) =>
{
Console.WriteLine("Posture Hands On Head reconnue !");
};
Body body = null;
while (true)
{
body = CurrentKinectStream.Bodies.FirstOrDefault();
if (body != null)
{
handUpPosture.TestGesture(body);
handsOnHeadPosture.TestGesture(body);
}
Thread.Sleep(50);
}
// KinectManager kinectManager = new KinectManager(); // KinectManager kinectManager = new KinectManager();
// if (kinectManager.StartSensor()) // if (kinectManager.StartSensor())
// { // {
@ -38,7 +67,7 @@ namespace ConsoleApp
// // Boucle pour tester les postures // // Boucle pour tester les postures
// while (true) // while (true)
// { // {
// Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps // Body body = kinecManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps
// if (body != null) // if (body != null)
// { // {
// handUpPosture.TestGesture(body); // handUpPosture.TestGesture(body);
@ -47,7 +76,8 @@ namespace ConsoleApp
// Thread.Sleep(50); // Une petite pause pour ne pas surcharger le CPU // Thread.Sleep(50); // Une petite pause pour ne pas surcharger le CPU
// } // }
} //}
}
} }
} }

@ -3,9 +3,9 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using MyGesturesBank; using KinectUtils;
namespace KinectUtils namespace MyGesturesBank
{ {
public class AllGesturesFactory : IGestureFactory public class AllGesturesFactory : IGestureFactory
{ {
@ -13,8 +13,8 @@ namespace KinectUtils
{ {
return new List<BaseGesture> return new List<BaseGesture>
{ {
new SwipeRightHand(), //new SwipeRightHand(),
new ClapHands() //new ClapHands()
// Ajoutez d'autres gestes ici // Ajoutez d'autres gestes ici
}; };
} }

@ -9,7 +9,7 @@ namespace KinectUtils
public event EventHandler GestureRecognized; public event EventHandler GestureRecognized;
// Nom du geste - marqué comme virtual pour permettre la substitution // Nom du geste - marqué comme virtual pour permettre la substitution
public string GestureName { get; protected set; } public virtual string GestureName { get; protected set; }
// Méthode abstraite pour tester le geste // Méthode abstraite pour tester le geste
public abstract void TestGesture(Body body); public abstract void TestGesture(Body body);

@ -7,36 +7,36 @@ using System.Threading.Tasks;
namespace KinectUtils namespace KinectUtils
{ {
abstract class Gesture : BaseGesture public abstract class Gesture : BaseGesture
{ {
public bool IsTesting { get; protected set; } public bool IsRecognitionRunning { get; set; }
protected int MinNbOfFrames = 10; // Exemple de valeur, ajustez selon le geste protected int MinNbOfFrames = 10; // Exemple de valeur, ajustez selon le geste
protected int MaxNbOfFrames = 50; // Exemple de valeur, ajustez selon le geste protected int MaxNbOfFrames = 50; // Exemple de valeur, ajustez selon le geste
private int mCurrentFrameCount = 0; private int currentFrameCount = 0;
// public bool isRecognitionRunning { get; set; }
public override void TestGesture(Body body) public override void TestGesture(Body body)
{ {
if (!IsTesting) if (!IsRecognitionRunning)
{ {
if (TestInitialConditions(body)) if (TestInitialConditions(body))
{ {
IsTesting = true; IsRecognitionRunning = true;
mCurrentFrameCount = 0; currentFrameCount = 0;
} }
} }
else else
{ {
mCurrentFrameCount++; currentFrameCount++;
if (!TestPosture(body) || !TestRunningGesture(body) || mCurrentFrameCount > MaxNbOfFrames) if (!TestPosture(body) || !TestRunningGesture(body) || currentFrameCount > MaxNbOfFrames)
{ {
IsTesting = false; IsRecognitionRunning = false;
} }
else if (TestEndConditions(body) && mCurrentFrameCount >= MinNbOfFrames) else if (TestEndConditions(body) && currentFrameCount >= MinNbOfFrames)
{ {
OnGestureRecognized(body); OnGestureRecognized(body);
IsTesting = false; IsRecognitionRunning = false;
} }
} }
} }
@ -47,3 +47,4 @@ namespace KinectUtils
abstract protected bool TestEndConditions(Body body); abstract protected bool TestEndConditions(Body body);
} }
} }

@ -1,16 +1,21 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.Remoting.Messaging;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using Lib; using Lib;
using Microsoft.Kinect;
namespace KinectUtils namespace KinectUtils
{ {
public static class GestureManager public static class GestureManager
{ {
public static event EventHandler<GestureRecognizedEventArgs> GestureRecognized; static private BodyFrameReader bodyFrameReader;
public static List<BaseGesture> KnownGestures = new List<BaseGesture>(); static private Body[] bodies;
static event EventHandler GestureRecognized;
static KinectManager KinectManager { get; set; }
static List<BaseGesture> KnownGestures { get; set; }
public static void AddGestures(IGestureFactory factory) public static void AddGestures(IGestureFactory factory)
{ {
@ -39,7 +44,29 @@ namespace KinectUtils
static public void StartAcquiringFrames(KinectManager kinectManager) static public void StartAcquiringFrames(KinectManager kinectManager)
{ {
throw new NotImplementedException(); bodyFrameReader = kinectManager.Sensor.BodyFrameSource.OpenReader();
bodyFrameReader.FrameArrived += Reader_BodyFrameArrived;
}
static private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
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)
{
gesture.TestGesture(body);
}
}
}
}
}
} }
} }
} }

@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace KinectUtils namespace KinectUtils
{ {
interface IGestureFactory public interface IGestureFactory
{ {
IEnumerable<BaseGesture> CreateGestures(); IEnumerable<BaseGesture> CreateGestures();
} }

@ -52,10 +52,6 @@
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\LibMyGesturesBank\MyGesturesBank.csproj">
<Project>{2496dfb1-eb55-47a1-a780-211e079b289d}</Project>
<Name>MyGesturesBank</Name>
</ProjectReference>
<ProjectReference Include="..\Lib\Lib.csproj"> <ProjectReference Include="..\Lib\Lib.csproj">
<Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project> <Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project>
<Name>Lib</Name> <Name>Lib</Name>

@ -16,7 +16,7 @@ namespace KinectUtils
if (TestPosture(body)) if (TestPosture(body))
{ {
// Posture is recognized // Posture is recognized
OnGestureRecognized(); OnGestureRecognized(body);
} }
} }

@ -153,20 +153,22 @@ namespace Lib
if (bodyframe != null) if (bodyframe != null)
{ {
bodyframe.GetAndRefreshBodyData(this.bodies); bodyframe.GetAndRefreshBodyData(this.bodies);
// nettoyer le Canvas avant de dessiner
Canvas.Children.Clear(); // nettoyer le Canvas avant de dessiner if (Canvas != null)
foreach (var body in this.bodies)
{ {
if (body.IsTracked) Canvas.Children.Clear();
foreach (var body in this.bodies)
{ {
// dessiner le squelette if (body.IsTracked)
drawskeleton(body); {
// dessiner le squelette
drawskeleton(body);
}
} }
} }
} }
} }
} }
} }
} }

@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using KinectUtils;
namespace MyGesturesBank
{
public class AllGesturesFactory : IGestureFactory
{
public IEnumerable<BaseGesture> CreateGestures()
{
return new List<BaseGesture>
{
new SwipeRightHand(),
//new ClapHands()
// Ajoutez d'autres gestes ici
};
}
}
}

@ -0,0 +1,44 @@
using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibMyGesturesBank
{
public class ClapHands : Gesture
{
protected override bool TestInitialConditions(Body body)
{
// Les conditions initiales ne sont pas strictes pour un clap, on commence donc directement avec TestPosture et TestRunningGesture
return true;
}
protected override bool TestPosture(Body body)
{
var handRight = body.Joints[JointType.HandRight].Position;
var handLeft = body.Joints[JointType.HandLeft].Position;
// Vérifie si les mains sont à une hauteur similaire et devant le corps
return Math.Abs(handRight.Y - handLeft.Y) < 0.1f && handRight.Z < 0.5f && handLeft.Z < 0.5f;
}
protected override bool TestRunningGesture(Body body)
{
var handRight = body.Joints[JointType.HandRight].Position;
var handLeft = body.Joints[JointType.HandLeft].Position;
// Vérifie si les mains se sont rencontrées au centre
return Math.Abs(handRight.X - handLeft.X) < 0.1f;
}
protected override bool TestEndConditions(Body body)
{
// Le clap est un geste instantané, donc si les conditions sont remplies une fois, le geste est considéré comme terminé
return true;
}
}
}

@ -44,6 +44,7 @@
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="ClapHands.cs" />
<Compile Include="PostureHandsOnHead .cs" /> <Compile Include="PostureHandsOnHead .cs" />
<Compile Include="PostureHandUp.cs" /> <Compile Include="PostureHandUp.cs" />
<Compile Include="Properties\AssemblyInfo.cs" /> <Compile Include="Properties\AssemblyInfo.cs" />
@ -52,6 +53,10 @@
<Compile Include="TwoHandsDragon.cs" /> <Compile Include="TwoHandsDragon.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj">
<Project>{2d44487e-f514-4063-9494-2af1e8c9e9c8}</Project>
<Name>KinectUtils</Name>
</ProjectReference>
<ProjectReference Include="..\Lib\Lib.csproj"> <ProjectReference Include="..\Lib\Lib.csproj">
<Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project> <Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project>
<Name>Lib</Name> <Name>Lib</Name>

@ -7,11 +7,13 @@ namespace MyGesturesBank
{ {
protected override bool TestPosture(Body body) protected override bool TestPosture(Body body)
{ {
// Exemple de condition : la main droite est plus haute que l'épaule droite var handRight = body.Joints[JointType.HandRight].Position;
return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.ShoulderRight].Position.Y; var handLeft = body.Joints[JointType.HandLeft].Position;
} var head = body.Joints[JointType.Head].Position;
public override string GestureName => "Hand Up"; return handRight.Y > head.Y || handLeft.Y > head.Y;
}
} }
} }

@ -8,26 +8,15 @@ namespace MyGesturesBank
{ {
protected override bool TestPosture(Body body) protected override bool TestPosture(Body body)
{ {
// Condition pour la main droite proche de la tête var handRight = body.Joints[JointType.HandRight].Position;
bool rightHandNearHead = IsHandNearHead(body.Joints[JointType.HandRight], body.Joints[JointType.Head]); var handLeft = body.Joints[JointType.HandLeft].Position;
var head = body.Joints[JointType.Head].Position;
// Condition pour la main gauche proche de la tête // Ajustez les seuils selon la précision souhaitée
bool leftHandNearHead = IsHandNearHead(body.Joints[JointType.HandLeft], body.Joints[JointType.Head]); var threshold = 0.1f; // Seuil pour ajuster la précision de la détection
return rightHandNearHead && leftHandNearHead; return Math.Abs(handRight.Y - head.Y) < threshold && Math.Abs(handLeft.Y - head.Y) < threshold;
} }
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";
} }

@ -1,4 +1,6 @@
using System; using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,7 +8,15 @@ using System.Threading.Tasks;
namespace MyGesturesBank namespace MyGesturesBank
{ {
internal class RightHandUp public class RightHandUp : Posture
{ {
protected override bool TestPosture(Body body)
{
var handRight = body.Joints[JointType.HandRight].Position;
var head = body.Joints[JointType.Head].Position;
return handRight.Y > head.Y;
}
} }
} }

@ -10,28 +10,50 @@ namespace MyGesturesBank
{ {
public class SwipeRightHand : Gesture public class SwipeRightHand : Gesture
{ {
private float previousX = float.NaN;
protected override bool TestInitialConditions(Body body) protected override bool TestInitialConditions(Body body)
{ {
// Implémentez la logique pour vérifier les conditions initiales du balayage à droite var handRight = body.Joints[JointType.HandRight].Position;
return false; var shoulderRight = body.Joints[JointType.ShoulderRight].Position;
// Conditions initiales : main droite au niveau ou à droite de l'épaule droite, mais pas trop éloignée
return handRight.X >= shoulderRight.X && handRight.X - shoulderRight.X < 0.5f;
} }
protected override bool TestPosture(Body body) protected override bool TestPosture(Body body)
{ {
// Implémentez la vérification de la posture pour le balayage à droite var handRight = body.Joints[JointType.HandRight].Position;
return false; var head = body.Joints[JointType.Head].Position;
// La main droite ne doit pas être plus haute que la tête
return handRight.Y <= head.Y;
} }
protected override bool TestRunningGesture(Body body) protected override bool TestRunningGesture(Body body)
{ {
// Implémentez la dynamique du geste de balayage à droite var handRight = body.Joints[JointType.HandRight].Position.X;
if (!float.IsNaN(previousX))
{
// Vérifie si la main droite se déplace vers la droite
bool isMovingRight = handRight > previousX;
previousX = handRight;
return isMovingRight;
}
previousX = handRight;
return false; return false;
} }
protected override bool TestEndConditions(Body body) protected override bool TestEndConditions(Body body)
{ {
// Vérifiez si les conditions de fin du geste de balayage à droite sont remplies var handRight = body.Joints[JointType.HandRight].Position;
return false; var spineBase = body.Joints[JointType.SpineBase].Position;
// Condition de fin : la main droite est bien à droite de la base de la colonne vertébrale
return handRight.X > spineBase.X + 0.5f; // Ajustez cette valeur selon le besoin
} }
} }

@ -1,4 +1,6 @@
using System; using KinectUtils;
using Microsoft.Kinect;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -6,7 +8,16 @@ using System.Threading.Tasks;
namespace MyGesturesBank namespace MyGesturesBank
{ {
internal class TwoHandsDragon public class TwoHandsDragon : Posture
{ {
protected override bool TestPosture(Body body)
{
var handRight = body.Joints[JointType.HandRight].Position;
var handLeft = body.Joints[JointType.HandLeft].Position;
var head = body.Joints[JointType.Head].Position;
return handRight.Y > head.Y && handLeft.Y > head.Y;
}
} }
} }

Loading…
Cancel
Save