-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathviewer.py
40 lines (33 loc) · 1.17 KB
/
viewer.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
import cv2
import zmq
import argparse
import numpy as np
#matplotlib.use('TkAgg')
from spect import graph
import datetime
args = argparse.ArgumentParser()
args.add_argument("-i", "--ip", type=str, default="192.168.1.99",
help="ip address of the server to which the client will connect")
args.add_argument("-p", "--port", type=str, default="5555",
help="port number of the server to which the client will connect")
args = vars(args.parse_args())
context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.bind('tcp://' + args["ip"] + ':' + args["port"])
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode_(''))
while True:
try:
frame = footage_socket.recv()
npimg = np.frombuffer(frame, dtype=np.uint8)
source = cv2.imdecode(npimg, 1)
cv2.imshow("Stream", source)
k=cv2.waitKey(1)
if k%256==27:
break
elif k%256 == 32:
img_name="samples/{}.png".format(datetime.datetime.now().strftime("%A-%H.%M.%S"))
cv2.imwrite(img_name,source)
graph(img_name)
except KeyboardInterrupt:
cv2.destroyAllWindows()
break