|
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 : 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; |
|
17
|
30 |
using Trakers.Debug; |
|
15
|
31 |
|
|
17
|
32 |
namespace Trakers.Tracking.Gestures |
|
15
|
33 |
{ |
|
|
34 |
public class GestureDetector |
|
|
35 |
{ |
|
17
|
36 |
public DebugWindow debug; |
|
|
37 |
|
|
15
|
38 |
//Historique des positions du squelette. |
|
|
39 |
protected static List<List<Joint>> history = new List<List<Joint>>(); |
|
|
40 |
//protected JointCollection previousSkeleton; |
|
|
41 |
|
|
|
42 |
//Voici les ID des noeuds d'un squelette : variables magiques en attente de factorisation. |
|
|
43 |
/*protected int hipCenterID = 0, spineID = 1, shoulderCenterID = 2, headID = 3; |
|
|
44 |
protected int shoulderLeftID = 4, elbowLeftID = 5, wristLeftID = 6, handLeftID = 7; |
|
|
45 |
protected int shoulderRightID = 8, elbowRightID = 9, wristRightID = 10, handRightID = 11; |
|
|
46 |
protected int hipLeftID = 12, kneeLeftID = 13, ankleLeftID = 14, footLeftID = 15; |
|
|
47 |
protected int hipRightID = 16, kneeRightID = 17, ankleRightID = 18, footRightID = 19;*/ |
|
|
48 |
|
|
|
49 |
//Elements nécessaires à la reconnaissance du geste : |
|
|
50 |
//Distance du parcours du geste (va dépendre de la distance de l'utilisateur). |
|
|
51 |
protected float refDistance; |
|
|
52 |
//Position de départ pour le geste. |
|
|
53 |
protected SkeletonPoint startPoint; |
|
|
54 |
//Estimation du temps que prend la gesture (en s). |
|
|
55 |
protected float gesturePeriod = 1; |
|
|
56 |
//Estimation du nombre d'indexes par seconde (framerate). |
|
|
57 |
protected int indexesPerSecond = 30; |
|
|
58 |
//Estimation du nombre de positions du squelette à vérifier dans l'historique. |
|
|
59 |
protected int indexesToCheck;// = gesturePeriod * indexesPerSecond; |
|
|
60 |
|
|
17
|
61 |
public GestureDetector(DebugWindow _debug) |
|
15
|
62 |
{ |
|
17
|
63 |
debug = _debug; |
|
15
|
64 |
} |
|
|
65 |
|
|
|
66 |
//Setters. |
|
|
67 |
public void setRefDistance(float _refDistance) |
|
|
68 |
{ |
|
|
69 |
refDistance = _refDistance; |
|
|
70 |
} |
|
|
71 |
public void setStartPoint(SkeletonPoint _startPoint) |
|
|
72 |
{ |
|
|
73 |
startPoint = _startPoint; |
|
|
74 |
} |
|
|
75 |
public void setGesturePeriod(float _gesturePeriod) |
|
|
76 |
{ |
|
|
77 |
gesturePeriod = _gesturePeriod; |
|
|
78 |
} |
|
|
79 |
public void setIndexesPerSecond(int _indexesPerSecond) |
|
|
80 |
{ |
|
|
81 |
indexesPerSecond = _indexesPerSecond; |
|
|
82 |
} |
|
|
83 |
public void setIndexesToCheck(int _indexesToCheck) |
|
|
84 |
{ |
|
|
85 |
indexesToCheck = _indexesToCheck; |
|
|
86 |
} |
|
|
87 |
|
|
|
88 |
//Getters. |
|
|
89 |
public float getRefDistance() |
|
|
90 |
{ |
|
|
91 |
return refDistance; |
|
|
92 |
} |
|
|
93 |
public SkeletonPoint getStartPoint() |
|
|
94 |
{ |
|
|
95 |
return startPoint; |
|
|
96 |
} |
|
|
97 |
public float getGesturePeriod() |
|
|
98 |
{ |
|
|
99 |
return gesturePeriod; |
|
|
100 |
} |
|
|
101 |
public int getIndexesPerSecond() |
|
|
102 |
{ |
|
|
103 |
return indexesPerSecond; |
|
|
104 |
} |
|
|
105 |
public int getIndexesToCheck() |
|
|
106 |
{ |
|
|
107 |
return indexesToCheck; |
|
|
108 |
} |
|
|
109 |
|
|
|
110 |
//Stocke les gestes du skelette pour ~3 seconds (si on prend en compte que le framerate de la Kinect |
|
|
111 |
//est de ~30 fps. |
|
|
112 |
public static void UpdateSkeletonHistory(List<Joint> latestSkeleton) |
|
|
113 |
{ |
|
|
114 |
history.Add(latestSkeleton); |
|
|
115 |
|
|
|
116 |
if (history.Count > 90) |
|
|
117 |
{ |
|
|
118 |
history.RemoveAt(0); |
|
|
119 |
} |
|
|
120 |
} |
|
|
121 |
} |
|
|
122 |
} |