Add(Gesture): Reconnaissance des gestes goods

pull/14/head
Louis DUFOUR 1 year ago
parent 50a988422c
commit da98a6ebb7

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>

@ -0,0 +1,67 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApp</RootNamespace>
<AssemblyName>ConsoleApp</AssemblyName>
<TargetFrameworkVersion>v4.7.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<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>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\LibMyGesturesBank\LibMyGesturesBank.csproj">
<Project>{2496dfb1-eb55-47a1-a780-211e079b289d}</Project>
<Name>LibMyGesturesBank</Name>
</ProjectReference>
<ProjectReference Include="..\Lib\Lib.csproj">
<Project>{0751c83e-7845-4e5f-a5d3-e11aba393aca}</Project>
<Name>Lib</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

@ -0,0 +1,54 @@
using Lib;
using LibMyGesturesBank;
using Microsoft.Kinect;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApp
{
internal class Program
{
static void Main(string[] args)
{
KinectManager kinectManager = new KinectManager();
if (!kinectManager.StartSensor())
{
Console.WriteLine("Kinect n'est pas connecté ou non reconnu.");
return;
}
// Créez les instances de vos postures
PostureHandUp handUpPosture = new PostureHandUp();
PostureHandsOnHead handsOnHeadPosture = new PostureHandsOnHead();
// Abonnez-vous aux événements de reconnaissance de posture
handUpPosture.GestureRecognized += (sender, e) =>
{
Console.WriteLine("Posture Hand Up reconnue !");
};
handsOnHeadPosture.GestureRecognized += (sender, e) =>
{
Console.WriteLine("Posture Hands On Head reconnue !");
};
// Boucle pour tester les postures
while (true)
{
Body body = kinectManager.GetNextBody(); // Méthode fictive pour obtenir les données du corps
if (body != null)
{
handUpPosture.TestGesture(body);
handsOnHeadPosture.TestGesture(body);
}
Thread.Sleep(50); // Une petite pause pour ne pas surcharger le CPU
}
}
}
}

@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[assembly: AssemblyTitle("ConsoleApp")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ConsoleApp")]
[assembly: AssemblyCopyright("Copyright © 2024")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[assembly: ComVisible(false)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[assembly: Guid("27d9c879-52bb-4bd7-b08d-63a534ac6d7e")]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Microsoft.Kinect" version="2.0.1410.19000" targetFramework="net472" />
</packages>

@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib", "Lib\Lib.csproj", "{0
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMyGesturesBank", "LibMyGesturesBank\LibMyGesturesBank.csproj", "{2496DFB1-EB55-47A1-A780-211E079B289D}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LibMyGesturesBank", "LibMyGesturesBank\LibMyGesturesBank.csproj", "{2496DFB1-EB55-47A1-A780-211E079B289D}"
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU Debug|Any CPU = Debug|Any CPU
@ -27,6 +29,10 @@ Global
{2496DFB1-EB55-47A1-A780-211E079B289D}.Debug|Any CPU.Build.0 = Debug|Any CPU {2496DFB1-EB55-47A1-A780-211E079B289D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2496DFB1-EB55-47A1-A780-211E079B289D}.Release|Any CPU.ActiveCfg = Release|Any CPU {2496DFB1-EB55-47A1-A780-211E079B289D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2496DFB1-EB55-47A1-A780-211E079B289D}.Release|Any CPU.Build.0 = Release|Any CPU {2496DFB1-EB55-47A1-A780-211E079B289D}.Release|Any CPU.Build.0 = Release|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

@ -7,6 +7,10 @@ namespace Lib
public class KinectManager : INotifyPropertyChanged public class KinectManager : INotifyPropertyChanged
{ {
private KinectSensor sensor; private KinectSensor sensor;
private BodyFrameReader bodyFrameReader;
private Body[] bodies = null;
public KinectSensor Sensor { public KinectSensor Sensor {
get { get {
return sensor; return sensor;
@ -27,18 +31,65 @@ namespace Lib
public KinectManager() public KinectManager()
{ {
sensor = KinectSensor.GetDefault(); sensor = KinectSensor.GetDefault();
if (sensor != null)
{
bodyFrameReader = sensor.BodyFrameSource.OpenReader();
bodyFrameReader.FrameArrived += BodyFrameReader_FrameArrived;
}
}
private void BodyFrameReader_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
{
using (var frame = e.FrameReference.AcquireFrame())
{
if (frame != null)
{
if (bodies == null)
{
bodies = new Body[frame.BodyCount];
}
frame.GetAndRefreshBodyData(bodies);
}
}
} }
public void StartSensor()
public Body GetNextBody()
{
if (bodies == null) return null;
foreach (var body in bodies)
{
if (body.IsTracked)
{
return body;
}
}
return null;
}
public bool StartSensor()
{ {
if (sensor != null) { if (sensor != null) {
sensor.Open(); sensor.Open();
return true;
}
else
{
return false;
} }
} }
public void StopSensor() public bool StopSensor()
{ {
if (sensor != null) if (sensor != null)
{ {
sensor.Close(); sensor.Close();
return true;
}
else
{
return false;
} }
} }
public bool Status public bool Status

Loading…
Cancel
Save