From d26575451e1d531af10b2819324f2706d8c731a4 Mon Sep 17 00:00:00 2001 From: Nico Date: Mon, 29 Jan 2024 13:04:48 +0100 Subject: [PATCH] :memo: plus d'explications --- KinectConnection/BodyImageStream.cs | 41 +++++++++------- KinectConnection/DepthImageStream.cs | 23 ++++----- KinectConnection/InfraredImageStream.cs | 64 ++++++++++++------------- 3 files changed, 66 insertions(+), 62 deletions(-) diff --git a/KinectConnection/BodyImageStream.cs b/KinectConnection/BodyImageStream.cs index 778c407..915abc8 100644 --- a/KinectConnection/BodyImageStream.cs +++ b/KinectConnection/BodyImageStream.cs @@ -101,11 +101,12 @@ namespace KinectConnection public BodyImageStream() : base() { this.coordinateMapper = this.KinectSensor.CoordinateMapper; + frameDescription = this.KinectSensor.DepthFrameSource.FrameDescription; displayHeight = frameDescription.Height; displayWidth = frameDescription.Width; - // Torso + // Torse this.bones.Add(new Tuple(JointType.Head, JointType.Neck)); this.bones.Add(new Tuple(JointType.Neck, JointType.SpineShoulder)); this.bones.Add(new Tuple(JointType.SpineShoulder, JointType.SpineMid)); @@ -115,30 +116,31 @@ namespace KinectConnection this.bones.Add(new Tuple(JointType.SpineBase, JointType.HipRight)); this.bones.Add(new Tuple(JointType.SpineBase, JointType.HipLeft)); - // Right Arm + // Bras droit this.bones.Add(new Tuple(JointType.ShoulderRight, JointType.ElbowRight)); this.bones.Add(new Tuple(JointType.ElbowRight, JointType.WristRight)); this.bones.Add(new Tuple(JointType.WristRight, JointType.HandRight)); this.bones.Add(new Tuple(JointType.HandRight, JointType.HandTipRight)); this.bones.Add(new Tuple(JointType.WristRight, JointType.ThumbRight)); - // Left Arm + // Bras gauche this.bones.Add(new Tuple(JointType.ShoulderLeft, JointType.ElbowLeft)); this.bones.Add(new Tuple(JointType.ElbowLeft, JointType.WristLeft)); this.bones.Add(new Tuple(JointType.WristLeft, JointType.HandLeft)); this.bones.Add(new Tuple(JointType.HandLeft, JointType.HandTipLeft)); this.bones.Add(new Tuple(JointType.WristLeft, JointType.ThumbLeft)); - // Right Leg + // Jambe droite this.bones.Add(new Tuple(JointType.HipRight, JointType.KneeRight)); this.bones.Add(new Tuple(JointType.KneeRight, JointType.AnkleRight)); this.bones.Add(new Tuple(JointType.AnkleRight, JointType.FootRight)); - // Left Leg + // Jambe gauche this.bones.Add(new Tuple(JointType.HipLeft, JointType.KneeLeft)); this.bones.Add(new Tuple(JointType.KneeLeft, JointType.AnkleLeft)); this.bones.Add(new Tuple(JointType.AnkleLeft, JointType.FootLeft)); + // Couleurs this.bodyColors.Add(new Pen(Brushes.Red, 6)); this.bodyColors.Add(new Pen(Brushes.Orange, 6)); this.bodyColors.Add(new Pen(Brushes.Green, 6)); @@ -188,6 +190,7 @@ namespace KinectConnection /// event arguments private void Reader_BodyFrameArrived(object sender, BodyFrameArrivedEventArgs e) { + // flag pour savoir si la donnée est reçu ou pas bool dataReceived = false; using (BodyFrame bodyFrame = e.FrameReference.AcquireFrame()) @@ -196,27 +199,32 @@ namespace KinectConnection { if (this.bodies == null) { + // ajouter des corps en fonction du bodyCount this.bodies = new Body[bodyFrame.BodyCount]; } - // The first time GetAndRefreshBodyData is called, Kinect will allocate each Body in the array. - // As long as those body objects are not disposed and not set to null in the array, - // those body objects will be re-used. + // Une fois que GetAndRefreshBodyData est appele le Kinect va allouer chaque body dans le tableau + // Tant que le body est toujours dans le cadre il ne sera pas supprimé donc les body deja alloues + // seront réutilisé bodyFrame.GetAndRefreshBodyData(this.bodies); + + // flag dataReceived = true; } } + // Si on reçoit de la donnée, alors dessiner le body if (dataReceived) { using (DrawingContext dc = this.drawingGroup.Open()) { - // Draw a transparent background to set the render size + // Fond transparent dc.DrawRectangle(Brushes.Black, null, new Rect(0.0, 0.0, displayWidth, displayHeight)); int penIndex = 0; foreach (Body body in this.bodies) { + // pour avoir des couleurs differentes pour chaque body Pen drawPen = this.bodyColors[penIndex++]; if (body.IsTracked) @@ -230,8 +238,8 @@ namespace KinectConnection foreach (JointType jointType in joints.Keys) { - // sometimes the depth(Z) of an inferred joint may show as negative - // clamp down to 0.1f to prevent coordinatemapper from returning (-Infinity, -Infinity) + // parfois la profondeur Z peut venir negatif + // avec 0.1 on evite les coordonées negatives du coordinateMapper CameraSpacePoint position = joints[jointType].Position; if (position.Z < 0) { @@ -242,14 +250,16 @@ namespace KinectConnection jointPoints[jointType] = new Point(depthSpacePoint.X, depthSpacePoint.Y); } + // dessiner les joints this.DrawBody(joints, jointPoints, dc, drawPen); + // dessiner les mains this.DrawHand(body.HandLeftState, jointPoints[JointType.HandLeft], dc); this.DrawHand(body.HandRightState, jointPoints[JointType.HandRight], dc); } } - // prevent drawing outside of our render area + // empeche de dessiner hors du cadre this.drawingGroup.ClipGeometry = new RectangleGeometry(new Rect(0.0, 0.0, displayWidth, displayHeight)); } } @@ -260,13 +270,13 @@ namespace KinectConnection /// private void DrawBody(IReadOnlyDictionary joints, IDictionary jointPoints, DrawingContext drawingContext, Pen drawingPen) { - // Draw the bones + // Dessiner les os (lignes entre les joints) foreach (var bone in this.bones) { this.DrawBone(joints, jointPoints, bone.Item1, bone.Item2, drawingContext, drawingPen); } - // Draw the joints + // Dessiner les joints foreach (JointType jointType in joints.Keys) { Brush drawBrush = null; @@ -318,14 +328,13 @@ namespace KinectConnection Joint joint0 = joints[jointType0]; Joint joint1 = joints[jointType1]; - // If we can't find either of these joints, exit + // Si ces joints n'existent pas, return (pas besoin de dessiner) if (joint0.TrackingState == TrackingState.NotTracked || joint1.TrackingState == TrackingState.NotTracked) { return; } - // We assume all drawn bones are inferred unless BOTH joints are tracked Pen drawPen = this.inferredBonePen; if ((joint0.TrackingState == TrackingState.Tracked) && (joint1.TrackingState == TrackingState.Tracked)) { diff --git a/KinectConnection/DepthImageStream.cs b/KinectConnection/DepthImageStream.cs index 6636133..c037677 100644 --- a/KinectConnection/DepthImageStream.cs +++ b/KinectConnection/DepthImageStream.cs @@ -21,27 +21,22 @@ namespace KinectConnection private const int MapDepthToByte = 8000 / 256; /// - /// Active Kinect sensor - /// - private KinectSensor kinectSensor = null; - - /// - /// Reader for depth frames + /// Reader pour les données /// private DepthFrameReader depthFrameReader = null; /// - /// Description of the data contained in the depth frame + /// Description du cadre (hauteur/largeur) /// private FrameDescription depthFrameDescription = null; /// - /// Bitmap to display + /// Le bitmap permettant d'afficher l'image /// private WriteableBitmap depthBitmap = null; /// - /// Intermediate storage for frame data converted to color + /// Stockage intermediare des données avant de convertir en couleurs /// private byte[] depthPixels = null; @@ -155,17 +150,17 @@ namespace KinectConnection /// La plus fiable valeur maximale pour la frame private unsafe void ProcessDepthFrameData(IntPtr depthFrameData, uint depthFrameDataSize, ushort minDepth, ushort maxDepth) { - // depth frame data is a 16 bit value + // la donnée du dephtFrame est une valeur de 16 bits ushort* frameData = (ushort*)depthFrameData; - // convert depth to a visual representation + // traduit la profondeur en une representation visuelle for (int i = 0; i < (int)(depthFrameDataSize / this.depthFrameDescription.BytesPerPixel); ++i) { - // Get the depth for this pixel + // obtenir la profondeur d'un pixel ushort depth = frameData[i]; - // To convert to a byte, we're mapping the depth value to the byte range. - // Values outside the reliable depth range are mapped to 0 (black). + // Pour convertir en bytes on doit traduire la profondeur en bytes + // Des valeurs qui n'est pas dans la portée valide on met 0 this.depthPixels[i] = (byte)(depth >= minDepth && depth <= maxDepth ? (depth / MapDepthToByte) : 0); } } diff --git a/KinectConnection/InfraredImageStream.cs b/KinectConnection/InfraredImageStream.cs index 3e457dc..3624efb 100644 --- a/KinectConnection/InfraredImageStream.cs +++ b/KinectConnection/InfraredImageStream.cs @@ -16,47 +16,47 @@ namespace KinectConnection public class InfraredImageStream : KinectStream { /// - /// Maximum value (as a float) that can be returned by the InfraredFrame + /// Valeur maximale (en tant que float) que peut renvoyer InfraredFrame. /// private const float InfraredSourceValueMaximum = (float)ushort.MaxValue; /// - /// The value by which the infrared source data will be scaled + /// La valeur par laquelle les données de la source infrarouge seront ajustées. /// private const float InfraredSourceScale = 0.75f; /// - /// Smallest value to display when the infrared data is normalized + /// Plus petite valeur à afficher lorsque les données infrarouges sont normalisées. /// private const float InfraredOutputValueMinimum = 0.01f; /// - /// Largest value to display when the infrared data is normalized + /// Plus grande valeur à afficher lorsque les données infrarouges sont normalisées. /// private const float InfraredOutputValueMaximum = 1.0f; /// - /// Active Kinect sensor + /// Capteur Kinect actif. /// private KinectSensor kinectSensor = null; /// - /// Reader for infrared frames + /// Lecteur pour les images infrarouges. /// private InfraredFrameReader infraredFrameReader = null; /// - /// Description (width, height, etc) of the infrared frame data + /// Description (largeur, hauteur, etc.) des données du cadre infrarouge. /// private FrameDescription infraredFrameDescription = null; /// - /// Bitmap to display + /// Bitmap à afficher. /// private WriteableBitmap infraredBitmap = null; /// - /// Current status text to display + /// Texte d'état actuel à afficher. /// private string statusText = null; @@ -76,10 +76,10 @@ namespace KinectConnection /// public InfraredImageStream() { - // get FrameDescription from InfraredFrameSource + // Obtient la description du cadre infrarouge à partir de InfraredFrameSource this.infraredFrameDescription = this.KinectSensor.InfraredFrameSource.FrameDescription; - // create the bitmap to display + // Crée la bitmap à afficher this.infraredBitmap = new WriteableBitmap(this.infraredFrameDescription.Width, this.infraredFrameDescription.Height, 96.0, 96.0, PixelFormats.Gray32Float, null); } @@ -90,12 +90,12 @@ namespace KinectConnection { if (this.KinectSensor != null) { - // open the reader for the depth frames + // Ouvre le lecteur pour les trames infrarouges this.infraredFrameReader = this.KinectSensor.InfraredFrameSource.OpenReader(); if (this.infraredFrameReader != null) { - // wire handler for frame arrival + // Lie le gestionnaire pour l'arrivée de la trame this.infraredFrameReader.FrameArrived += this.Reader_InfraredFrameArrived; } } @@ -110,30 +110,30 @@ namespace KinectConnection { this.infraredFrameReader.FrameArrived -= this.Reader_InfraredFrameArrived; - // Dispose the reader to free resources. - // If we don't dispose manualy, the gc will do it for us, but we don't know when. + // Libère le lecteur pour libérer des ressources. + // Si nous ne le faisons pas manuellement, le GC le fera pour nous, mais nous ne savons pas quand. this.infraredFrameReader.Dispose(); this.infraredFrameReader = null; } } /// - /// Méthode appelée lors de l'arrivée d'un nouveau frame infrarouge. + /// Méthode appelée lors de l'arrivée d'un nouveau cadre infrarouge. /// - /// object sending the event - /// event arguments + /// objet envoyant l'événement + /// arguments de l'événement private void Reader_InfraredFrameArrived(object sender, InfraredFrameArrivedEventArgs e) { - // InfraredFrame is IDisposable + // InfraredFrame est IDisposable using (InfraredFrame infraredFrame = e.FrameReference.AcquireFrame()) { if (infraredFrame != null) { - // the fastest way to process the infrared frame data is to directly access - // the underlying buffer + // La manière la plus rapide de traiter les données du cadre infrarouge est d'accéder directement + // au tampon sous-jacent using (Microsoft.Kinect.KinectBuffer infraredBuffer = infraredFrame.LockImageBuffer()) { - // verify data and write the new infrared frame data to the display bitmap + // Vérifie les données et écrit les nouvelles données du cadre infrarouge sur la bitmap d'affichage if (((this.infraredFrameDescription.Width * this.infraredFrameDescription.Height) == (infraredBuffer.Size / this.infraredFrameDescription.BytesPerPixel)) && (this.infraredFrameDescription.Width == this.infraredBitmap.PixelWidth) && (this.infraredFrameDescription.Height == this.infraredBitmap.PixelHeight)) { @@ -150,31 +150,31 @@ namespace KinectConnection /// Cette fonction nécessite l'option /unsafe du compilateur car nous utilisons un accès direct /// à la mémoire native pointée par le pointeur infraredFrameData. /// - /// Pointeur vers les données d'image InfraredFrame - /// Taille des données d'image InfraredFrame + /// Pointeur vers les données du cadre infrarouge + /// Taille des données du cadre infrarouge private unsafe void ProcessInfraredFrameData(IntPtr infraredFrameData, uint infraredFrameDataSize) { - // infrared frame data is a 16 bit value + // Les données du cadre infrarouge sont une valeur de 16 bits ushort* frameData = (ushort*)infraredFrameData; - // lock the target bitmap + // Verrouille la bitmap cible this.infraredBitmap.Lock(); - // get the pointer to the bitmap's back buffer + // Obtient le pointeur vers le tampon arrière de la bitmap float* backBuffer = (float*)this.infraredBitmap.BackBuffer; - // process the infrared data + // Traite les données infrarouges for (int i = 0; i < (int)(infraredFrameDataSize / this.infraredFrameDescription.BytesPerPixel); ++i) { - // since we are displaying the image as a normalized grey scale image, we need to convert from - // the ushort data (as provided by the InfraredFrame) to a value from [InfraredOutputValueMinimum, InfraredOutputValueMaximum] + // Comme nous affichons l'image en niveaux de gris normalisés, nous devons convertir de + // la donnée ushort (fournie par InfraredFrame) à une valeur de [InfraredOutputValueMinimum, InfraredOutputValueMaximum] backBuffer[i] = Math.Min(InfraredOutputValueMaximum, (((float)frameData[i] / InfraredSourceValueMaximum * InfraredSourceScale) * (1.0f - InfraredOutputValueMinimum)) + InfraredOutputValueMinimum); } - // mark the entire bitmap as needing to be drawn + // Marque toute la bitmap comme nécessitant un redessin this.infraredBitmap.AddDirtyRect(new Int32Rect(0, 0, this.infraredBitmap.PixelWidth, this.infraredBitmap.PixelHeight)); - // unlock the bitmap + // Déverrouille la bitmap this.infraredBitmap.Unlock(); } }