|
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/Gestures |
|
14 * Classe : WaveDetector |
|
15 * |
|
16 * Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
17 * |
|
18 * Fonctionnalités : Permet de détecter si l'utilisateur a effectué un wave, 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.Gestures |
|
30 { |
|
31 public class WaveDetector : GestureDetector |
|
32 { |
|
33 public WaveDetector(DebugWindow _debug) : base(_debug) |
|
34 { |
|
35 //Temps de gesture maximum. |
|
36 gesturePeriod = (float)2; |
|
37 indexesPerSecond = 30; |
|
38 indexesToCheck = (int)(gesturePeriod * indexesPerSecond); |
|
39 } |
|
40 |
|
41 /* |
|
42 * Méthode de détection de wave |
|
43 */ |
|
44 public bool CheckForWave() |
|
45 { |
|
46 //Crée un historique de squelette local, puisque l'historique est mis à jour toutes les ~1/30 s. |
|
47 List<List<Joint>> localHistory = new List<List<Joint>>(history); |
|
48 |
|
49 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
|
50 if (localHistory.Count < indexesToCheck) |
|
51 return false; |
|
52 |
|
53 //La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
|
54 float refDistance = Math.Abs(localHistory[0][(int)JointType.Spine].Position.Y - localHistory[0][(int)JointType.ShoulderCenter].Position.Y); |
|
55 //On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
|
56 |
|
57 float startPosX = localHistory[localHistory.Count - indexesToCheck][(int)JointType.HandRight].Position.X; |
|
58 |
|
59 bool movedRight = false; |
|
60 |
|
61 //De la position p1 à pn, on suit l'algorithme. |
|
62 for (int i = localHistory.Count - indexesToCheck + 1; i < localHistory.Count; i++) |
|
63 { |
|
64 /*if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.ElbowRight].Position.Y + refDistance) |
|
65 debug.onR0(true); |
|
66 else |
|
67 debug.onR0(false); |
|
68 if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.HipCenter].Position.Y) |
|
69 debug.onR1(true); |
|
70 else |
|
71 debug.onR1(false); |
|
72 if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.WristRight].Position.Y + refDistance / 4) |
|
73 debug.onR2(true); |
|
74 else |
|
75 debug.onR2(false);*/ |
|
76 //Si la position Y de la main droite est plus haute que le coude + la distance de référence |
|
77 //OU si la position Y de la main droite est plus basse que la hanche |
|
78 //OU si la position Y de la main droite est plus haute que le poignet + le quart de la distance de référence. |
|
79 //Alors la main en question ne fait pas de Wave. |
|
80 if (localHistory[i][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.ElbowRight].Position.Y + refDistance || |
|
81 localHistory[i][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.HipCenter].Position.Y || |
|
82 localHistory[i][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.WristRight].Position.Y + refDistance / 4) |
|
83 return false; |
|
84 |
|
85 //On vérifie si la main à bougé vers la droite. |
|
86 |
|
87 if (localHistory[i][(int)JointType.HandRight].Position.X >= startPosX + refDistance / 2 && !movedRight) |
|
88 movedRight = true; |
|
89 |
|
90 //Si la main a bougé vers la droite, on regarde si elle est retournée à sa position initiale. |
|
91 if (movedRight && localHistory[i][(int)JointType.HandRight].Position.X <= startPosX) |
|
92 { |
|
93 history.Clear(); |
|
94 return true; |
|
95 } |
|
96 } |
|
97 return false; |
|
98 } |
|
99 } |
|
100 } |