-
Notifications
You must be signed in to change notification settings - Fork 0
/
cctv.py
43 lines (34 loc) · 859 Bytes
/
cctv.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
import time
import sys
from viewer import viewer
from utils import bytes_to_rgb, bgr_weights
from stream import stream_client, unpack
import numpy as np
host = 'localhost'
port = 5556
if len(sys.argv)>1:
host = sys.argv[1]
if len(sys.argv)>2:
port = sys.argv[2]
client = stream_client(host=host, port=port)
view = viewer()
i,t1,t = 0,0,0
t0 = time.time()
print('Stream from: ', client.addr)
while True:
msg = client.receive()
if msg:
data = unpack(msg)
if data['type'] == 'bgr':
frame = bytes_to_rgb(data['data'], data['size'])
#frame = np.uint8(np.dot(frame, bgr_weights))
elif data['type'] == 'grayscale':
frame = np.frombuffer(data['data'], dtype=np.uint8).reshape(data['size'])
else:
frame = []
view.show(frame)
i += 1
t1 = time.time()
t += t1-t0
t0 = t1
print('fps', int((i+1)/t), end='\r', flush=True)