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