|
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 : GestureDetector |
|
15 * |
|
16 * Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
17 * |
|
18 * Fonctionnalités : Reçoit les positions des noeuds envoyés par la classe de manipulation de la Kinect |
|
19 * et les stocke dans un historique. |
|
20 * Contient également des variables propres à toute gesture : distance de référence, point de départ, |
|
21 * durée de la gesture, FPS et nombre de frames à traiter. |
|
22 */ |
|
23 |
|
24 using System; |
|
25 using System.Collections.Generic; |
|
26 using System.Linq; |
|
27 using System.Text; |
|
28 using Microsoft.Kinect; |
|
29 using System.Drawing; |
|
30 |
|
31 namespace Trakers.MainModule.Gestures |
|
32 { |
|
33 public class GestureDetector |
|
34 { |
|
35 //Historique des positions du squelette. |
|
36 protected static List<List<Joint>> history = new List<List<Joint>>(); |
|
37 //protected JointCollection previousSkeleton; |
|
38 |
|
39 //Voici les ID des noeuds d'un squelette : variables magiques en attente de factorisation. |
|
40 /*protected int hipCenterID = 0, spineID = 1, shoulderCenterID = 2, headID = 3; |
|
41 protected int shoulderLeftID = 4, elbowLeftID = 5, wristLeftID = 6, handLeftID = 7; |
|
42 protected int shoulderRightID = 8, elbowRightID = 9, wristRightID = 10, handRightID = 11; |
|
43 protected int hipLeftID = 12, kneeLeftID = 13, ankleLeftID = 14, footLeftID = 15; |
|
44 protected int hipRightID = 16, kneeRightID = 17, ankleRightID = 18, footRightID = 19;*/ |
|
45 |
|
46 //Elements nécessaires à la reconnaissance du geste : |
|
47 //Distance du parcours du geste (va dépendre de la distance de l'utilisateur). |
|
48 protected float refDistance; |
|
49 //Position de départ pour le geste. |
|
50 protected SkeletonPoint startPoint; |
|
51 //Estimation du temps que prend la gesture (en s). |
|
52 protected float gesturePeriod = 1; |
|
53 //Estimation du nombre d'indexes par seconde (framerate). |
|
54 protected int indexesPerSecond = 30; |
|
55 //Estimation du nombre de positions du squelette à vérifier dans l'historique. |
|
56 protected int indexesToCheck;// = gesturePeriod * indexesPerSecond; |
|
57 |
|
58 public GestureDetector() |
|
59 { |
|
60 |
|
61 } |
|
62 |
|
63 //Setters. |
|
64 public void setRefDistance(float _refDistance) |
|
65 { |
|
66 refDistance = _refDistance; |
|
67 } |
|
68 public void setStartPoint(SkeletonPoint _startPoint) |
|
69 { |
|
70 startPoint = _startPoint; |
|
71 } |
|
72 public void setGesturePeriod(float _gesturePeriod) |
|
73 { |
|
74 gesturePeriod = _gesturePeriod; |
|
75 } |
|
76 public void setIndexesPerSecond(int _indexesPerSecond) |
|
77 { |
|
78 indexesPerSecond = _indexesPerSecond; |
|
79 } |
|
80 public void setIndexesToCheck(int _indexesToCheck) |
|
81 { |
|
82 indexesToCheck = _indexesToCheck; |
|
83 } |
|
84 |
|
85 //Getters. |
|
86 public float getRefDistance() |
|
87 { |
|
88 return refDistance; |
|
89 } |
|
90 public SkeletonPoint getStartPoint() |
|
91 { |
|
92 return startPoint; |
|
93 } |
|
94 public float getGesturePeriod() |
|
95 { |
|
96 return gesturePeriod; |
|
97 } |
|
98 public int getIndexesPerSecond() |
|
99 { |
|
100 return indexesPerSecond; |
|
101 } |
|
102 public int getIndexesToCheck() |
|
103 { |
|
104 return indexesToCheck; |
|
105 } |
|
106 |
|
107 //Stocke les gestes du skelette pour ~3 seconds (si on prend en compte que le framerate de la Kinect |
|
108 //est de ~30 fps. |
|
109 public static void UpdateSkeletonHistory(List<Joint> latestSkeleton) |
|
110 { |
|
111 history.Add(latestSkeleton); |
|
112 |
|
113 if (history.Count > 90) |
|
114 { |
|
115 history.RemoveAt(0); |
|
116 } |
|
117 } |
|
118 |
|
119 /*public bool CheckForHandWave() |
|
120 { |
|
121 //Crée un historique de squelette local, puisque l'historique est mis à jour toutes les ~1/30 s. |
|
122 List<Skeleton> history = new List<Skeleton>(history); |
|
123 //Si il n'y a pas assez de positions dans l'historique local pour vérifier le geste. |
|
124 if (history.Count < indexesToCheck) |
|
125 return false; |
|
126 |
|
127 float refDistance = Math.Abs(history[0].Joints.ElementAt(spineID).Position.Y - history[0].Joints.ElementAt(hipCenterID).Position.Y); |
|
128 float startPos = history[history.Count - indexesToCheck].Joints.ElementAt(handRightID).Position.X; |
|
129 bool movedRight = false; |
|
130 for (int i = history.Count - indexesToCheck + 1; i < history.Count; i++) |
|
131 { |
|
132 // Throughout the gesture period, right hand should be above theelbow, below the head and hand should be higher than the wrist |
|
133 if (!(history[i].Joints[JointID.HandRight].Position.Y > history[i].Joints[JointID.ElbowRight].Position.Y + refDistance && |
|
134 history[i].Joints[JointID.HandRight].Position.Y < history[i].Joints[JointID.Head].Position.Y && |
|
135 history[i].Joints[JointID.HandRight].Position.Y > history[i].Joints[JointID.WristRight].Position.Y + refDistance / 4)) |
|
136 { |
|
137 return false; |
|
138 } |
|
139 // If the previous condition was met, check if the hand has moved to the right |
|
140 if (history[i].Joints[JointID.HandRight].Position.X >= startPos + refDistance / 2 && !movedRight) |
|
141 { |
|
142 movedRight = true; |
|
143 } |
|
144 // If the hand did move to the right, check if it returned near the original position |
|
145 if (movedRight && history[i].Joints[JointID.HandRight].Position.X <= startPos + refDistance / 5) |
|
146 { |
|
147 skeletonHistory.Clear(); |
|
148 return true; |
|
149 } |
|
150 } |
|
151 return false; |
|
152 }*/ |
|
153 } |
|
154 } |