-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzn.py
More file actions
36 lines (31 loc) · 895 Bytes
/
zn.py
File metadata and controls
36 lines (31 loc) · 895 Bytes
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
import numpy as np
import zmq
import struct
dtype_map = { 0: np.uint8, 1: np.int8,
2: np.uint16, 3: np.int16,
4: np.int32, 5: np.float32,
6: np.float64
}
depth_map = { 2: 0, # uint8
1: 1, # int8
4: 2, # uint16
3: 3, # int16
5: 4, # int32
11: 5, # float32
12: 6 # float64
}
def send(sock, frame):
shape = frame.shape
meta=struct.pack('iiii', depth_map[frame.dtype.num], shape[0], shape[1], shape[2])
sock.send(meta, zmq.SNDMORE)
sock.send(frame)
def recv(sock):
data = sock.recv()
meta=struct.unpack('iiii', data)
dtype = dtype_map[meta[0]]
shape0 = meta[1]
shape1 = meta[2]
shape2 = meta[3]
data = sock.recv(zmq.RCVMORE)
frame = np.fromstring(data, dtype=dtype).reshape(shape0, shape1, shape2)
return frame