-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclient.py
74 lines (62 loc) · 2.85 KB
/
client.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
import socket
from xml.etree.ElementInclude import DEFAULT_MAX_INCLUSION_DEPTH
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
from tqdm import tqdm
HOST = "nano3-4904-frc" # The server's hostname or IP address. This needs to be constantly updated
PORT = 8324 # The port used by the server
address = (HOST, PORT)
should_show_image = True
while True:
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.connect(address)
s.sendall(b"Hello, world")
beginning_buffer = b""
with tqdm(leave=False) as pbar:
while True:
bytes_in = b""
while True:
data = s.recv(1024)
bytes_in = bytes_in+data
# print(type(image))
# print(type(image[-1]))
# If end
if b'ThisIsAnEndToken' in bytes_in:
bytes_in = bytes_in.replace(b'ThisIsAnEndToken', b'')
break
# print("recieved bytes of", len(bytes_in), type(bytes_in))
# image = bytes(image)
# image = list(image)
# print(len(image))
# print(type(image))
# should_show_image = not should_show_image
if not should_show_image:
continue
np_jpeg = np.frombuffer(bytes_in, dtype='uint8')
# print('got jpg image of len', len(np_jpeg))
img_rec = cv.imdecode(np_jpeg, cv.IMREAD_GRAYSCALE)
if img_rec is None: continue
# print('got image of shape', img_rec.shape)
# crosshairs
# img_rec //= 2
# img_rec[img_rec.shape[0]//2, :] = 255
# img_rec[img_rec.shape[0]//2+1, :] = 0
img_rec[:, img_rec.shape[1]//2] = 255
img_rec[:, img_rec.shape[1]//2+1] = 0
def draw_tick(img_rec, ypos, xratio):
left_bound = int(img_rec.shape[0] * xratio/2)
right_bound = int(img_rec.shape[0] * (1-xratio/2))
img_rec[left_bound:right_bound, int(img_rec.shape[1] * (0.5 - ypos/2))] = 255
img_rec[left_bound:right_bound, int(img_rec.shape[1] * (0.5 - ypos/2))+1] = 0
img_rec[left_bound:right_bound, int(img_rec.shape[1] * (0.5 + ypos/2))] = 255
img_rec[left_bound:right_bound, int(img_rec.shape[1] * (0.5 + ypos/2))+1] = 0
return img_rec
img_rec = draw_tick(img_rec, 0.2, 1/4)
img_rec = draw_tick(img_rec, 0.4, 1/3)
# plt.imshow(img_rec)
# plt.show()
pbar.update()
cv.imshow("frame", img_rec)
if cv.waitKey(1) == ord('q'):
break