middleware/Tracking/Postures/CorrectPosture.cs
changeset 37 37ebedd84755
child 39 15b11d291417
equal deleted inserted replaced
36:25e71ada2a6d 37:37ebedd84755
       
     1 /*
       
     2 * This file is part of the TraKERS\Middleware package.
       
     3 *
       
     4 * (c) IRI <http://www.iri.centrepompidou.fr/>
       
     5 *
       
     6 * For the full copyright and license information, please view the LICENSE
       
     7 * file that was distributed with this source code.
       
     8 */
       
     9 
       
    10 /*
       
    11  * Projet : TraKERS
       
    12  * Module : MIDDLEWARE
       
    13  * Sous-Module : Tracking/Postures
       
    14  * Classe : BendDetector
       
    15  * 
       
    16  * Auteur : alexandre.bastien@iri.centrepompidou.fr
       
    17  * 
       
    18  * Fonctionnalités : Permet de détecter si l'utilisateur est bien tracké.
       
    19  */
       
    20 
       
    21 using System;
       
    22 using System.Collections.Generic;
       
    23 using System.Linq;
       
    24 using Microsoft.Kinect;
       
    25 using Trakers.Debug;
       
    26 
       
    27 namespace Trakers.Tracking.Postures
       
    28 {
       
    29     public class CorrectPosture : PostureDetector
       
    30     {
       
    31         public CorrectPosture(DebugWindow _debug)
       
    32             : base(_debug)
       
    33         {
       
    34         }
       
    35 
       
    36         /*
       
    37          * Méthode de détection du penché.
       
    38          */
       
    39         public bool CheckForCorrectPosture()
       
    40         {
       
    41             //Crée un état local afin de pouvoir analyser s'il y a une posture.
       
    42             List<Joint> localState = new List<Joint>(currentState);
       
    43 
       
    44             bool c1, c2, c3, c4, c5, c6, c7, c8, c9, c10, c11, c12, c13;
       
    45 
       
    46             //Si les genoux sont plus hauts que le centre
       
    47             //OU si les pieds sont plus hauts que le centre
       
    48             //OU si la tête est plus basse que les hanches
       
    49             //OU si les épaules sont plus basses que les genoux
       
    50             //OU si les épaules droites et gauches sont trop proches
       
    51             //OU si les genoux droites et gauches sont trop proches
       
    52             //OU si les pieds sont plus hauts que les genoux, les genoux étant plus bas que le bassin
       
    53             //OU si les genoux sont inversés par rapport aux épaules
       
    54             //Alors on ne s'est pas tracké.
       
    55             c1 = localState[(int)JointType.KneeLeft].Position.Y < localState[(int)JointType.Spine].Position.Y;
       
    56             c2 = localState[(int)JointType.KneeRight].Position.Y < localState[(int)JointType.Spine].Position.Y;
       
    57             c3 = localState[(int)JointType.FootLeft].Position.Y < localState[(int)JointType.Spine].Position.Y;
       
    58             c4 = localState[(int)JointType.FootRight].Position.Y < localState[(int)JointType.Spine].Position.Y;
       
    59             c5 = localState[(int)JointType.Head].Position.Y > localState[(int)JointType.HipCenter].Position.Y;
       
    60             c6 = localState[(int)JointType.ShoulderCenter].Position.Y > localState[(int)JointType.KneeLeft].Position.Y;
       
    61             c7 = localState[(int)JointType.ShoulderCenter].Position.Y > localState[(int)JointType.KneeRight].Position.Y;
       
    62             c8 = Math.Abs(localState[(int)JointType.ShoulderLeft].Position.X - localState[(int)JointType.ShoulderRight].Position.X) < 0.20;
       
    63             c9 = Math.Abs(localState[(int)JointType.KneeLeft].Position.X - localState[(int)JointType.KneeRight].Position.X) < 0.20;
       
    64             c10 = localState[(int)JointType.FootLeft].Position.Y < localState[(int)JointType.KneeLeft].Position.Y && localState[(int)JointType.KneeLeft].Position.Y > localState[(int)JointType.HipCenter].Position.Y;
       
    65             c11 = localState[(int)JointType.FootRight].Position.Y < localState[(int)JointType.KneeRight].Position.Y && localState[(int)JointType.KneeRight].Position.Y > localState[(int)JointType.HipCenter].Position.Y;
       
    66             c12 = localState[(int)JointType.ShoulderRight].Position.X < localState[(int)JointType.ShoulderLeft].Position.X && localState[(int)JointType.KneeRight].Position.X > localState[(int)JointType.KneeLeft].Position.X;
       
    67             c13 = localState[(int)JointType.ShoulderRight].Position.X > localState[(int)JointType.ShoulderLeft].Position.X && localState[(int)JointType.KneeRight].Position.X < localState[(int)JointType.KneeLeft].Position.X;
       
    68             if (c1 || c2 || c3 || c4 || c5 || c6 || c7 || c8 || c9 || c10 || c11 || c12 || c13)
       
    69             {
       
    70                 //debug.showCorrect(c1, c2, c3, c4, c5, c6, c7, c8, c9, c12, c13);
       
    71                 //Console.WriteLine("NOT DETECTED");
       
    72                 return false;
       
    73             }
       
    74             return true;
       
    75         }
       
    76     }
       
    77 }