Add gestures to the test methods

pull/19/head
Johan LACHENAL 1 year ago
parent 5326981d8f
commit beff9b5954

@ -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
// } // }
} //}
}
} }
} }

@ -32,5 +32,9 @@ namespace KinectUtils
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }
static public void StopAcquiringFrames()
{
throw new NotImplementedException();
}
} }
} }

@ -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);
}
} }
} }
} }
} }
} }
} }
} }

@ -47,8 +47,6 @@
<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" />
<Compile Include="RightHandUp.cs" />
<Compile Include="TwoHandsDragon.cs" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ProjectReference Include="..\KinectUtils\KinectUtils.csproj"> <ProjectReference Include="..\KinectUtils\KinectUtils.csproj">

@ -20,10 +20,11 @@ namespace MyGesturesBank
private bool IsHandNearHead(Joint hand, Joint head) private bool IsHandNearHead(Joint hand, Joint head)
{ {
// Exemple de condition : la main est à moins de 30 cm de la tête // Exemple de condition : la main est à moins de 30 cm de la tête
return Math.Sqrt( double distance = Math.Sqrt(
Math.Pow(hand.Position.X - head.Position.X, 2) + Math.Pow(hand.Position.X - head.Position.X, 2) +
Math.Pow(hand.Position.Y - head.Position.Y, 2) + Math.Pow(hand.Position.Y - head.Position.Y, 2) +
Math.Pow(hand.Position.Z - head.Position.Z, 2)) < 0.3; Math.Pow(hand.Position.Z - head.Position.Z, 2));
return distance < 0.3 && distance > 0;
} }
public override string GestureName => "Hands On Head"; public override string GestureName => "Hands On Head";

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibMyGesturesBank
{
internal class RightHandUp
{
}
}

@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LibMyGesturesBank
{
internal class TwoHandsDragon
{
}
}
Loading…
Cancel
Save