|
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_MIDDLEWARE |
|
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 : KneeUpDetector |
|
15 * |
|
16 * Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
17 * |
|
18 * Fonctionnalités : Permet de détecter si l'utilisateur a levé le genou, en se basant sur |
|
19 * des règles appliquées à la positions des noeuds dans le temps. |
|
20 */ |
|
21 |
|
22 using System; |
|
23 using System.Collections.Generic; |
|
24 using System.Linq; |
|
25 using System.Text; |
|
26 using Microsoft.Kinect; |
|
27 using Trakers.Debug; |
|
28 |
|
29 namespace Trakers.Tracking.Postures |
|
30 { |
|
31 public class KneeUpDetector : PostureDetector |
|
32 { |
|
33 public KneeUpDetector(DebugWindow _debug) : base(_debug) |
|
34 { |
|
35 } |
|
36 |
|
37 /* |
|
38 * Méthode de détection du penché. |
|
39 */ |
|
40 public bool CheckForKneeUp() |
|
41 { |
|
42 //Crée un état local afin de pouvoir analyser s'il y a une posture. |
|
43 List<Joint> localState = new List<Joint>(currentState); |
|
44 |
|
45 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
|
46 float refDistance = Math.Abs(localState[(int)JointType.Spine].Position.Y - localState[(int)JointType.ShoulderCenter].Position.Y); |
|
47 |
|
48 /*if (Math.Abs(localState[(int)JointType.KneeLeft].Position.Y - localState[(int)JointType.KneeRight].Position.Y) > refDistance / 2) |
|
49 debug.onR0(true); |
|
50 else |
|
51 debug.onR0(false); |
|
52 if (Math.Abs(localState[(int)JointType.HipCenter].Position.Z - localState[(int)JointType.KneeLeft].Position.Z) > 0.20) |
|
53 debug.onR1(true); |
|
54 else |
|
55 debug.onR1(false); |
|
56 if (Math.Abs(localState[(int)JointType.HipCenter].Position.Z - localState[(int)JointType.KneeRight].Position.Z) > 0.20) |
|
57 debug.onR2(true); |
|
58 else |
|
59 debug.onR2(false);*/ |
|
60 |
|
61 //Si un genou n'est pas plus haut de la distance de référence/2 que l'autre |
|
62 //OU si le genou gauche n'est pas plus proche de 20cm par rapport à la hanche |
|
63 //OU si le genou droit n'est pas plus proche de 20cm par rapport à la hanche. |
|
64 //Alors on n'a pas levé de genou. |
|
65 if (Math.Abs(localState[(int)JointType.KneeLeft].Position.Y - localState[(int)JointType.KneeRight].Position.Y) < refDistance / 2 || |
|
66 Math.Abs(localState[(int)JointType.HipCenter].Position.Z - localState[(int)JointType.KneeLeft].Position.Z) < 0.20 && |
|
67 Math.Abs(localState[(int)JointType.HipCenter].Position.Z - localState[(int)JointType.KneeRight].Position.Z) < 0.20) |
|
68 return false; |
|
69 return true; |
|
70 } |
|
71 } |
|
72 } |