|
15
|
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 : JumpDetector |
|
|
15 |
* |
|
|
16 |
* Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
|
17 |
* |
|
|
18 |
* Fonctionnalités : Permet de détecter si l'utilisateur a sauté, en se basant sur |
|
|
19 |
* des règles appliquées à la positions des noeuds dans le temps. |
|
|
20 |
* |
|
|
21 |
* P.S : Cette partie est encore en développement. |
|
|
22 |
*/ |
|
|
23 |
|
|
|
24 |
using System; |
|
|
25 |
using System.Collections.Generic; |
|
|
26 |
using System.Linq; |
|
|
27 |
using System.Text; |
|
|
28 |
using Microsoft.Kinect; |
|
17
|
29 |
using Trakers.Debug; |
|
15
|
30 |
|
|
17
|
31 |
namespace Trakers.Tracking.Gestures |
|
15
|
32 |
{ |
|
|
33 |
public class JumpDetector : GestureDetector |
|
|
34 |
{ |
|
|
35 |
static int n = 0; |
|
|
36 |
|
|
17
|
37 |
public JumpDetector(DebugWindow _debug) : base(_debug) |
|
15
|
38 |
{ |
|
|
39 |
gesturePeriod = (float)1; |
|
|
40 |
indexesPerSecond = 30; |
|
|
41 |
indexesToCheck = (int)(gesturePeriod * indexesPerSecond); |
|
|
42 |
} |
|
|
43 |
|
|
|
44 |
/* |
|
|
45 |
* Lit les noeuds de l'historique du squelette afin de détecter un Jump. |
|
|
46 |
* Règles : |
|
|
47 |
* . |
|
|
48 |
*/ |
|
|
49 |
public bool CheckForJump() |
|
|
50 |
{ |
|
|
51 |
//Crée un historique de squelette local, puisque l'historique est mis à jour toutes les ~1/30 s. |
|
|
52 |
List<List<Joint>> localHistory = new List<List<Joint>>(history); |
|
|
53 |
|
|
|
54 |
//Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
|
|
55 |
if (localHistory.Count < indexesToCheck) |
|
|
56 |
return false; |
|
|
57 |
|
|
|
58 |
/* (HeadBelowBaseLine || LeftKneeBelowBaseLine || RightKneeBelowBaseLine || |
|
|
59 |
* LeftAnkleBelowBaseLine || RightAnkleBelowBaseLine || BodyFaceUpwards |
|
|
60 |
* |
|
|
61 |
* NOT |
|
|
62 |
* |
|
|
63 |
* AND |
|
|
64 |
* |
|
|
65 |
* HeadAboveBaseLine && LeftKneeAboveBaseLine && RightKneeAboveBaseLine && |
|
|
66 |
* LegsStraightPreviouslyBent) |
|
|
67 |
* |
|
|
68 |
* OR |
|
|
69 |
* |
|
|
70 |
* HeadFarAboveBaseLine |
|
|
71 |
*/ |
|
|
72 |
|
|
|
73 |
//La distance de référence est ici la distance entre le milieu du dos et le milieu des épaules. |
|
|
74 |
refDistance = Math.Abs(localHistory[0][(int)JointType.Spine].Position.Y - localHistory[0][(int)JointType.ShoulderCenter].Position.Y); |
|
|
75 |
//On commence la position pour les indexesToCheck dernières postures (celle à l'index 0 étant la dernière). |
|
|
76 |
|
|
|
77 |
int beginIdx = localHistory.Count - indexesToCheck + 1; |
|
|
78 |
int middleIdx = localHistory.Count - indexesToCheck / 2; |
|
|
79 |
|
|
|
80 |
//bool middleOK = true |
|
|
81 |
bool topOfJump = false; |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
|
|
|
85 |
//De la position p1 à pn, on suit l'algorithme. |
|
|
86 |
for (int i = beginIdx ; i < localHistory.Count ; i++) |
|
|
87 |
{ |
|
|
88 |
|
|
|
89 |
if (localHistory[i][(int)JointType.HandRight].Position.Y < localHistory[beginIdx][(int)JointType.HandRight].Position.Y + refDistance && |
|
|
90 |
localHistory[i - 1][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.HandRight].Position.Y) |
|
|
91 |
{ |
|
|
92 |
topOfJump = true; |
|
|
93 |
//Console.Out.WriteLine("TOP"); |
|
|
94 |
} |
|
|
95 |
|
|
|
96 |
if (localHistory[i - 1][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.HandRight].Position.Y && !topOfJump) |
|
|
97 |
return false; |
|
|
98 |
|
|
|
99 |
//Si la position Y de la main est plus haute que la tête |
|
|
100 |
//OU si la position Y de la main est plus basse que la hanche |
|
|
101 |
//OU si la nouvelle position Z de la main est moins profonde que la précédente |
|
|
102 |
//OU si la nouvelle position X de la main est plus éloignée de la distance N par rapport à la première position X |
|
|
103 |
//OU si la nouvelle position Y de la main est plus éloignée de la distance N par rapport à la première position Y |
|
|
104 |
//Alors la main en question ne fait pas de push. |
|
|
105 |
if (localHistory[i - 1][(int)JointType.HandRight].Position.Y > localHistory[i][(int)JointType.HandRight].Position.Y && |
|
|
106 |
topOfJump || localHistory[i - 1][(int)JointType.HandRight].Position.Y < localHistory[i][(int)JointType.HandRight].Position.Y && |
|
|
107 |
!topOfJump) |
|
|
108 |
return false; |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
//Console.Out.WriteLine("OK"); |
|
|
112 |
|
|
|
113 |
//Si la distance en Z du geste a été plus courte que la distance N |
|
|
114 |
//Alors on retourne faux. |
|
|
115 |
//float dist = (localHistory[localHistory.Count - 1][handRightID].Position.X - localHistory[localHistory.Count - indexesToCheck][handRightID].Position.X); |
|
|
116 |
|
|
|
117 |
//Console.WriteLine(Math.Abs(localHistory[0][handLeftID].Position.Z - localHistory[localHistory.Count - indexesToCheck][handLeftID].Position.Z) * 100 + " " + refDistance); |
|
|
118 |
|
|
|
119 |
//Si la dernière position de la main droite/gauche est sur le côté gauche/droit du corps |
|
|
120 |
//OU si la première position calculée de la main droite/gauche est sur le côté gauche/droit du corps |
|
|
121 |
//Alors on retourne faux. |
|
|
122 |
|
|
|
123 |
//On supprime l'historique local. |
|
|
124 |
|
|
|
125 |
return false; |
|
|
126 |
} |
|
|
127 |
} |
|
|
128 |
} |