This repository has been archived by the owner on Aug 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
KinectRemoteControl.pde
187 lines (158 loc) · 4.48 KB
/
KinectRemoteControl.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
* KinectRemoteControl
* @author Jonathan Simon Prates (jonathan.simonprates@gmail.com)
* @version 1.0
* from SimpleOpenNI NITE Slider2d example
*/
import SimpleOpenNI.*;
Environment environment;
IRDevice device;
Recognizer recognizer;
SimpleOpenNI kinect;
XnVSessionManager sessionManager;
XnVSelectableSlider2D trackPad;
Trackpad trackPadViz;
String command;
void setup()
{
environment = new Environment(this, false);
device = new IRDevice("Onix4000");
recognizer = new Recognizer();
setupKinect();
setupTrackpad(5, 2);
}
void draw()
{
environment.update();
kinect.update();
kinect.update(sessionManager);
image(kinect.depthImage(), 0, 0, 100, 100); //tests
if (environment.getUserFocus()) {
trackPadViz.draw();
}
else {
command = recognizer.findGesture(kinect, false);
if (command != null) {
device.transmit(command);
command = null;
}
}
}
void setupKinect()
{
kinect = new SimpleOpenNI(this, SimpleOpenNI.RUN_MODE_MULTI_THREADED);
kinect.setMirror(true);
if (kinect.enableDepth() == false) {
println("Testing kinect: Can't open depth");
exit();
}
kinect.enableUser(SimpleOpenNI.SKEL_PROFILE_ALL);
if (kinect.enableRGB() == false) {
println("Testing kinect: Can't open the RGB");
exit();
}
if (kinect.enableGesture() == false) {
println("Testing kinect: Can't enable gestures");
exit();
}
if (kinect.enableHands() == false) {
println("Testing kinect: Can't enable hands");
exit();
}
sessionManager = kinect.createSessionManager("Wave", "Wave");
sessionManager.SetQuickRefocusTimeout(2000);
}
void setupTrackpad(int columns, int lines)
{
float buttonWidth = environment.screenWidth * 0.18;
float buttonHeight = environment.screenHeight * 0.18;
trackPad = new XnVSelectableSlider2D(columns, lines);
trackPad.RegisterItemHover(this);
trackPad.RegisterValueChange(this);
trackPad.RegisterItemSelect(this);
trackPad.RegisterPrimaryPointCreate(this);
trackPad.RegisterPrimaryPointDestroy(this);
trackPadViz = new Trackpad(new PVector(environment.screenWidth / 2, environment.screenHeight / 2 - 50, 0), columns, lines, (int) buttonWidth, (int) buttonHeight, 15, device);
sessionManager.AddListener(trackPad);
}
public void stop() {
environment.stop();
super.stop();
}
// NITE session callbacks
void onStartSession(PVector pos) {
environment.setUserFocus(true);
}
void onEndSession() {
environment.setUserFocus(false);
}
void onFocusSession(String strFocus, PVector pos, float progress) {
// println("onFocusSession: focus=" + strFocus + ",pos=" + pos + ",progress=" + progress);
}
// XnVSelectableSlider2D callbacks
void onValueChange(float fXValue, float fYValue) {
// println("onValueChange: fXValue=" + fXValue +" fYValue=" + fYValue);
}
void onItemHover(int nXIndex, int nYIndex)
{
//println("onItemHover: nXIndex=" + nXIndex +" nYIndex=" + nYIndex);
trackPadViz.update(nXIndex, nYIndex);
}
void onItemSelect(int nXIndex, int nYIndex, int eDir)
{
// println("onItemSelect: nXIndex=" + nXIndex + " nYIndex=" + nYIndex + " eDir=" + eDir);
trackPadViz.push(nXIndex, nYIndex, eDir);
}
void onPrimaryPointCreate(XnVHandPointContext pContext, XnPoint3D ptFocus)
{
println("onPrimaryPointCreate");
environment.setUserFocus(true);
trackPadViz.enable();
}
void onPrimaryPointDestroy(int nID)
{
println("onPrimaryPointDestroy");
environment.setUserFocus(false);
trackPadViz.disable();
}
void onNewUser(int userId)
{
println("onNewUser - userId: " + userId);
println(" start pose detection");
kinect.startPoseDetection("Psi", userId);
}
void onLostUser(int userId)
{
println("onLostUser - userId: " + userId);
}
void onStartCalibration(int userId)
{
println("onStartCalibration - userId: " + userId);
}
void onEndCalibration(int userId, boolean successfull)
{
println("onEndCalibration - userId: " + userId + ", successfull: " + successfull);
println(successfull);
if (successfull)
{
println(" User calibrated !!!");
kinect.startTrackingSkeleton(userId);
}
else
{
println(" Failed to calibrate user !!!");
println(" Start pose detection");
kinect.startPoseDetection("Psi", userId);
}
}
void onStartPose(String pose, int userId)
{
println("onStartPose - userId: " + userId + ", pose: " + pose);
println(" stop pose detection");
kinect.stopPoseDetection(userId);
kinect.requestCalibrationSkeleton(userId, true);
}
void onEndPose(String pose, int userId)
{
println("onEndPose - userId: " + userId + ", pose: " + pose);
}