forked from jdibenes/hl2ss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_stream_rm_depth_ahat.py
94 lines (76 loc) · 2.95 KB
/
client_stream_rm_depth_ahat.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
#------------------------------------------------------------------------------
# This script receives video from the HoloLens depth camera in ahat mode and
# plays it. The resolution is 512x512 @ 45 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.
# See https://github.com/jdibenes/hl2ss/tree/main/extensions before setting
# profile_z to hl2ss.DepthProfile.ZDEPTH (lossless* compression).
#------------------------------------------------------------------------------
from pynput import keyboard
import numpy as np
import cv2
import hl2ss_imshow
import hl2ss
import hl2ss_lnm
# Settings --------------------------------------------------------------------
# HoloLens address
host = "192.169.1.41"
# 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
# Depth encoding profile
# SAME: use same compression as AB
# AB RAW:
# - data streamed as-is (most accurate)
# - very low framerate (uncompressed)
# AB H264/H265:
# - reduced depth resolution (from 1mm to 4mm)
# - noisy due to lossy video compression
# - full framerate
# ZDEPTH: use ZDepth lossless* compression
# - increased minimum range (objects close to the camera get truncated)
# - full framerate
# - requires building the pyzdepth extension (one time only)
profile_z = hl2ss.DepthProfile.SAME
# AB encoding profile
profile_ab = hl2ss.VideoProfile.H265_MAIN
#------------------------------------------------------------------------------
if (mode == hl2ss.StreamMode.MODE_2):
data = hl2ss_lnm.download_calibration_rm_depth_ahat(host, hl2ss.StreamPort.RM_DEPTH_AHAT)
print('Calibration data')
print('Image point to unit plane')
print(data.uv2xy)
print('Extrinsics')
print(data.extrinsics)
print(f'Scale: {data.scale}')
print(f'Alias: {data.alias}')
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_ahat(host, hl2ss.StreamPort.RM_DEPTH_AHAT, mode=mode, divisor=divisor, profile_z=profile_z, profile_ab=profile_ab)
client.open()
while (enable):
data = client.get_next_packet()
print(f'Pose at time {data.timestamp}')
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()