-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_vis.py
294 lines (207 loc) · 9.52 KB
/
test_vis.py
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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
if len(sys.argv)>1:
#graphic mode
import numpy as np
from nite2 import *
import time
# Test code -- print head coordinates of users
NiTE.initialize()
tracker = UserTracker()
tracker.create()
def USER_MESSAGE(m):
print m
g_visibleUsers={}
g_skeletonStates={}
def updateUserState( user, ts):
if user.isNew():
USER_MESSAGE("New")
elif (user.isVisible() and not g_visibleUsers[user.getId()]):
USER_MESSAGE("Visible")
elif (not user.isVisible() and g_visibleUsers[user.getId()]):
USER_MESSAGE("Out of Scene")
elif (user.isLost()):
USER_MESSAGE("Lost")
g_visibleUsers[user.getId()] = user.isVisible();
#if (g_skeletonStates[user.getId()] != user.getSkeleton().getState()):
#switch(g_skeletonStates[user.getId()] = user.getSkeleton().getState())
#{
#case nite::SKELETON_NONE:
#USER_MESSAGE("Stopped tracking.")
#break;
#case nite::SKELETON_CALIBRATING:
#USER_MESSAGE("Calibrating...")
#break;
#case nite::SKELETON_TRACKED:
#USER_MESSAGE("Tracking!")
#break;
#case nite::SKELETON_CALIBRATION_ERROR_NOT_IN_POSE:
#case nite::SKELETON_CALIBRATION_ERROR_HANDS:
#case nite::SKELETON_CALIBRATION_ERROR_LEGS:
#case nite::SKELETON_CALIBRATION_ERROR_HEAD:
#case nite::SKELETON_CALIBRATION_ERROR_TORSO:
#USER_MESSAGE("Calibration Failed... :-|")
#break;
#}
#}
#}
import numpy as np
import matplotlib.pyplot as plt
import mpl_toolkits.mplot3d.axes3d as p3
import matplotlib.animation as animation
import matplotlib
matplotlib.pyplot.autoscale(enable=True, axis='both', tight=None)
import random
fig = plt.figure()
ax = p3.Axes3D(fig)
# Fifty lines of random 3-D lines
data = [i for i in range(50)]
# Creating fifty line objects.
# NOTE: Can't pass empty arrays into 3d version of plot()
# Setting the axes properties
ax.set_xlim3d([-600, 100])
ax.set_xlabel('X')
ax.set_ylim3d([-1000, 1000])
ax.set_ylabel('Y')
ax.set_zlim3d([200, 3500])
ax.set_zlabel('Z')
ax.set_title('3D Test')
# line, = ax.plot([0,10],[0,10], [0,10])
def animate(i):
lims=list(ax.get_xlim3d())+list(ax.get_ylim3d())+list(ax.get_zlim3d())
lines=[]
f = tracker.readFrame()
users=f.getUsers()
#print users
for uid in users:
user = f.getUserById(uid)
uid=user.getId()
updateUserState(user, f.getTimestamp());
if user.isNew():
print("New user id %d !" % uid)
tracker.startSkeletonTracking(uid)
elif user.getSkeleton().getState() == SkeletonState.SKELETON_TRACKED:
skel=user.getSkeleton()
#for atr in ['JOINT_HEAD',
#'JOINT_LEFT_HAND','JOINT_RIGHT_HAND',
#'JOINT_TORSO',
#'JOINT_LEFT_FOOT','JOINT_RIGHT_FOOT']:
#joint=skel.getJoint(getattr(JointType,atr))
#pos=joint.getPosition()
#lims=[ min(pos[0], lims[0]), max(pos[0], lims[1]),
#min(pos[1], lims[2]), max(pos[1], lims[3]),
#min(pos[2], lims[4]), max(pos[2], lims[5])]
#lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'ro')[0])
#'b' blue
#'g' green
#'r' red
#'c' cyan
#'m' magenta
#'y' yellow
#'k' black
#'w' white
head = user.getSkeleton().getJoint(JointType.JOINT_HEAD)
pos=head.getPosition()
lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'bo')[0])
head = user.getSkeleton().getJoint(JointType.JOINT_LEFT_HAND)
pos=head.getPosition()
lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'go')[0])
head = user.getSkeleton().getJoint(JointType.JOINT_RIGHT_HAND)
pos=head.getPosition()
lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'ro')[0])
head = user.getSkeleton().getJoint(JointType.JOINT_TORSO)
pos=head.getPosition()
lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'ko')[0])
#head = user.getSkeleton().getJoint(JointType.JOINT_HEAD)
#pos=head.getPosition()
#lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'bo')[0])
head = user.getSkeleton().getJoint(JointType.JOINT_LEFT_FOOT)
pos=head.getPosition()
lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'co')[0])
head = user.getSkeleton().getJoint(JointType.JOINT_RIGHT_FOOT)
pos=head.getPosition()
lines.append(ax.plot([ pos[0]],[ pos[1]],[ pos[2]], 'yo')[0])
print("User {} : {}".format(uid, pos))
#lines.append(ax.plot([0, pos[0]],[0, pos[1]],[0, pos[2]])[0])
print user.getSkeleton().getState()
#line,=ax.plot([0,random.randint(0,10)],[0,random.randint(0,10)],[0,random.randint(0,10)])
#line2,=ax.plot([0,random.randint(0,10)],[0,random.randint(0,10)],[0,random.randint(0,10)])
ax.clear()
#ax.set_xlim3d([lims[0], lims[1]])
#ax.set_ylim3d([lims[2], lims[3]])
#ax.set_zlim3d([lims[4], lims[5]])
# line.set_ydata(random.randint(0,10))
# line.set_xdata([random.randint(0,10), random.randint(0,10)])
# line.set_ydata( [random.randint(0,10),random.randint(0,10)])
return lines
ani = animation.FuncAnimation(fig, animate, np.arange(1, 10), interval=20, blit=True)
plt.show()
sys.exit()
#console mode
import numpy as np
from nite2 import *
import time
# Test code -- print head coordinates of users
NiTE.initialize()
tracker = UserTracker()
tracker.create()
def USER_MESSAGE(m):
print m
g_visibleUsers={}
g_skeletonStates={}
def updateUserState( user, ts):
if user.isNew():
USER_MESSAGE("New")
elif (user.isVisible() and not g_visibleUsers[user.getId()]):
USER_MESSAGE("Visible")
elif (not user.isVisible() and g_visibleUsers[user.getId()]):
USER_MESSAGE("Out of Scene")
elif (user.isLost()):
USER_MESSAGE("Lost")
g_visibleUsers[user.getId()] = user.isVisible();
#if (g_skeletonStates[user.getId()] != user.getSkeleton().getState()):
#switch(g_skeletonStates[user.getId()] = user.getSkeleton().getState())
#{
#case nite::SKELETON_NONE:
#USER_MESSAGE("Stopped tracking.")
#break;
#case nite::SKELETON_CALIBRATING:
#USER_MESSAGE("Calibrating...")
#break;
#case nite::SKELETON_TRACKED:
#USER_MESSAGE("Tracking!")
#break;
#case nite::SKELETON_CALIBRATION_ERROR_NOT_IN_POSE:
#case nite::SKELETON_CALIBRATION_ERROR_HANDS:
#case nite::SKELETON_CALIBRATION_ERROR_LEGS:
#case nite::SKELETON_CALIBRATION_ERROR_HEAD:
#case nite::SKELETON_CALIBRATION_ERROR_TORSO:
#USER_MESSAGE("Calibration Failed... :-|")
#break;
#}
#}
#}
while(True):
f = tracker.readFrame()
users=f.getUsers()
#print users
for uid in users:
user = f.getUserById(uid)
uid=user.getId()
updateUserState(user, f.getTimestamp());
if user.isNew():
print("New user id %d !" % uid)
tracker.startSkeletonTracking(uid)
elif user.getSkeleton().getState() == SkeletonState.SKELETON_TRACKED:
head = user.getSkeleton().getJoint(JointType.JOINT_HEAD)
rhand = user.getSkeleton().getJoint(JointType.JOINT_RIGHT_HAND)
print [head.getPosition(), rhand.getPosition()]
print("User {} : {}".format(uid, head.getPosition()))
print user.getSkeleton().getState()
#else:
#if user.isVisible():
#head = user.getSkeleton().getJoint(JointType.JOINT_HEAD)
#print("User {} : {}".format(uid, head.getPosition()))
tracker.destroy()
NiTE.shutdown()