forked from jdibenes/hl2ss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_stream_rm_depth_longthrow.py
75 lines (59 loc) · 2.22 KB
/
client_stream_rm_depth_longthrow.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
#------------------------------------------------------------------------------
# This script receives video from the HoloLens depth camera in long throw mode
# and plays it. The resolution is 320x288 @ 5 FPS. The stream supports three
# operating modes: 0) video, 1) video + rig pose, 2) query calibration (single
# transfer). Depth and AB data are scaled for visibility. The ahat and long
# throw streams cannot be used simultaneously.
# Press esc to stop.
#------------------------------------------------------------------------------
from pynput import keyboard
import numpy as np
import cv2
import hl2ss_imshow
import hl2ss
import hl2ss_lnm
# Settings --------------------------------------------------------------------
# HoloLens address
host = "192.168.1.7"
# Operating mode
# 0: video
# 1: video + rig pose
# 2: query calibration (single transfer)
mode = hl2ss.StreamMode.MODE_1
# Framerate denominator (must be > 0)
# Effective framerate is framerate / divisor
divisor = 1
#------------------------------------------------------------------------------
if (mode == hl2ss.StreamMode.MODE_2):
data = hl2ss_lnm.download_calibration_rm_depth_longthrow(host, hl2ss.StreamPort.RM_DEPTH_LONGTHROW)
print('Calibration data')
print('Image point to unit plane')
print(data.uv2xy)
print('Extrinsics')
print(data.extrinsics)
print(f'Scale: {data.scale}')
print('Undistort map')
print(data.undistort_map)
print('Intrinsics (undistorted only)')
print(data.intrinsics)
quit()
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_rm_depth_longthrow(host, hl2ss.StreamPort.RM_DEPTH_LONGTHROW, mode=mode, divisor=divisor)
client.open()
while (enable):
data = client.get_next_packet()
print(f'Frame captured at {data.timestamp}')
print(f'Sensor Ticks: {data.payload.sensor_ticks}')
print(f'Pose')
print(data.pose)
cv2.imshow('Depth', data.payload.depth / np.max(data.payload.depth)) # Scaled for visibility
cv2.imshow('AB', data.payload.ab / np.max(data.payload.ab)) # Scaled for visibility
cv2.waitKey(1)
client.close()
listener.join()