|
0
|
1 |
/* |
|
8
|
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 |
/* |
|
3
|
11 |
* Projet : TraKERS |
|
0
|
12 |
* Module : MIDDLEWARE |
|
|
13 |
* Sous-Module : Tracking |
|
|
14 |
* Classe : KinectMain |
|
|
15 |
* |
|
|
16 |
* Auteur : alexandre.bastien@iri.centrepompidou.fr |
|
|
17 |
* |
|
|
18 |
* Fonctionnalités : Récupère les trames de données de la Kinect, les squelettes détectés via le SDK 1.0 de Microsoft. |
|
|
19 |
* Interprète ces trames de façon à afficher le flux vidéo couleurs, et récupérer la distance de l'utilisateur et les |
|
|
20 |
* noeuds de son squelette. Lance des événements lorsque la main gauche/droite entre dans/quitte le champ. |
|
|
21 |
* Envoie des données au sous-module de debug de manière a afficher un retour visuel sur la position de l'utilisateur, |
|
|
22 |
* son squelette, la détection de ses mains. |
|
|
23 |
*/ |
|
|
24 |
|
|
|
25 |
using System; |
|
|
26 |
using System.Collections.Generic; |
|
|
27 |
using System.Linq; |
|
|
28 |
using System.Text; |
|
|
29 |
using System.Windows; |
|
|
30 |
using System.Windows.Controls; |
|
|
31 |
using System.Windows.Data; |
|
|
32 |
using System.Windows.Documents; |
|
|
33 |
using System.Windows.Input; |
|
|
34 |
using System.Windows.Media; |
|
|
35 |
using System.Windows.Media.Imaging; |
|
|
36 |
using System.Windows.Navigation; |
|
|
37 |
using System.Windows.Shapes; |
|
|
38 |
using System.Drawing; |
|
|
39 |
using System.Windows.Media.Media3D; |
|
|
40 |
using Microsoft.Kinect; |
|
|
41 |
|
|
|
42 |
using Coding4Fun.Kinect.Wpf; |
|
|
43 |
using System.ComponentModel; |
|
|
44 |
|
|
|
45 |
using Trakers.Debug; |
|
|
46 |
using Tuio; |
|
|
47 |
using Trakers.Communication; |
|
|
48 |
using System.IO; |
|
|
49 |
using Trakers.Tracking.Gestures; |
|
|
50 |
using Trakers.Tracking.Events; |
|
|
51 |
using System.Configuration; |
|
3
|
52 |
using System.Resources; |
|
|
53 |
using System.Reflection; |
|
0
|
54 |
|
|
|
55 |
namespace Trakers.Tracking |
|
|
56 |
{ |
|
|
57 |
//Il s'agit des fonctions permettant d'appeler les fonctions des événements Main droite/gauche entre/quitte le champ. |
|
|
58 |
public delegate void LeftHandTrackedHandler(object o, LeftHandTrackedEventArgs e); |
|
|
59 |
public delegate void RightHandTrackedHandler(object o, RightHandTrackedEventArgs e); |
|
|
60 |
public delegate void LeftHandQuitHandler(object o, LeftHandQuitEventArgs e); |
|
|
61 |
public delegate void RightHandQuitHandler(object o, RightHandQuitEventArgs e); |
|
3
|
62 |
//Il s'agit de la fonction permettant d'appeler les fonctions des événements Swipe left/right/up/down. |
|
0
|
63 |
public delegate void SwipeHandler(object o, SwipeEventArgs e); |
|
3
|
64 |
//Il s'agit de la fonction permettant d'appeler les fonctions des événements Push/Pull. |
|
|
65 |
public delegate void PushHandler(object o, PushEventArgs e); |
|
|
66 |
//Il s'agit de la fonction permettant d'appeler les fonctions des événements Jump. |
|
|
67 |
public delegate void JumpHandler(object o, JumpEventArgs e); |
|
6
|
68 |
//Il s'agit de la fonction permettant d'appeler les fonctions des événements de proximité. |
|
|
69 |
public delegate void UserPositionHandler(object o, UserPositionEventArgs e); |
|
11
|
70 |
//Il s'agit de la fonctoin permettant de notifier le serveur en cas de changement de mode. |
|
|
71 |
public delegate void ModChangeHandler(object o, ModChangeEventArgs e); |
|
0
|
72 |
|
|
|
73 |
public class KinectMain |
|
|
74 |
{ |
|
3
|
75 |
//Gestionnaire de ressources. |
|
|
76 |
private ResourceManager rm; |
|
0
|
77 |
//Fenêtre de debug. |
|
|
78 |
private Debug.DebugWindow debug; |
|
|
79 |
//Squelettes (Il y en a 6 par défaut). |
|
|
80 |
private Skeleton[] skeletons; |
|
|
81 |
//Caméra infrarouge (sensor) de la Kinect. |
|
|
82 |
private KinectSensor kinectSensor; |
|
|
83 |
|
|
3
|
84 |
//Détecteur de swipes. |
|
0
|
85 |
private SwipeDetector swipeDetector; |
|
3
|
86 |
//Détecteur de pushes. |
|
|
87 |
private PushDetector pushDetector; |
|
|
88 |
//Détecteur de jumps. |
|
|
89 |
private JumpDetector jumpDetector; |
|
6
|
90 |
//Détecteur de proximité. |
|
|
91 |
private UserPositionDetector userPositionDetector; |
|
0
|
92 |
|
|
|
93 |
//Distances min/max délimitant le champ de recherche. |
|
|
94 |
private float minDistHands; |
|
|
95 |
private float maxDistHands; |
|
6
|
96 |
private float minDist; |
|
|
97 |
private float maxDist; |
|
|
98 |
private float zeroPoint; |
|
11
|
99 |
private int imagesToShow; |
|
0
|
100 |
|
|
3
|
101 |
//Temps de rafraichissement pour le timer (Détection de gesture dans le serveur TUIO). |
|
|
102 |
private int timerElapsing; |
|
|
103 |
|
|
0
|
104 |
//Serveur TUIO pour la connexion du Middleware vers le Front Atelier. |
|
|
105 |
private Server server; |
|
|
106 |
|
|
|
107 |
//Les événements des mains pour la recherche. |
|
|
108 |
public static event LeftHandTrackedHandler LeftHandTrackedEvent; |
|
|
109 |
public static event RightHandTrackedHandler RightHandTrackedEvent; |
|
|
110 |
public static event LeftHandQuitHandler LeftHandQuitEvent; |
|
|
111 |
public static event RightHandQuitHandler RightHandQuitEvent; |
|
3
|
112 |
//L'événement swipe. |
|
0
|
113 |
public static event SwipeHandler SwipeEvent; |
|
3
|
114 |
//L'événement push. |
|
|
115 |
public static event PushHandler PushEvent; |
|
|
116 |
//L'événement jump. |
|
|
117 |
public static event JumpHandler JumpEvent; |
|
6
|
118 |
//L'événement l'utilisateur se déplace dans la zone de détection. |
|
|
119 |
public static event UserPositionHandler UserPositionEvent; |
|
11
|
120 |
//L'événement on change de mode. |
|
|
121 |
public static event ModChangeHandler ModChangeEvent; |
|
5
|
122 |
|
|
3
|
123 |
private string connexionHost; |
|
|
124 |
private int connexionPort; |
|
0
|
125 |
|
|
|
126 |
/* |
|
|
127 |
* Initialisation de la classe principale. |
|
|
128 |
* Affiche l'écran de debug dans lequel on voit la distance à la Kinect, |
|
|
129 |
* les mains détectées et le squelette de l'utilisateur. |
|
|
130 |
*/ |
|
|
131 |
public KinectMain() |
|
|
132 |
{ |
|
5
|
133 |
//On fait appel au gestionnaire de ressources. |
|
|
134 |
rm = new ResourceManager("Trakers.Properties.resources", Assembly.GetExecutingAssembly()); |
|
0
|
135 |
|
|
|
136 |
//On tente de charger les paramètres du fichier params.ini. |
|
|
137 |
//Si on n'y arrive pas, on affiche une erreur et on charge les paramètres par défaut. |
|
|
138 |
if (!loadParameters()) |
|
|
139 |
{ |
|
3
|
140 |
debug.ExceptionLbl.Content = rm.GetString("loadParametersFail"); |
|
0
|
141 |
//Distances de détection des mains par défaut pour la recherche (ici de 1m à 2m de la Kinect). |
|
6
|
142 |
minDistHands = 1.0f; |
|
|
143 |
maxDistHands = 1.5f; |
|
|
144 |
minDist = 1.0f; |
|
|
145 |
maxDist = 4.0f; |
|
|
146 |
zeroPoint = 1.7f; |
|
3
|
147 |
connexionHost = "127.0.0.1"; |
|
|
148 |
connexionPort = 80; |
|
|
149 |
timerElapsing = 1000; |
|
11
|
150 |
imagesToShow = 25; |
|
0
|
151 |
} |
|
|
152 |
|
|
7
|
153 |
//On crée la fenêtre de debug. |
|
|
154 |
debug = new Debug.DebugWindow(this); |
|
|
155 |
|
|
6
|
156 |
//On crée les détecteurs de gestes. |
|
|
157 |
swipeDetector = new SwipeDetector(debug); |
|
|
158 |
pushDetector = new PushDetector(debug); |
|
|
159 |
jumpDetector = new JumpDetector(debug); |
|
|
160 |
//On crée le détecteur de proximité. |
|
|
161 |
userPositionDetector = new UserPositionDetector(debug, minDist, maxDist, zeroPoint, minDistHands, maxDistHands); |
|
|
162 |
|
|
0
|
163 |
//On affiche la fenêtre de debug. |
|
|
164 |
try |
|
|
165 |
{ |
|
|
166 |
debug.ShowDialog(); |
|
|
167 |
} |
|
|
168 |
catch(Exception){} |
|
|
169 |
} |
|
|
170 |
|
|
|
171 |
/* |
|
3
|
172 |
* Initialisation de la classe principale avec comme argument le gestionnaire de ressources. |
|
|
173 |
*/ |
|
|
174 |
public KinectMain(ResourceManager _rm) : this() |
|
|
175 |
{ |
|
|
176 |
rm = _rm; |
|
|
177 |
} |
|
|
178 |
|
|
|
179 |
/* |
|
0
|
180 |
* Initialisation du sensor de la Kinect. |
|
|
181 |
*/ |
|
|
182 |
public void KinectInitialization() |
|
|
183 |
{ |
|
|
184 |
try |
|
|
185 |
{ |
|
|
186 |
//On sélectionne la première kinect détectée. |
|
|
187 |
kinectSensor = KinectSensor.KinectSensors.FirstOrDefault(s => s.Status == KinectStatus.Connected); |
|
|
188 |
//La caméra couleur est activée avec une résolution 640x480 et un framerate de 30 FPS. |
|
|
189 |
kinectSensor.ColorStream.Enable(ColorImageFormat.RgbResolution640x480Fps30); |
|
|
190 |
//La caméra de profondeur est activée. |
|
|
191 |
kinectSensor.DepthStream.Enable(); |
|
|
192 |
//Le squelette est activé. |
|
|
193 |
kinectSensor.SkeletonStream.Enable(); |
|
|
194 |
|
|
|
195 |
//Quand le Middleware reçoit des trames de la Kinect, on va dans cette fonction. |
|
|
196 |
kinectSensor.AllFramesReady += new EventHandler<AllFramesReadyEventArgs>(AllFramesReady); |
|
|
197 |
|
|
3
|
198 |
//On applique des paramètres d'ajustement pour le squelette. |
|
|
199 |
TransformSmoothParameters parameters = new TransformSmoothParameters(); |
|
|
200 |
parameters.Smoothing = 0.2f; |
|
|
201 |
parameters.Correction = 0.8f; |
|
|
202 |
parameters.Prediction = 0.0f; |
|
|
203 |
parameters.JitterRadius = 0.5f; |
|
|
204 |
parameters.MaxDeviationRadius = 0.5f; |
|
|
205 |
kinectSensor.SkeletonStream.Enable(parameters); |
|
0
|
206 |
//On démarre la Kinect. |
|
|
207 |
kinectSensor.Start(); |
|
|
208 |
debug.ExceptionLbl.Content = ""; |
|
|
209 |
} |
|
|
210 |
catch (System.Exception) |
|
|
211 |
{ |
|
3
|
212 |
debug.ExceptionLbl.Content = rm.GetString("KinectNotConnected"); |
|
0
|
213 |
} |
|
|
214 |
|
|
|
215 |
//Pour les événements main gauche/droite entre dans/quitte le champ, on a 4 listeners. |
|
|
216 |
//Fonction appelée lorsque la main gauche entre dans le champ de recherche. |
|
|
217 |
LeftHandTrackedListener leftHandTrackedListener = new LeftHandTrackedListener(); |
|
|
218 |
LeftHandTrackedEvent += new LeftHandTrackedHandler(leftHandTrackedListener.ShowOnScreen); |
|
|
219 |
|
|
|
220 |
//Fonction appelée lorsque la main droite entre dans le champ de recherche. |
|
|
221 |
RightHandTrackedListener rightHandTrackedListener = new RightHandTrackedListener(); |
|
|
222 |
RightHandTrackedEvent += new RightHandTrackedHandler(rightHandTrackedListener.ShowOnScreen); |
|
|
223 |
|
|
|
224 |
//Fonction appelée lorsque la main gauche quitte le champ de recherche. |
|
|
225 |
LeftHandQuitListener leftHandQuitListener = new LeftHandQuitListener(); |
|
|
226 |
LeftHandQuitEvent += new LeftHandQuitHandler(leftHandQuitListener.ShowOnScreen); |
|
|
227 |
|
|
|
228 |
//Fonction appelée lorsque la main droite quitte le champ de recherche. |
|
|
229 |
RightHandQuitListener rightHandQuitListener = new RightHandQuitListener(); |
|
|
230 |
RightHandQuitEvent += new RightHandQuitHandler(rightHandQuitListener.ShowOnScreen); |
|
|
231 |
|
|
3
|
232 |
//Fonction appelée lorsque l'utilisateur effectue un Swipe right/left/up/down. |
|
|
233 |
SwipeListener swipeListener = new SwipeListener(); |
|
0
|
234 |
SwipeEvent += new SwipeHandler(swipeListener.ShowOnScreen); |
|
|
235 |
|
|
3
|
236 |
//Fonction appelée lorsque l'utilisateur effectue un Push/Pull. |
|
|
237 |
PushListener pushListener = new PushListener(); |
|
|
238 |
PushEvent += new PushHandler(pushListener.ShowOnScreen); |
|
|
239 |
|
|
|
240 |
//Fonction appelée lorsque l'utilisateur effectue un Jump. |
|
|
241 |
JumpListener jumpListener = new JumpListener(); |
|
|
242 |
JumpEvent += new JumpHandler(jumpListener.ShowOnScreen); |
|
|
243 |
|
|
6
|
244 |
//Fonction appelée lorsque l'utilisateur se déplace dans la zone de détection. |
|
|
245 |
UserPositionListener userPositionListener = new UserPositionListener(); |
|
|
246 |
UserPositionEvent += new UserPositionHandler(userPositionListener.ShowOnScreen); |
|
|
247 |
|
|
11
|
248 |
//Fonction appelée lorsqu'on change de mode. |
|
|
249 |
ModChangeListener modChangeListener = new ModChangeListener(); |
|
|
250 |
ModChangeEvent += new ModChangeHandler(modChangeListener.ShowOnScreen); |
|
|
251 |
|
|
0
|
252 |
//On connecte le serveur à l'adresse locale sur le port 80. |
|
5
|
253 |
server = new Server(connexionHost, connexionPort, timerElapsing, debug); |
|
0
|
254 |
} |
|
|
255 |
|
|
|
256 |
/* |
|
|
257 |
* Fermeture du sensor de la Kinect. |
|
|
258 |
*/ |
|
|
259 |
public void KinectClose() |
|
|
260 |
{ |
|
|
261 |
try |
|
|
262 |
{ |
|
|
263 |
//On stoppe la Kinect. |
|
|
264 |
kinectSensor.Stop(); |
|
|
265 |
//On met a zero l'image d'affichage et le serveur. |
|
|
266 |
debug.DebugImage.Source = null; |
|
|
267 |
//server = null; |
|
|
268 |
debug.ExceptionLbl.Content = ""; |
|
|
269 |
} |
|
|
270 |
catch (System.Exception) |
|
|
271 |
{ |
|
3
|
272 |
debug.ExceptionLbl.Content = rm.GetString("KinectNotConnected"); |
|
0
|
273 |
} |
|
|
274 |
} |
|
|
275 |
|
|
|
276 |
/* |
|
|
277 |
* Récupère le premier squelette. |
|
|
278 |
*/ |
|
3
|
279 |
Skeleton GetFirstSkeleton(object sender, AllFramesReadyEventArgs e) |
|
0
|
280 |
{ |
|
|
281 |
using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) |
|
|
282 |
{ |
|
|
283 |
if (skeletonFrameData == null) |
|
|
284 |
return null; |
|
|
285 |
if ((skeletons == null) || (skeletons.Length != skeletonFrameData.SkeletonArrayLength)) |
|
|
286 |
skeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength]; |
|
|
287 |
skeletonFrameData.CopySkeletonDataTo(skeletons); |
|
|
288 |
|
|
|
289 |
//On obtient le premier skelette. |
|
|
290 |
Skeleton first = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); |
|
|
291 |
|
|
|
292 |
return first; |
|
|
293 |
} |
|
|
294 |
} |
|
|
295 |
|
|
|
296 |
/* |
|
|
297 |
* Récupère le squelette le plus proche. |
|
|
298 |
*/ |
|
3
|
299 |
Skeleton GetNearestSkeleton(object sender, AllFramesReadyEventArgs e) |
|
0
|
300 |
{ |
|
|
301 |
using (SkeletonFrame skeletonFrameData = e.OpenSkeletonFrame()) |
|
|
302 |
{ |
|
|
303 |
if (skeletonFrameData == null) |
|
|
304 |
return null; |
|
|
305 |
if ((skeletons == null) || (skeletons.Length != skeletonFrameData.SkeletonArrayLength)) |
|
|
306 |
skeletons = new Skeleton[skeletonFrameData.SkeletonArrayLength]; |
|
|
307 |
skeletonFrameData.CopySkeletonDataTo(skeletons); |
|
|
308 |
|
|
|
309 |
Skeleton s; |
|
|
310 |
float minDist = (float)-1.0; |
|
|
311 |
int minID = 0; |
|
|
312 |
|
|
|
313 |
//Pour tous les squelettes. |
|
|
314 |
for(int i = 0 ; i < skeletons.Count() ; i++) |
|
|
315 |
{ |
|
|
316 |
s = skeletons.ElementAt(i); |
|
|
317 |
//S'il est tracké. |
|
|
318 |
if(s.TrackingState == SkeletonTrackingState.Tracked) |
|
|
319 |
{ |
|
|
320 |
//On récupère sa position et on obtient la distance min et l'ID du squelette qui est à la distance min. |
|
|
321 |
float dist = skeletons.ElementAt(i).Position.Z; |
|
|
322 |
if (minDist == -1) |
|
|
323 |
{ |
|
|
324 |
minDist = dist; |
|
|
325 |
minID = i; |
|
|
326 |
} |
|
|
327 |
else if(minDist > dist) |
|
|
328 |
{ |
|
|
329 |
minDist = dist; |
|
|
330 |
minID = i; |
|
|
331 |
} |
|
|
332 |
} |
|
|
333 |
} |
|
|
334 |
|
|
|
335 |
//On renvoie le skelette le plus proche. |
|
|
336 |
return skeletons.ElementAt(minID); |
|
|
337 |
} |
|
|
338 |
} |
|
|
339 |
|
|
|
340 |
/* |
|
|
341 |
* Récupère le squelette le plus proche. |
|
|
342 |
*/ |
|
|
343 |
private void AllFramesReady(object sender, AllFramesReadyEventArgs e) |
|
|
344 |
{ |
|
|
345 |
//On ne calcule rien si la fenêtre de debug se ferme. |
|
|
346 |
if (debug.isClosing()) |
|
|
347 |
return; |
|
|
348 |
|
|
|
349 |
//On met à jour la vidéo de debug. |
|
|
350 |
debug.RefreshVideo(e); |
|
|
351 |
//On récupère le premier squelette tracké. |
|
|
352 |
//Skeleton first = GetFirstSkeleton(e); |
|
|
353 |
//On récupère le plus proche squelette tracké. |
|
3
|
354 |
Skeleton first = GetNearestSkeleton(sender, e); |
|
0
|
355 |
//Si celui-ci n’est pas nul |
|
|
356 |
if (first == null) |
|
|
357 |
return; |
|
3
|
358 |
|
|
0
|
359 |
//Si ce squelette est tracké (donc suivi et reconnu par la camera) |
|
|
360 |
if (first.TrackingState == SkeletonTrackingState.Tracked) |
|
|
361 |
{ |
|
|
362 |
//Ensemble des noeuds du squelette. |
|
5
|
363 |
Joint hipCenter = getJoint(first, JointType.HipCenter), spine = getJoint(first, JointType.Spine), shoulderCenter = getJoint(first, JointType.ShoulderCenter), head = getJoint(first, JointType.Head); |
|
|
364 |
Joint shoulderLeft = getJoint(first, JointType.ShoulderLeft), elbowLeft = getJoint(first, JointType.ElbowLeft), wristLeft = getJoint(first, JointType.WristLeft), handLeft = getJoint(first, JointType.HandLeft); |
|
|
365 |
Joint shoulderRight = getJoint(first, JointType.ShoulderRight), elbowRight = getJoint(first, JointType.ElbowRight), wristRight = getJoint(first, JointType.WristRight), handRight = getJoint(first, JointType.HandRight); |
|
|
366 |
Joint hipLeft = getJoint(first, JointType.HipLeft), kneeLeft = getJoint(first, JointType.KneeLeft), ankleLeft = getJoint(first, JointType.AnkleLeft), footLeft = getJoint(first, JointType.FootLeft); |
|
|
367 |
Joint hipRight = getJoint(first, JointType.HipRight), kneeRight = getJoint(first, JointType.KneeRight), ankleRight = getJoint(first, JointType.AnkleRight), footRight = getJoint(first, JointType.FootRight); |
|
0
|
368 |
|
|
|
369 |
//On construit l'historique des postures. |
|
3
|
370 |
List<Joint> joints = new List<Joint>(); |
|
0
|
371 |
joints.Clear(); |
|
5
|
372 |
joints.Insert((int)JointType.HipCenter, hipCenter); |
|
|
373 |
joints.Insert((int)JointType.Spine, spine); |
|
|
374 |
joints.Insert((int)JointType.ShoulderCenter, shoulderCenter); |
|
|
375 |
joints.Insert((int)JointType.Head, head); |
|
|
376 |
joints.Insert((int)JointType.ShoulderLeft, shoulderLeft); |
|
|
377 |
joints.Insert((int)JointType.ElbowLeft, elbowLeft); |
|
|
378 |
joints.Insert((int)JointType.WristLeft, wristLeft); |
|
|
379 |
joints.Insert((int)JointType.HandLeft, handLeft); |
|
|
380 |
joints.Insert((int)JointType.ShoulderRight, shoulderRight); |
|
|
381 |
joints.Insert((int)JointType.ElbowRight, elbowRight); |
|
|
382 |
joints.Insert((int)JointType.WristRight, wristRight); |
|
|
383 |
joints.Insert((int)JointType.HandRight, handRight); |
|
|
384 |
joints.Insert((int)JointType.HipLeft, hipLeft); |
|
|
385 |
joints.Insert((int)JointType.KneeLeft, kneeLeft); |
|
|
386 |
joints.Insert((int)JointType.AnkleLeft, ankleLeft); |
|
|
387 |
joints.Insert((int)JointType.FootLeft, footLeft); |
|
|
388 |
joints.Insert((int)JointType.HipRight, hipRight); |
|
|
389 |
joints.Insert((int)JointType.KneeRight, kneeRight); |
|
|
390 |
joints.Insert((int)JointType.AnkleRight, ankleRight); |
|
|
391 |
joints.Insert((int)JointType.FootRight, footRight); |
|
3
|
392 |
GestureDetector.UpdateSkeletonHistory(joints); |
|
0
|
393 |
|
|
|
394 |
//Si la main gauche est dans le champ, on lance l'événement approprié. |
|
|
395 |
if (handLeft.Position.Z < maxDistHands && handLeft.Position.Z > minDistHands) |
|
|
396 |
{ |
|
|
397 |
LeftHandTrackedEventArgs leftHandTrackedEvent = new LeftHandTrackedEventArgs(handLeft, handLeft.Position.Z, debug, server); |
|
|
398 |
OnLeftHandTrackedEvent(leftHandTrackedEvent); |
|
|
399 |
} |
|
|
400 |
//Si la main gauche quitte le champ, on lance l'événement approprié. |
|
|
401 |
else |
|
|
402 |
{ |
|
|
403 |
LeftHandQuitEventArgs leftHandQuitEvent = new LeftHandQuitEventArgs(handLeft, handLeft.Position.Z, debug, server); |
|
|
404 |
OnLeftHandQuitEvent(leftHandQuitEvent); |
|
|
405 |
} |
|
|
406 |
//Si la main droite est dans le champ, on lance l'événement approprié. |
|
|
407 |
if (handRight.Position.Z < maxDistHands && handRight.Position.Z > minDistHands) |
|
|
408 |
{ |
|
|
409 |
RightHandTrackedEventArgs rightHandTrackedEvent = new RightHandTrackedEventArgs(handRight, handRight.Position.Z, debug, server); |
|
|
410 |
OnRightHandTrackedEvent(rightHandTrackedEvent); |
|
|
411 |
} |
|
|
412 |
//Si la main droite quitte le champ, on lance l'événement approprié. |
|
|
413 |
else |
|
|
414 |
{ |
|
|
415 |
RightHandQuitEventArgs rightHandQuitEvent = new RightHandQuitEventArgs(handRight, handRight.Position.Z, debug, server); |
|
|
416 |
OnRightHandQuitEvent(rightHandQuitEvent); |
|
|
417 |
} |
|
7
|
418 |
|
|
0
|
419 |
//Si l'utilisateur effectue un swipe left. |
|
|
420 |
if (swipeDetector.CheckForSwipeLeft()) |
|
|
421 |
{ |
|
|
422 |
SwipeEventArgs swipeEvent = new SwipeEventArgs(debug, server, SwipeDetector.Direction.LEFT); |
|
|
423 |
OnSwipeEvent(swipeEvent); |
|
|
424 |
} |
|
|
425 |
|
|
3
|
426 |
//Si l'utilisateur effectue un swipe right. |
|
|
427 |
if (swipeDetector.CheckForSwipeRight()) |
|
|
428 |
{ |
|
|
429 |
SwipeEventArgs swipeEvent = new SwipeEventArgs(debug, server, SwipeDetector.Direction.RIGHT); |
|
|
430 |
OnSwipeEvent(swipeEvent); |
|
|
431 |
} |
|
|
432 |
|
|
|
433 |
//Enum sur la main qui effectue le geste. |
|
|
434 |
PushDetector.Hand handPush; |
|
|
435 |
//Si l'utilisateur effectue un push. |
|
|
436 |
if ((handPush = pushDetector.CheckForPush()) != PushDetector.Hand.NONE) |
|
|
437 |
{ |
|
|
438 |
PushEventArgs pushEvent = new PushEventArgs(debug, server, PushDetector.Direction.PUSH, handPush); |
|
|
439 |
OnPushEvent(pushEvent); |
|
|
440 |
} |
|
|
441 |
//Si l'utilisateur effectue un pull. |
|
|
442 |
if ((handPush = pushDetector.CheckForPull()) != PushDetector.Hand.NONE) |
|
|
443 |
{ |
|
|
444 |
PushEventArgs pushEvent = new PushEventArgs(debug, server, PushDetector.Direction.PULL, handPush); |
|
|
445 |
OnPushEvent(pushEvent); |
|
|
446 |
} |
|
|
447 |
|
|
|
448 |
//Si l'utilisateur effectue un saut. |
|
|
449 |
/*if (jumpDetector.CheckForJump()) |
|
|
450 |
{ |
|
|
451 |
JumpEventArgs jumpEvent = new JumpEventArgs(debug, server); |
|
|
452 |
OnJumpEvent(jumpEvent); |
|
|
453 |
}*/ |
|
0
|
454 |
|
|
6
|
455 |
//Si l'utilisateur se déplace dans la zone de détection. |
|
|
456 |
//On traite le problème en plusieurs limites, on discrétise la zone. |
|
7
|
457 |
if (first.TrackingState == SkeletonTrackingState.Tracked) |
|
6
|
458 |
{ |
|
|
459 |
float proximity = userPositionDetector.CalcProximity(first.Position.Z); |
|
11
|
460 |
int numberOfImages = userPositionDetector.ImagesToShow(proximity, imagesToShow); |
|
6
|
461 |
|
|
|
462 |
if (proximity > 0f) |
|
|
463 |
{ |
|
11
|
464 |
UserPositionEventArgs userPositionEvent = new UserPositionEventArgs(debug, server, proximity, numberOfImages); |
|
6
|
465 |
OnUserPositionEvent(userPositionEvent); |
|
|
466 |
} |
|
|
467 |
else |
|
7
|
468 |
{ |
|
|
469 |
debug.hideSkeleton(); |
|
|
470 |
} |
|
6
|
471 |
} |
|
|
472 |
|
|
0
|
473 |
//Dessine le squelette dans le debug. |
|
3
|
474 |
debug.drawJoints(first.Joints, first); |
|
|
475 |
debug.showSkeleton(hipCenter, spine, shoulderCenter, head, shoulderLeft, elbowLeft, wristLeft, handLeft, shoulderRight, elbowRight, wristRight, handRight, hipLeft, kneeLeft, ankleLeft, footLeft, hipRight, kneeRight, ankleRight, footRight); |
|
0
|
476 |
} |
|
7
|
477 |
else |
|
|
478 |
debug.hideSkeleton(); |
|
0
|
479 |
} |
|
|
480 |
|
|
|
481 |
/* |
|
|
482 |
* Change l'échelle des coordonnées d'un noeud pour qu'en X et Y il corresponde à la résolution et en Z à la distance à la Kinect. |
|
|
483 |
*/ |
|
5
|
484 |
public Joint getJoint(Skeleton ske, JointType jointID) |
|
0
|
485 |
{ |
|
5
|
486 |
return Coding4Fun.Kinect.Wpf.SkeletalExtensions.ScaleTo(ske.Joints[jointID], 600, 400, 0.75f, 0.75f); |
|
0
|
487 |
} |
|
|
488 |
|
|
|
489 |
/* |
|
|
490 |
* Initialise l'événement et fait appel aux fonctions du listener quand la main gauche entre dans le champ. |
|
|
491 |
*/ |
|
|
492 |
public static void OnLeftHandTrackedEvent(LeftHandTrackedEventArgs e) |
|
|
493 |
{ |
|
|
494 |
if (LeftHandTrackedEvent != null) |
|
|
495 |
LeftHandTrackedEvent(new object(), e); |
|
|
496 |
} |
|
|
497 |
|
|
|
498 |
/* |
|
|
499 |
* Initialise l'événement et fait appel aux fonctions du listener quand la main droite entre dans le champ. |
|
|
500 |
*/ |
|
|
501 |
public static void OnRightHandTrackedEvent(RightHandTrackedEventArgs e) |
|
|
502 |
{ |
|
|
503 |
if (RightHandTrackedEvent != null) |
|
|
504 |
RightHandTrackedEvent(new object(), e); |
|
|
505 |
} |
|
|
506 |
|
|
|
507 |
/* |
|
|
508 |
* Initialise l'événement et fait appel aux fonctions du listener quand la main gauche quitte le champ. |
|
|
509 |
*/ |
|
|
510 |
public static void OnLeftHandQuitEvent(LeftHandQuitEventArgs e) |
|
|
511 |
{ |
|
|
512 |
if (LeftHandQuitEvent != null) |
|
|
513 |
LeftHandQuitEvent(new object(), e); |
|
|
514 |
} |
|
|
515 |
|
|
|
516 |
/* |
|
|
517 |
* Initialise l'événement et fait appel aux fonctions du listener quand la main droite quitte le champ. |
|
|
518 |
*/ |
|
|
519 |
public static void OnRightHandQuitEvent(RightHandQuitEventArgs e) |
|
|
520 |
{ |
|
|
521 |
if (RightHandQuitEvent != null) |
|
|
522 |
RightHandQuitEvent(new object(), e); |
|
|
523 |
} |
|
|
524 |
|
|
|
525 |
/* |
|
|
526 |
* Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur effectue un swipe right. |
|
|
527 |
*/ |
|
|
528 |
public static void OnSwipeEvent(SwipeEventArgs e) |
|
|
529 |
{ |
|
|
530 |
if (SwipeEvent != null) |
|
|
531 |
SwipeEvent(new object(), e); |
|
|
532 |
} |
|
|
533 |
|
|
|
534 |
/* |
|
3
|
535 |
* Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur effectue un push. |
|
0
|
536 |
*/ |
|
3
|
537 |
public static void OnPushEvent(PushEventArgs e) |
|
0
|
538 |
{ |
|
3
|
539 |
if (PushEvent != null) |
|
|
540 |
PushEvent(new object(), e); |
|
|
541 |
} |
|
0
|
542 |
|
|
|
543 |
/* |
|
3
|
544 |
* Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur effectue un saut. |
|
0
|
545 |
*/ |
|
3
|
546 |
public static void OnJumpEvent(JumpEventArgs e) |
|
0
|
547 |
{ |
|
3
|
548 |
if (JumpEvent != null) |
|
|
549 |
JumpEvent(new object(), e); |
|
|
550 |
} |
|
0
|
551 |
|
|
|
552 |
/* |
|
6
|
553 |
* Initialise l'événement et fait appel aux fonctions du listener quand l'utilisateur se déplace |
|
|
554 |
* dans la zone de détection. |
|
|
555 |
*/ |
|
|
556 |
public static void OnUserPositionEvent(UserPositionEventArgs e) |
|
|
557 |
{ |
|
|
558 |
if (UserPositionEvent != null) |
|
|
559 |
UserPositionEvent(new object(), e); |
|
|
560 |
} |
|
|
561 |
|
|
|
562 |
/* |
|
11
|
563 |
* Initialise l'événement et fait appel aux fonctions du listener quand on change de mode. |
|
|
564 |
*/ |
|
|
565 |
public static void OnModChangeEvent(ModChangeEventArgs e) |
|
|
566 |
{ |
|
|
567 |
if (ModChangeEvent != null) |
|
|
568 |
ModChangeEvent(new object(), e); |
|
|
569 |
} |
|
|
570 |
|
|
|
571 |
/* |
|
0
|
572 |
* Méthode de chargement des paramètres (position du champ de recherche...). |
|
|
573 |
*/ |
|
|
574 |
public bool loadParameters() |
|
|
575 |
{ |
|
|
576 |
try |
|
|
577 |
{ |
|
3
|
578 |
minDistHands = (float)double.Parse(ConfigurationManager.AppSettings["searchMinDistance"]); |
|
|
579 |
maxDistHands = (float)double.Parse(ConfigurationManager.AppSettings["searchMaxDistance"]); |
|
6
|
580 |
minDist = (float)double.Parse(ConfigurationManager.AppSettings["minDistance"]); |
|
|
581 |
maxDist = (float)double.Parse(ConfigurationManager.AppSettings["maxDistance"]); |
|
|
582 |
zeroPoint = (float)double.Parse(ConfigurationManager.AppSettings["zeroPoint"]); |
|
3
|
583 |
connexionHost = ConfigurationManager.AppSettings["connexionHost"]; |
|
|
584 |
connexionPort = int.Parse(ConfigurationManager.AppSettings["connexionPort"]); |
|
|
585 |
timerElapsing = int.Parse(ConfigurationManager.AppSettings["timerElapsing"]); |
|
11
|
586 |
imagesToShow = int.Parse(ConfigurationManager.AppSettings["imagesToShow"]); |
|
0
|
587 |
} |
|
|
588 |
catch (Exception) |
|
|
589 |
{ |
|
|
590 |
return false; |
|
|
591 |
} |
|
6
|
592 |
|
|
|
593 |
if (maxDistHands <= 0f || minDistHands <= 0f || maxDistHands > maxDist || minDistHands > maxDist || |
|
|
594 |
minDistHands >= maxDistHands || zeroPoint < maxDistHands || minDistHands < minDist || |
|
11
|
595 |
zeroPoint >= maxDist || connexionPort < 0 || timerElapsing < 0 || imagesToShow < 1) |
|
3
|
596 |
{ |
|
|
597 |
debug.ExceptionLbl.Content = rm.GetString("loadParametersIncorrect"); |
|
|
598 |
return false; |
|
|
599 |
} |
|
0
|
600 |
return true; |
|
|
601 |
} |
|
5
|
602 |
|
|
|
603 |
/* |
|
|
604 |
* Met à jour les nouveaux paramètres dans la configuration. |
|
|
605 |
*/ |
|
|
606 |
public void updateParameters() |
|
|
607 |
{ |
|
6
|
608 |
userPositionDetector.setParams(minDist, maxDist, minDistHands, maxDistHands, zeroPoint); |
|
|
609 |
|
|
5
|
610 |
//On récupère la config. |
|
|
611 |
Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); |
|
|
612 |
//On met à jour. |
|
|
613 |
config.AppSettings.Settings.Remove("searchMinDistance"); |
|
|
614 |
config.AppSettings.Settings.Add("searchMinDistance", minDistHands.ToString()); |
|
|
615 |
config.AppSettings.Settings.Remove("searchMaxDistance"); |
|
|
616 |
config.AppSettings.Settings.Add("searchMaxDistance", maxDistHands.ToString()); |
|
6
|
617 |
config.AppSettings.Settings.Remove("minDistance"); |
|
|
618 |
config.AppSettings.Settings.Add("minDistance", minDist.ToString()); |
|
|
619 |
config.AppSettings.Settings.Remove("maxDistance"); |
|
|
620 |
config.AppSettings.Settings.Add("maxDistance", maxDist.ToString()); |
|
|
621 |
config.AppSettings.Settings.Remove("zeroPoint"); |
|
|
622 |
config.AppSettings.Settings.Add("zeroPoint", zeroPoint.ToString()); |
|
5
|
623 |
config.AppSettings.Settings.Remove("connexionHost"); |
|
|
624 |
config.AppSettings.Settings.Add("connexionHost", connexionHost); |
|
|
625 |
config.AppSettings.Settings.Remove("connexionPort"); |
|
|
626 |
config.AppSettings.Settings.Add("connexionPort", connexionPort.ToString()); |
|
|
627 |
config.AppSettings.Settings.Remove("timerElapsing"); |
|
|
628 |
config.AppSettings.Settings.Add("timerElapsing", timerElapsing.ToString()); |
|
11
|
629 |
config.AppSettings.Settings.Remove("imagesToShow"); |
|
|
630 |
config.AppSettings.Settings.Add("imagesToShow", imagesToShow.ToString()); |
|
5
|
631 |
|
|
|
632 |
//Sauvegarde la configuration. |
|
|
633 |
config.Save(ConfigurationSaveMode.Modified); |
|
|
634 |
ConfigurationManager.RefreshSection("appSettings"); |
|
|
635 |
} |
|
|
636 |
|
|
|
637 |
/* |
|
|
638 |
* Getters et setters des paramètres du Middleware. |
|
|
639 |
*/ |
|
|
640 |
public void setMinDistHands(float min) |
|
|
641 |
{ |
|
|
642 |
minDistHands = min; |
|
|
643 |
} |
|
|
644 |
public void setMaxDistHands(float max) |
|
|
645 |
{ |
|
|
646 |
maxDistHands = max; |
|
|
647 |
} |
|
11
|
648 |
public void setMinDist(float min) |
|
|
649 |
{ |
|
|
650 |
minDist = min; |
|
|
651 |
} |
|
|
652 |
public void setMaxDist(float max) |
|
|
653 |
{ |
|
|
654 |
maxDist = max; |
|
|
655 |
} |
|
|
656 |
public void setZeroPoint(float zero) |
|
|
657 |
{ |
|
|
658 |
zeroPoint = zero; |
|
|
659 |
} |
|
5
|
660 |
public void setConnexionHost(String host) |
|
|
661 |
{ |
|
|
662 |
connexionHost = host; |
|
|
663 |
} |
|
|
664 |
public void setConnexionPort(int port) |
|
|
665 |
{ |
|
|
666 |
connexionPort = port; |
|
|
667 |
} |
|
|
668 |
public void setTimerElapsing(int time) |
|
|
669 |
{ |
|
|
670 |
timerElapsing = time; |
|
|
671 |
} |
|
11
|
672 |
public void setImagesToShow(int _imagesToShow) |
|
|
673 |
{ |
|
|
674 |
imagesToShow = _imagesToShow; |
|
|
675 |
} |
|
5
|
676 |
|
|
|
677 |
public float getMinDistHands() |
|
|
678 |
{ |
|
|
679 |
return minDistHands; |
|
|
680 |
} |
|
|
681 |
public float getMaxDistHands() |
|
|
682 |
{ |
|
|
683 |
return maxDistHands; |
|
|
684 |
} |
|
11
|
685 |
public float getMinDist() |
|
|
686 |
{ |
|
|
687 |
return minDist; |
|
|
688 |
} |
|
|
689 |
public float getMaxDist() |
|
|
690 |
{ |
|
|
691 |
return maxDist; |
|
|
692 |
} |
|
|
693 |
public float getZeroPoint() |
|
|
694 |
{ |
|
|
695 |
return zeroPoint; |
|
|
696 |
} |
|
5
|
697 |
public String getConnexionHost() |
|
|
698 |
{ |
|
|
699 |
return connexionHost; |
|
|
700 |
} |
|
|
701 |
public int getConnexionPort() |
|
|
702 |
{ |
|
|
703 |
return connexionPort; |
|
|
704 |
} |
|
|
705 |
public int getTimerElapsing() |
|
|
706 |
{ |
|
|
707 |
return timerElapsing; |
|
|
708 |
} |
|
11
|
709 |
public int getImagesToShow() |
|
|
710 |
{ |
|
|
711 |
return imagesToShow; |
|
|
712 |
} |
|
0
|
713 |
} |
|
|
714 |
} |