middleware/Tracking/Postures/FallDetector.cs
author ymh <ymh.work@gmail.com>
Thu, 02 Aug 2012 09:26:15 +0200
changeset 66 20da47bd9408
parent 39 15b11d291417
permissions -rw-r--r--
correct sync config and script

/*
* This file is part of the TraKERS\Middleware package.
*
* (c) IRI <http://www.iri.centrepompidou.fr/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

/*
 * Projet : TraKERS
 * Module : MIDDLEWARE
 * Sous-Module : Tracking/Gestures
 * Classe : FallDetector
 * 
 * Auteur : alexandre.bastien@iri.centrepompidou.fr
 * 
 * Fonctionnalités : Permet de détecter si l'utilisateur est tombé, en se basant sur
 * des règles appliquées à la positions des noeuds dans le temps.
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Kinect;
using Trakers.Debug;

namespace Trakers.Tracking.Postures
{
    public class FallDetector : PostureDetector
    {
        static int n = 0;

        public FallDetector(DebugWindow _debug)
            : base(_debug)
        {
        }

        /*
         * Méthode de détection du fall.
         */
        public bool CheckForFall()
        {
            //Crée un état local afin de pouvoir analyser s'il y a une posture.
            List<Joint> localState = new List<Joint>(currentState);

            //Si les genoux ne sont pas éloignés d'au moins 20cm vers l'avant par rapport aux hanches
            //OU si les hanches et la tête ne sont pas au même niveau avec 20 cm d'erreur.
            //Alors on ne fait pas un fall.
            if (localState[(int)JointType.KneeLeft].Position.Z + 0.15 >= localState[(int)JointType.HipCenter].Position.Z ||
                localState[(int)JointType.KneeRight].Position.Z + 0.15 >= localState[(int)JointType.HipCenter].Position.Z ||
                Math.Abs(localState[(int)JointType.HipCenter].Position.Z - localState[(int)JointType.Head].Position.Z) > 0.20)
                return false;
            return true;
        }
    }
}