diff --git a/Sources/ConsoleApp/App.config b/Sources/ConsoleApp/App.config new file mode 100644 index 0000000..56efbc7 --- /dev/null +++ b/Sources/ConsoleApp/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Sources/ConsoleApp/ConsoleApp.csproj b/Sources/ConsoleApp/ConsoleApp.csproj new file mode 100644 index 0000000..11b775b --- /dev/null +++ b/Sources/ConsoleApp/ConsoleApp.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {27D9C879-52BB-4BD7-B08D-63A534AC6D7E} + Exe + ConsoleApp + ConsoleApp + v4.7.2 + 512 + true + true + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll + + + + + + + + + + + + + + + + + + + + + {0751c83e-7845-4e5f-a5d3-e11aba393aca} + Lib + + + + \ No newline at end of file diff --git a/Sources/ConsoleApp/Program.cs b/Sources/ConsoleApp/Program.cs new file mode 100644 index 0000000..fb7ff8d --- /dev/null +++ b/Sources/ConsoleApp/Program.cs @@ -0,0 +1,53 @@ +using Lib; +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 + // } + } + + } +} diff --git a/Sources/ConsoleApp/Properties/AssemblyInfo.cs b/Sources/ConsoleApp/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..d40f227 --- /dev/null +++ b/Sources/ConsoleApp/Properties/AssemblyInfo.cs @@ -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")] diff --git a/Sources/ConsoleApp/packages.config b/Sources/ConsoleApp/packages.config new file mode 100644 index 0000000..f7f19c3 --- /dev/null +++ b/Sources/ConsoleApp/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Sources/KinectSolution.sln b/Sources/KinectSolution.sln index d187b5e..84d68a1 100644 --- a/Sources/KinectSolution.sln +++ b/Sources/KinectSolution.sln @@ -7,6 +7,12 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WpfApp", "WpfApp\WpfApp.csp EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Lib", "Lib\Lib.csproj", "{0751C83E-7845-4E5F-A5D3-E11ABA393ACA}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MyGesturesBank", "LibMyGesturesBank\MyGesturesBank.csproj", "{2496DFB1-EB55-47A1-A780-211E079B289D}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ConsoleApp", "ConsoleApp\ConsoleApp.csproj", "{27D9C879-52BB-4BD7-B08D-63A534AC6D7E}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KinectUtils", "KinectUtils\KinectUtils.csproj", "{2D44487E-F514-4063-9494-2AF1E8C9E9C8}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -21,6 +27,18 @@ Global {0751C83E-7845-4E5F-A5D3-E11ABA393ACA}.Debug|Any CPU.Build.0 = Debug|Any CPU {0751C83E-7845-4E5F-A5D3-E11ABA393ACA}.Release|Any CPU.ActiveCfg = Release|Any CPU {0751C83E-7845-4E5F-A5D3-E11ABA393ACA}.Release|Any CPU.Build.0 = Release|Any CPU + {2496DFB1-EB55-47A1-A780-211E079B289D}.Debug|Any CPU.ActiveCfg = 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.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 + {2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D44487E-F514-4063-9494-2AF1E8C9E9C8}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/Sources/KinectUtils/AllGesturesFactory.cs b/Sources/KinectUtils/AllGesturesFactory.cs new file mode 100644 index 0000000..970478a --- /dev/null +++ b/Sources/KinectUtils/AllGesturesFactory.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KinectUtils +{ + public class AllGesturesFactory : IGestureFactory + { + public IEnumerable CreateGestures() + { + throw new NotImplementedException(); + } + } +} diff --git a/Sources/KinectUtils/BaseGesture.cs b/Sources/KinectUtils/BaseGesture.cs new file mode 100644 index 0000000..c414db6 --- /dev/null +++ b/Sources/KinectUtils/BaseGesture.cs @@ -0,0 +1,36 @@ +using System; +using Microsoft.Kinect; + +namespace KinectUtils +{ + public abstract class BaseGesture + { + // Événement déclenché lorsque le geste est reconnu + public event EventHandler GestureRecognized; + + // Nom du geste - marqué comme virtual pour permettre la substitution + public string GestureName { get; protected set; } + + // Méthode abstraite pour tester le geste + public abstract void TestGesture(Body body); + + // Méthode protégée pour déclencher l'événement GestureRecognized + protected virtual void OnGestureRecognized(Body body) + { + GestureRecognized?.Invoke(this, new GestureRecognizedEventArgs(body, GestureName)); + } + } + + public class GestureRecognizedEventArgs : EventArgs + { + public Body Body { get; private set; } + public string GestureName { get; private set; } + + public GestureRecognizedEventArgs(Body body, string gestureName) + { + Body = body; + GestureName = gestureName; + } + } + +} diff --git a/Sources/KinectUtils/BaseMapping.cs b/Sources/KinectUtils/BaseMapping.cs new file mode 100644 index 0000000..8d16076 --- /dev/null +++ b/Sources/KinectUtils/BaseMapping.cs @@ -0,0 +1,33 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KinectUtils +{ + class BaseMapping + { + public void SubscribeToStartGesture(BaseGesture gesture) + { + throw new NotImplementedException(); + } + public void SubscribeToEndGesture(BaseGesture gesture) + { + throw new NotImplementedException(); + } + public void SubscribeToToggleGesture(BaseGesture gesture) + { + throw new NotImplementedException(); + } + protected T Mapping(Body body) + { + throw new NotImplementedException(); + } + public bool TestMapping(Body body, out T output) + { + throw new NotImplementedException(); + } + } +} diff --git a/Sources/KinectUtils/Gesture.cs b/Sources/KinectUtils/Gesture.cs new file mode 100644 index 0000000..1315626 --- /dev/null +++ b/Sources/KinectUtils/Gesture.cs @@ -0,0 +1,49 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KinectUtils +{ + abstract class Gesture : BaseGesture + { + public bool IsTesting { get; protected set; } + protected int MinNbOfFrames = 10; // Exemple de valeur, ajustez selon le geste + protected int MaxNbOfFrames = 50; // Exemple de valeur, ajustez selon le geste + private int mCurrentFrameCount = 0; + // public bool isRecognitionRunning { get; set; } + + public override void TestGesture(Body body) + { + if (!IsTesting) + { + if (TestInitialConditions(body)) + { + IsTesting = true; + mCurrentFrameCount = 0; + } + } + else + { + mCurrentFrameCount++; + + if (!TestPosture(body) || !TestRunningGesture(body) || mCurrentFrameCount > MaxNbOfFrames) + { + IsTesting = false; + } + else if (TestEndConditions(body) && mCurrentFrameCount >= MinNbOfFrames) + { + OnGestureRecognized(body); + IsTesting = false; + } + } + } + + abstract protected bool TestInitialConditions(Body body); + abstract protected bool TestPosture(Body body); + abstract protected bool TestRunningGesture(Body body); + abstract protected bool TestEndConditions(Body body); + } +} diff --git a/Sources/KinectUtils/GestureManager.cs b/Sources/KinectUtils/GestureManager.cs new file mode 100644 index 0000000..d9e08a5 --- /dev/null +++ b/Sources/KinectUtils/GestureManager.cs @@ -0,0 +1,36 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Lib; + +namespace KinectUtils +{ + static class GestureManager + { + static event EventHandler GestureRecognized; + static KinectManager KinectManager { get; set; } + static List KnownGestures { get; set; } + + static public void AddGestures(IGestureFactory factory) + { + KnownGestures = (List)factory.CreateGestures(); + } + static public void AddGestures(params BaseGesture[] gestures) + { + foreach (var gesture in gestures) + { + KnownGestures.Add(gesture); + } + } + static public void RemoveGesture(BaseGesture gesture) + { + KnownGestures.Remove(gesture); + } + static public void StartAcquiringFrames(KinectManager kinectManager) + { + throw new NotImplementedException(); + } + } +} diff --git a/Sources/KinectUtils/IGestureFactory.cs b/Sources/KinectUtils/IGestureFactory.cs new file mode 100644 index 0000000..f78c453 --- /dev/null +++ b/Sources/KinectUtils/IGestureFactory.cs @@ -0,0 +1,13 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KinectUtils +{ + interface IGestureFactory + { + IEnumerable CreateGestures(); + } +} diff --git a/Sources/KinectUtils/KinectUtils.csproj b/Sources/KinectUtils/KinectUtils.csproj new file mode 100644 index 0000000..c64f282 --- /dev/null +++ b/Sources/KinectUtils/KinectUtils.csproj @@ -0,0 +1,61 @@ + + + + + Debug + AnyCPU + {2D44487E-F514-4063-9494-2AF1E8C9E9C8} + Library + Properties + KinectUtils + KinectUtils + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + + + + + + + + + + + + + + + + + + {0751c83e-7845-4e5f-a5d3-e11aba393aca} + Lib + + + + \ No newline at end of file diff --git a/Sources/KinectUtils/Posture.cs b/Sources/KinectUtils/Posture.cs new file mode 100644 index 0000000..a95b2c6 --- /dev/null +++ b/Sources/KinectUtils/Posture.cs @@ -0,0 +1,24 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace KinectUtils +{ + public abstract class Posture : BaseGesture + { + protected abstract bool TestPosture(Body body); + + public override void TestGesture(Body body) + { + if (TestPosture(body)) + { + // Posture is recognized + OnGestureRecognized(); + } + } + + } +} diff --git a/Sources/KinectUtils/Properties/AssemblyInfo.cs b/Sources/KinectUtils/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..08c12d2 --- /dev/null +++ b/Sources/KinectUtils/Properties/AssemblyInfo.cs @@ -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("KinectUtils")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("KinectUtils")] +[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("2d44487e-f514-4063-9494-2af1e8c9e9c8")] + +// 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")] diff --git a/Sources/Lib/BodyImageStream.cs b/Sources/Lib/BodyImageStream.cs new file mode 100644 index 0000000..8b7b9bc --- /dev/null +++ b/Sources/Lib/BodyImageStream.cs @@ -0,0 +1,172 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using System.Windows.Media; +using System.Windows; +using System.Windows.Shapes; +using Lib; +using System.Windows.Controls; + +namespace Lib +{ + public class BodyImageStream : KinectStream + { + private BodyFrameReader reader; + public BodyFrameReader Reader + { + get { return reader; } + set { reader = value; } + } + + private Body[] bodies; + public Body[] Bodies + { + get { return bodies; } + private set { bodies = value; } + } + public override void Stop() + { + if (Reader != null) + { + Reader.Dispose(); + Reader = null; + } + + } + + public BodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager) + { + var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); + Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); + reader = kinectmanager.Sensor.BodyFrameSource.OpenReader(); + reader.FrameArrived += Reader_BodyFrameArrived; + + // initialiser le tableau des corps + this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount]; + Canvas = skeletonCanvas; + } + + private void drawbone(Body body, JointType JointType0, JointType JointType1) + { + Joint joint0 = body.Joints[JointType0]; + Joint joint1 = body.Joints[JointType1]; + + // ne dessinez que si les deux joints sont suivis + if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked) + { + Line bone = new Line + { + Stroke = new SolidColorBrush(Colors.LightBlue), + StrokeThickness = 4, + X1 = MapJointToScreen(joint0).X, + Y1 = MapJointToScreen(joint0).Y, + X2 = MapJointToScreen(joint1).X, + Y2 = MapJointToScreen(joint1).Y + }; + + Canvas.Children.Add(bone); + } + } + + private Point MapJointToScreen(Joint joint) + { + ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position); + + // Gestion des coordonnées infinies + float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X; + float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y; + + return new Point(x, y); + } + + private void drawskeleton(Body body) + { + // tête et cou + drawbone(body, JointType.Head, JointType.Neck); + drawbone(body, JointType.Neck, JointType.SpineShoulder); + + // torse + drawbone(body, JointType.SpineShoulder, JointType.SpineMid); + drawbone(body, JointType.SpineMid, JointType.SpineBase); + drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight); + drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft); + drawbone(body, JointType.SpineBase, JointType.HipRight); + drawbone(body, JointType.SpineBase, JointType.HipLeft); + + // bras droit + drawbone(body, JointType.ShoulderRight, JointType.ElbowRight); + drawbone(body, JointType.ElbowRight, JointType.WristRight); + drawbone(body, JointType.WristRight, JointType.HandRight); + drawbone(body, JointType.HandRight, JointType.HandTipRight); + drawbone(body, JointType.WristRight, JointType.ThumbRight); + + // bras gauche + drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft); + drawbone(body, JointType.ElbowLeft, JointType.WristLeft); + drawbone(body, JointType.WristLeft, JointType.HandLeft); + drawbone(body, JointType.HandLeft, JointType.HandTipLeft); + drawbone(body, JointType.WristLeft, JointType.ThumbLeft); + + // jambe droite + drawbone(body, JointType.HipRight, JointType.KneeRight); + drawbone(body, JointType.KneeRight, JointType.AnkleRight); + drawbone(body, JointType.AnkleRight, JointType.FootRight); + + // jambe gauche + drawbone(body, JointType.HipLeft, JointType.KneeLeft); + drawbone(body, JointType.KneeLeft, JointType.AnkleLeft); + drawbone(body, JointType.AnkleLeft, JointType.FootLeft); + + // dessinez les joints + foreach (JointType JointType in body.Joints.Keys) + { + Joint joint = body.Joints[JointType]; + if (joint.TrackingState == TrackingState.Tracked) + { + DrawJoint(MapJointToScreen(joint)); + } + } + } + + private void DrawJoint(Point point) + { + Ellipse ellipse = new Ellipse + { + Width = 10, + Height = 10, + Fill = new SolidColorBrush(Colors.Red) + }; + + Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2); + Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2); + + Canvas.Children.Add(ellipse); + } + private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) + { + using (var bodyframe = e.FrameReference.AcquireFrame()) + { + if (bodyframe != null) + { + bodyframe.GetAndRefreshBodyData(this.bodies); + + Canvas.Children.Clear(); // nettoyer le Canvas avant de dessiner + + foreach (var body in this.bodies) + { + if (body.IsTracked) + { + // dessiner le squelette + drawskeleton(body); + } + } + } + } + } + } +} + diff --git a/Sources/Lib/ColorAndBodyImageStream.cs b/Sources/Lib/ColorAndBodyImageStream.cs new file mode 100644 index 0000000..f410334 --- /dev/null +++ b/Sources/Lib/ColorAndBodyImageStream.cs @@ -0,0 +1,213 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Media.Imaging; +using System.Windows.Media; +using System.Windows.Shapes; +using System.Windows; + +namespace Lib +{ + public class ColorAndBodyImageStream : KinectStream + { + private BodyFrameReader reader; + public BodyFrameReader Reader + { + get { return reader; } + private set { reader = value; } + } + + private ColorFrameReader _colorReader; + public ColorFrameReader ColorReader { + get { return _colorReader; } + private set { _colorReader = value; } + } + + private Body[] bodies; + public Body[] Bodies + { + get { return bodies; } + private set { bodies = value; } + } + public override void Stop() + { + if (Reader != null) + { + Reader.Dispose(); + Reader = null; + } + if(ColorReader != null) + { + ColorReader.Dispose(); + ColorReader = null; + } + + } + + public ColorAndBodyImageStream(KinectManager kinectmanager, Canvas skeletonCanvas) : base(kinectmanager) + { + var framedescription = kinectmanager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); + Bitmap = new WriteableBitmap(framedescription.Width, framedescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); + reader = kinectmanager.Sensor.BodyFrameSource.OpenReader(); + reader.FrameArrived += Reader_BodyFrameArrived; + ColorReader = KinectManager.Sensor.ColorFrameSource.OpenReader(); + ColorReader.FrameArrived += Reader_ColorFrameArrived; + // initialiser le tableau des corps + this.bodies = new Body[kinectmanager.Sensor.BodyFrameSource.BodyCount]; + Canvas = skeletonCanvas; + } + + private void drawbone(Body body, JointType JointType0, JointType JointType1) + { + Joint joint0 = body.Joints[JointType0]; + Joint joint1 = body.Joints[JointType1]; + + // ne dessinez que si les deux joints sont suivis + if (joint0.TrackingState == TrackingState.Tracked && joint1.TrackingState == TrackingState.Tracked) + { + Line bone = new Line + { + Stroke = new SolidColorBrush(Colors.LightBlue), + StrokeThickness = 4, + X1 = MapJointToScreen(joint0).X, + Y1 = MapJointToScreen(joint0).Y, + X2 = MapJointToScreen(joint1).X, + Y2 = MapJointToScreen(joint1).Y + }; + + Canvas.Children.Add(bone); + } + } + + private Point MapJointToScreen(Joint joint) + { + ColorSpacePoint colorPoint = this.KinectManager.Sensor.CoordinateMapper.MapCameraPointToColorSpace(joint.Position); + + // Gestion des coordonnées infinies + float x = float.IsInfinity(colorPoint.X) ? 0 : colorPoint.X; + float y = float.IsInfinity(colorPoint.Y) ? 0 : colorPoint.Y; + + return new Point(x, y); + } + + private void drawskeleton(Body body) + { + // tête et cou + drawbone(body, JointType.Head, JointType.Neck); + drawbone(body, JointType.Neck, JointType.SpineShoulder); + + // torse + drawbone(body, JointType.SpineShoulder, JointType.SpineMid); + drawbone(body, JointType.SpineMid, JointType.SpineBase); + drawbone(body, JointType.SpineShoulder, JointType.ShoulderRight); + drawbone(body, JointType.SpineShoulder, JointType.ShoulderLeft); + drawbone(body, JointType.SpineBase, JointType.HipRight); + drawbone(body, JointType.SpineBase, JointType.HipLeft); + + // bras droit + drawbone(body, JointType.ShoulderRight, JointType.ElbowRight); + drawbone(body, JointType.ElbowRight, JointType.WristRight); + drawbone(body, JointType.WristRight, JointType.HandRight); + drawbone(body, JointType.HandRight, JointType.HandTipRight); + drawbone(body, JointType.WristRight, JointType.ThumbRight); + + // bras gauche + drawbone(body, JointType.ShoulderLeft, JointType.ElbowLeft); + drawbone(body, JointType.ElbowLeft, JointType.WristLeft); + drawbone(body, JointType.WristLeft, JointType.HandLeft); + drawbone(body, JointType.HandLeft, JointType.HandTipLeft); + drawbone(body, JointType.WristLeft, JointType.ThumbLeft); + + // jambe droite + drawbone(body, JointType.HipRight, JointType.KneeRight); + drawbone(body, JointType.KneeRight, JointType.AnkleRight); + drawbone(body, JointType.AnkleRight, JointType.FootRight); + + // jambe gauche + drawbone(body, JointType.HipLeft, JointType.KneeLeft); + drawbone(body, JointType.KneeLeft, JointType.AnkleLeft); + drawbone(body, JointType.AnkleLeft, JointType.FootLeft); + + // dessinez les joints + foreach (JointType JointType in body.Joints.Keys) + { + Joint joint = body.Joints[JointType]; + if (joint.TrackingState == TrackingState.Tracked) + { + DrawJoint(MapJointToScreen(joint)); + } + } + } + + private void DrawJoint(Point point) + { + Ellipse ellipse = new Ellipse + { + Width = 10, + Height = 10, + Fill = new SolidColorBrush(Colors.Red) + }; + + Canvas.SetLeft(ellipse, point.X - ellipse.Width / 2); + Canvas.SetTop(ellipse, point.Y - ellipse.Height / 2); + + Canvas.Children.Add(ellipse); + } + private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) + { + using (var bodyframe = e.FrameReference.AcquireFrame()) + { + if (bodyframe != null) + { + bodyframe.GetAndRefreshBodyData(this.bodies); + + Canvas.Children.Clear(); // nettoyer le Canvas avant de dessiner + + foreach (var body in this.bodies) + { + if (body.IsTracked) + { + // dessiner le squelette + drawskeleton(body); + } + } + } + } + } + private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e) + { + using (ColorFrame colorFrame = e.FrameReference.AcquireFrame()) + { + if (colorFrame != null) + { + // ... Logique existante pour traiter la frame + //Debug.WriteLine("Traitement de la frame de couleur."); + FrameDescription colorFrameDescription = colorFrame.FrameDescription; + + using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) + { + this.Bitmap.Lock(); + + // Vérifier si la taille de l'image a changé + if ((colorFrameDescription.Width == this.Bitmap.PixelWidth) && (colorFrameDescription.Height == this.Bitmap.PixelHeight)) + { + colorFrame.CopyConvertedFrameDataToIntPtr( + this.Bitmap.BackBuffer, + (uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4), + ColorImageFormat.Bgra); + + this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)); + } + + this.Bitmap.Unlock(); + } + //Debug.WriteLine("Frame de couleur traitée."); + } + } + } + } +} diff --git a/Sources/Lib/ColorImageStream.cs b/Sources/Lib/ColorImageStream.cs new file mode 100644 index 0000000..2580220 --- /dev/null +++ b/Sources/Lib/ColorImageStream.cs @@ -0,0 +1,70 @@ +using Microsoft.Kinect; +using System.ComponentModel; +using System.Windows; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace Lib +{ + public class ColorImageStream : KinectStream + { + private ColorFrameReader reader; + public ColorFrameReader Reader { + get { + return reader; + } + set + { + reader = value; + } + } + public ColorImageStream(KinectManager kinectManager) : base(kinectManager) + { + var frameDescription = KinectManager.Sensor.ColorFrameSource.CreateFrameDescription(ColorImageFormat.Bgra); + this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Bgr32, null); + reader = KinectManager.Sensor.ColorFrameSource.OpenReader(); + reader.FrameArrived += Reader_ColorFrameArrived; + } + + public override void Stop() + { + if (reader != null) + { + reader.Dispose(); + reader = null; + } + } + + private void Reader_ColorFrameArrived(object sender, ColorFrameArrivedEventArgs e) + { + using (ColorFrame colorFrame = e.FrameReference.AcquireFrame()) + { + if (colorFrame != null) + { + // ... Logique existante pour traiter la frame + //Debug.WriteLine("Traitement de la frame de couleur."); + FrameDescription colorFrameDescription = colorFrame.FrameDescription; + + using (KinectBuffer colorBuffer = colorFrame.LockRawImageBuffer()) + { + this.Bitmap.Lock(); + + // Vérifier si la taille de l'image a changé + if ((colorFrameDescription.Width == this.Bitmap.PixelWidth) && (colorFrameDescription.Height == this.Bitmap.PixelHeight)) + { + colorFrame.CopyConvertedFrameDataToIntPtr( + this.Bitmap.BackBuffer, + (uint)(colorFrameDescription.Width * colorFrameDescription.Height * 4), + ColorImageFormat.Bgra); + + this.Bitmap.AddDirtyRect(new Int32Rect(0, 0, this.Bitmap.PixelWidth, this.Bitmap.PixelHeight)); + } + + this.Bitmap.Unlock(); + } + //Debug.WriteLine("Frame de couleur traitée."); + } + } + } + } +} diff --git a/Sources/Lib/DepthImageStream.cs b/Sources/Lib/DepthImageStream.cs new file mode 100644 index 0000000..1cdafd9 --- /dev/null +++ b/Sources/Lib/DepthImageStream.cs @@ -0,0 +1,90 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using System.Windows.Media; +using System.Windows; + +namespace Lib +{ + class DepthImageStream : KinectStream + { + private DepthFrameReader reader; + public DepthFrameReader Reader + { + get + { + return reader; + } + set + { + reader = value; + } + } + private byte[] depthPixels; + public byte[] DepthPixels { + get { + return depthPixels; + } + set + { + depthPixels = value; + } + } + public DepthImageStream(KinectManager kinectManager) : base(kinectManager) + { + var frameDescription = KinectManager.Sensor.DepthFrameSource.FrameDescription; + this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null); + reader = KinectManager.Sensor.DepthFrameSource.OpenReader(); + reader.FrameArrived += Reader_DepthFrameArrived; + DepthPixels = new byte[frameDescription.Width * frameDescription.Height]; + } + private void Reader_DepthFrameArrived(object sender, DepthFrameArrivedEventArgs e) + { + using (DepthFrame depthFrame = e.FrameReference.AcquireFrame()) + { + if (depthFrame != null) + { + FrameDescription depthFrameDescription = depthFrame.FrameDescription; + + // Créez un tableau pour stocker les données de profondeur + ushort[] depthData = new ushort[depthFrameDescription.LengthInPixels]; + depthFrame.CopyFrameDataToArray(depthData); + + // Traitez les données de profondeur + ProcessDepthFrameData(depthData, depthFrameDescription.LengthInPixels, depthFrame.DepthMinReliableDistance, depthFrame.DepthMaxReliableDistance); + + // Mettez à jour le bitmap de profondeur + this.Bitmap.WritePixels( + new Int32Rect(0, 0, depthFrameDescription.Width, depthFrameDescription.Height), + this.depthPixels, + depthFrameDescription.Width, + 0); + } + } + } + + public override void Stop() + { + if (reader != null) + { + reader.Dispose(); + reader = null; + } + } + + private void ProcessDepthFrameData(ushort[] depthData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth) + { + // Convertir les données de profondeur en niveaux de gris + for (int i = 0; i < depthFrameDataSize; ++i) + { + ushort depth = depthData[i]; + DepthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth % 256) : 0); + } + } + + } +} diff --git a/Sources/Lib/InfraredImageStream.cs b/Sources/Lib/InfraredImageStream.cs new file mode 100644 index 0000000..fd0fef8 --- /dev/null +++ b/Sources/Lib/InfraredImageStream.cs @@ -0,0 +1,92 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media.Imaging; +using System.Windows.Media; +using System.Windows; + +namespace Lib +{ + class InfraredImageStream : KinectStream + { + private InfraredFrameReader reader; + private byte[] infraredPixels; + public byte[] InfraredPixels + { + get + { + return infraredPixels; + } + private set + { + infraredPixels = value; + } + } + public InfraredFrameReader Reader + { + get + { + return reader; + } + private set + { + reader = value; + } + } + public InfraredImageStream(KinectManager kinectManager) : base(kinectManager) + { + var frameDescription = KinectManager.Sensor.InfraredFrameSource.FrameDescription; + this.Bitmap = new WriteableBitmap(frameDescription.Width, frameDescription.Height, 96.0, 96.0, PixelFormats.Gray8, null); + reader = KinectManager.Sensor.InfraredFrameSource.OpenReader(); + reader.FrameArrived += Reader_InfraredFrameArrived; + infraredPixels = new byte[frameDescription.Width * frameDescription.Height]; + } + + public override void Stop() + { + if (reader != null) + { + reader.Dispose(); + reader = null; + } + } + private void ProcessInfraredFrameData(ushort[] frameData, uint frameDataSize) + { + // Convertir les données infrarouges en niveaux de gris + for (int i = 0; i < frameDataSize; ++i) + { + // Convertir la valeur infrarouge en une intensité lumineuse + byte intensity = (byte)(frameData[i] >> 8); + InfraredPixels[i] = intensity; + } + } + + private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e) + { + using (InfraredFrame infraredFrame = e.FrameReference.AcquireFrame()) + { + if (infraredFrame != null) + { + FrameDescription infraredFrameDescription = infraredFrame.FrameDescription; + + // Créez un tableau pour stocker les données infrarouges + ushort[] infraredData = new ushort[infraredFrameDescription.LengthInPixels]; + infraredFrame.CopyFrameDataToArray(infraredData); + + // Traitez les données infrarouges + ProcessInfraredFrameData(infraredData, infraredFrameDescription.LengthInPixels); + + // Mettez à jour le bitmap infrarouge + this.Bitmap.WritePixels( + new Int32Rect(0, 0, infraredFrameDescription.Width, infraredFrameDescription.Height), + this.infraredPixels, + infraredFrameDescription.Width, + 0); + } + } + } + } +} diff --git a/Sources/Lib/KinectManager.cs b/Sources/Lib/KinectManager.cs new file mode 100644 index 0000000..dbe75da --- /dev/null +++ b/Sources/Lib/KinectManager.cs @@ -0,0 +1,113 @@ +using Microsoft.Kinect; +using System.ComponentModel; +using System.Diagnostics; +using System.Windows.Media; + +namespace Lib +{ + public class KinectManager : INotifyPropertyChanged + { + private KinectSensor sensor; + public KinectSensor Sensor { + get { + return sensor; + } + set + { + sensor = value; + OnPropertyChanged(nameof(Sensor)); + } + } + + private SolidColorBrush _kinectStatusColor = new SolidColorBrush(Colors.Red); // Couleur rouge par défaut, signifiant inactive + public SolidColorBrush KinectStatusColor + { + get { return _kinectStatusColor; } + set + { + _kinectStatusColor = value; + OnPropertyChanged(nameof(KinectStatusColor)); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + protected virtual void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public KinectManager() + { + sensor = KinectSensor.GetDefault(); + UpdateStatusProperties(); + // Abonnez-vous à l'événement IsAvailableChanged + if (sensor != null) + { + sensor.IsAvailableChanged += KinectSensor_IsAvailableChanged; + } + } + public void StartSensor() + { + if (sensor != null && !sensor.IsOpen) { + sensor.Open(); + } + else { + sensor = KinectSensor.GetDefault(); + sensor.Open(); + } + } + public void StopSensor() + { + if (sensor != null) + { + sensor.Close(); + sensor = null; + } + } + public bool Status + { + get { return Sensor != null && Sensor.IsAvailable; } + } + private string _statusText; + public string StatusText + { + get { return _statusText; } + set { + _statusText = value; + if(this.PropertyChanged != null) + { + this.PropertyChanged(this, new PropertyChangedEventArgs("StatusText")); + } + } + } + + private void KinectSensor_IsAvailableChanged(object sender, IsAvailableChangedEventArgs e) + { + UpdateStatusProperties(); + } + + private void UpdateStatusProperties() + { + if (Sensor == null) + { + StatusText = "Kinect n'est pas connecté"; + KinectStatusColor = new SolidColorBrush(Colors.Red); + } + else if (!Sensor.IsOpen) + { + StatusText = "Kinect n'est pas ouvert"; + KinectStatusColor = new SolidColorBrush(Colors.Yellow); + } + else if (Sensor.IsAvailable) + { + StatusText = "Kinect est disponible"; + KinectStatusColor = new SolidColorBrush(Colors.Green); + } + else + { + StatusText = "Kinect n'est pas disponible"; + KinectStatusColor = new SolidColorBrush(Colors.Orange); + } + } + } +} \ No newline at end of file diff --git a/Sources/Lib/KinectStream.cs b/Sources/Lib/KinectStream.cs new file mode 100644 index 0000000..0be4e5a --- /dev/null +++ b/Sources/Lib/KinectStream.cs @@ -0,0 +1,65 @@ +using Microsoft.Kinect; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; +using System.Windows.Media; +using System.Windows.Media.Imaging; + +namespace Lib +{ + public abstract class KinectStream : INotifyPropertyChanged + { + public KinectManager KinectManager { get; private set; } + private WriteableBitmap bitmap; + public WriteableBitmap Bitmap + { + get { return bitmap; } + protected set + { + if (bitmap != value) + { + bitmap = value; + OnPropertyChanged(nameof(Bitmap)); + } + } + } + private Canvas _canvas; + public Canvas Canvas + { + get { return _canvas; } + protected set + { + _canvas = value; + OnPropertyChanged(nameof(Canvas)); + } + } + + public event PropertyChangedEventHandler PropertyChanged; + public void OnPropertyChanged(string propertyName) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } + + public KinectStream(KinectManager kinectManager) + { + KinectManager = kinectManager; + Canvas = null; + if (kinectManager.Sensor == null) + { + KinectManager.StartSensor(); + } + } + + public virtual void Start() + { + KinectManager.StartSensor(); + } + + public abstract void Stop(); + + } +} diff --git a/Sources/Lib/KinectStreams.cs b/Sources/Lib/KinectStreams.cs new file mode 100644 index 0000000..7909557 --- /dev/null +++ b/Sources/Lib/KinectStreams.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Lib +{ + public enum KinectStreams + { + None, + Color, + Depth, + IR, + Body, + ColorAndBody + } +} diff --git a/Sources/Lib/KinectStreamsFactory.cs b/Sources/Lib/KinectStreamsFactory.cs new file mode 100644 index 0000000..1571530 --- /dev/null +++ b/Sources/Lib/KinectStreamsFactory.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls; + +namespace Lib +{ + public class KinectStreamsFactory + { + private KinectManager _kinectManager; + public KinectManager KinectManager { + get { return _kinectManager; } + private set { _kinectManager = value; } + } + + private Dictionary> _streamFactory; + public Dictionary> StreamFactory + { + get { return _streamFactory; } + private set { _streamFactory = value; } + } + + public KinectStreamsFactory(KinectManager kinect,Canvas SkeletonCanvas) + { + _kinectManager = kinect; + // Initialisation de la fabrique avec les fonctions de création pour chaque type de flux. + StreamFactory = new Dictionary> + { + { KinectStreams.Color, () => new ColorImageStream(KinectManager) }, + { KinectStreams.Depth, () => new DepthImageStream(KinectManager) }, + { KinectStreams.IR, () => new InfraredImageStream(KinectManager) }, + { KinectStreams.Body, () => new BodyImageStream(KinectManager,SkeletonCanvas) }, + { KinectStreams.ColorAndBody, () => new ColorAndBodyImageStream(KinectManager,SkeletonCanvas) } + }; + } + + public KinectStream this[KinectStreams stream] + { + get + { + if (StreamFactory.ContainsKey(stream)) + { + return StreamFactory[stream](); + } + else + { + throw new ArgumentException("Invalid stream type."); + } + } + } + } +} \ No newline at end of file diff --git a/Sources/Lib/Lib.csproj b/Sources/Lib/Lib.csproj index 12682ba..1898143 100644 --- a/Sources/Lib/Lib.csproj +++ b/Sources/Lib/Lib.csproj @@ -1,10 +1,10 @@ - + Debug AnyCPU - 0751c83e-7845-4e5f-a5d3-e11aba393aca + {0751C83E-7845-4E5F-A5D3-E11ABA393ACA} Library Properties Lib @@ -31,24 +31,35 @@ 4 - - - - - - - - - - - - - - + + ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll + + + + + + + + + + + + - + + + + + + + + + + + + - + \ No newline at end of file diff --git a/Sources/Lib/packages.config b/Sources/Lib/packages.config new file mode 100644 index 0000000..f7f19c3 --- /dev/null +++ b/Sources/Lib/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Sources/LibMyGesturesBank/MyGesturesBank.csproj b/Sources/LibMyGesturesBank/MyGesturesBank.csproj new file mode 100644 index 0000000..7a43ab1 --- /dev/null +++ b/Sources/LibMyGesturesBank/MyGesturesBank.csproj @@ -0,0 +1,67 @@ + + + + + Debug + AnyCPU + {2496DFB1-EB55-47A1-A780-211E079B289D} + Library + Properties + LibMyGesturesBank + MyGesturesBank + v4.7.2 + 512 + true + + + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + ..\packages\Microsoft.Kinect.2.0.1410.19000\lib\net45\Microsoft.Kinect.dll + + + + + + + + + + + + + + + + + + + + {2d44487e-f514-4063-9494-2af1e8c9e9c8} + KinectUtils + + + {0751c83e-7845-4e5f-a5d3-e11aba393aca} + Lib + + + + + + + \ No newline at end of file diff --git a/Sources/LibMyGesturesBank/PostureHandUp.cs b/Sources/LibMyGesturesBank/PostureHandUp.cs new file mode 100644 index 0000000..54b1a6e --- /dev/null +++ b/Sources/LibMyGesturesBank/PostureHandUp.cs @@ -0,0 +1,17 @@ +using Microsoft.Kinect; +using KinectUtils; + +namespace MyGesturesBank +{ + public class PostureHandUp : Posture + { + protected override bool TestPosture(Body body) + { + // Exemple de condition : la main droite est plus haute que l'épaule droite + return body.Joints[JointType.HandRight].Position.Y > body.Joints[JointType.ShoulderRight].Position.Y; + } + + public override string GestureName => "Hand Up"; + } + +} diff --git a/Sources/LibMyGesturesBank/PostureHandsOnHead .cs b/Sources/LibMyGesturesBank/PostureHandsOnHead .cs new file mode 100644 index 0000000..7ad19b9 --- /dev/null +++ b/Sources/LibMyGesturesBank/PostureHandsOnHead .cs @@ -0,0 +1,34 @@ +using Microsoft.Kinect; +using System; +using KinectUtils; + +namespace MyGesturesBank +{ + public class PostureHandsOnHead : Posture + { + protected override bool TestPosture(Body body) + { + // Condition pour la main droite proche de la tête + bool rightHandNearHead = IsHandNearHead(body.Joints[JointType.HandRight], body.Joints[JointType.Head]); + + // Condition pour la main gauche proche de la tête + bool leftHandNearHead = IsHandNearHead(body.Joints[JointType.HandLeft], body.Joints[JointType.Head]); + + return rightHandNearHead && leftHandNearHead; + } + + 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"; + + } + + +} diff --git a/Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs b/Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..ab22671 --- /dev/null +++ b/Sources/LibMyGesturesBank/Properties/AssemblyInfo.cs @@ -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("MyGesturesBank")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("MyGesturesBank")] +[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("2496dfb1-eb55-47a1-a780-211e079b289d")] + +// 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")] diff --git a/Sources/Lib/Class1.cs b/Sources/LibMyGesturesBank/RightHandUp.cs similarity index 69% rename from Sources/Lib/Class1.cs rename to Sources/LibMyGesturesBank/RightHandUp.cs index dfbc46b..259d3a5 100644 --- a/Sources/Lib/Class1.cs +++ b/Sources/LibMyGesturesBank/RightHandUp.cs @@ -4,9 +4,9 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace Lib +namespace LibMyGesturesBank { - public class Class1 + internal class RightHandUp { } } diff --git a/Sources/LibMyGesturesBank/TwoHandsDragon.cs b/Sources/LibMyGesturesBank/TwoHandsDragon.cs new file mode 100644 index 0000000..a5e9d5f --- /dev/null +++ b/Sources/LibMyGesturesBank/TwoHandsDragon.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace LibMyGesturesBank +{ + internal class TwoHandsDragon + { + } +} diff --git a/Sources/LibMyGesturesBank/packages.config b/Sources/LibMyGesturesBank/packages.config new file mode 100644 index 0000000..f7f19c3 --- /dev/null +++ b/Sources/LibMyGesturesBank/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Sources/WpfApp/Bone.cs b/Sources/WpfApp/Bone.cs new file mode 100644 index 0000000..4b9bf97 --- /dev/null +++ b/Sources/WpfApp/Bone.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Media; + +namespace WpfApp +{ + public class Bone : INotifyPropertyChanged + { + public event PropertyChangedEventHandler PropertyChanged; + private void OnPropertyChanged(string propName) + { + if(PropertyChanged != null) + { + PropertyChanged(this, new PropertyChangedEventArgs(propName)); + } + } + + private double _top; + public double Top + { + get { return _top; } + set { + _top = value; + OnPropertyChanged(nameof(Top)); + } + } + public double Left + { + get; + set; + } + + public double Diameter + { + get + { + return _diameter; + } + set + { + _diameter = value; + OnPropertyChanged(nameof(Diameter)); + } + } + private double _diameter; + public SolidColorBrush ColorBrush { + get; + set; + } + } +} diff --git a/Sources/WpfApp/Bones.cs b/Sources/WpfApp/Bones.cs new file mode 100644 index 0000000..e56fc98 --- /dev/null +++ b/Sources/WpfApp/Bones.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace WpfApp +{ + class Bones : Collection + { + public Bones() { + Add(new Bone { }); + } + + } +} diff --git a/Sources/WpfApp/MainWindow.xaml b/Sources/WpfApp/MainWindow.xaml index 5e4a5e2..4e345b9 100644 --- a/Sources/WpfApp/MainWindow.xaml +++ b/Sources/WpfApp/MainWindow.xaml @@ -14,20 +14,23 @@ - - + + -