forked from jdibenes/hl2ss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_stream_si.py
71 lines (54 loc) · 2.28 KB
/
client_stream_si.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
#------------------------------------------------------------------------------
# This script receives spatial input data from the HoloLens, which comprises:
# 1) Head pose, 2) Eye ray, 3) Hand tracking, and prints it. 30 Hz sample rate.
# Press esc to stop.
#------------------------------------------------------------------------------
from pynput import keyboard
import hl2ss
import hl2ss_lnm
# Settings --------------------------------------------------------------------
# HoloLens address
host = "192.168.1.7"
#------------------------------------------------------------------------------
enable = True
def on_press(key):
global enable
enable = key != keyboard.Key.esc
return enable
listener = keyboard.Listener(on_press=on_press)
listener.start()
client = hl2ss_lnm.rx_si(host, hl2ss.StreamPort.SPATIAL_INPUT)
client.open()
while (enable):
data = client.get_next_packet()
si = hl2ss.unpack_si(data.payload)
print(f'Tracking status at time {data.timestamp}')
if (si.is_valid_head_pose()):
head_pose = si.get_head_pose()
print(f'Head pose: Position={head_pose.position} Forward={head_pose.forward} Up={head_pose.up}')
# right = cross(up, -forward)
# up => y, forward => -z, right => x
else:
print('No head pose data')
if (si.is_valid_eye_ray()):
eye_ray = si.get_eye_ray()
print(f'Eye ray: Origin={eye_ray.origin} Direction={eye_ray.direction}')
else:
print('No eye tracking data')
# See
# https://learn.microsoft.com/en-us/uwp/api/windows.perception.people.jointpose?view=winrt-22621
# for hand data details
if (si.is_valid_hand_left()):
hand_left = si.get_hand_left()
pose = hand_left.get_joint_pose(hl2ss.SI_HandJointKind.Wrist)
print(f'Left wrist pose: Position={pose.position} Orientation={pose.orientation} Radius={pose.radius} Accuracy={pose.accuracy}')
else:
print('No left hand data')
if (si.is_valid_hand_right()):
hand_right = si.get_hand_right()
pose = hand_right.get_joint_pose(hl2ss.SI_HandJointKind.Wrist)
print(f'Right wrist pose: Position={pose.position} Orientation={pose.orientation} Radius={pose.radius} Accuracy={pose.accuracy}')
else:
print('No right hand data')
client.close()
listener.join()