-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathclient.py
More file actions
91 lines (66 loc) · 2.35 KB
/
Copy pathclient.py
File metadata and controls
91 lines (66 loc) · 2.35 KB
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
"""
Walk-Assistant : Recognizing sidewalk for the visually impaired
Copyright (C) 2018 Yoongi Kim (devlifecode@outlook.com)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
print("""
Walk-Assistant Copyright (C) 2018 Yoongi Kim
This program comes with ABSOLUTELY NO WARRANTY.
This is free software, and you are welcome to redistribute it
under certain conditions.
""")
import requests
import json
import cv2
import base64
import numpy as np
img_file = 'data/test2.jpg'
addr = 'http://127.0.0.1'
test_url = addr + '/predict'
WIDTH = 1280
HEIGHT = 720
def encode_image(img):
_, img_encoded = cv2.imencode('.jpg', img)
b64 = base64.b64encode(img_encoded)
return b64
def decode_result(s):
arr = []
rows = str(s).split('\n')
for row in rows:
cols = row.split(',')
cols_parse = []
for col in cols:
cols_parse.append(float(col))
arr.append(cols_parse)
return np.array(arr, dtype=np.float32)
def render(img, res):
res *= 255
res = res.astype(np.uint8)
res = cv2.cvtColor(res, cv2.COLOR_GRAY2BGR) # to white color
res[:, :, 0] = 0 # remove blue channel
res[:, :, 2] = 0 # remove red channel
res = cv2.resize(res, (WIDTH, HEIGHT), interpolation=cv2.INTER_LINEAR) # resize 15x8 to 1280x720
org = cv2.resize(img, (WIDTH, HEIGHT))
added = cv2.add(org, res) # combine input, output
cv2.imshow('result', added)
cv2.waitKey(0)
# if cv2.waitKey(1) & 0xFF == ord('q'):
# print('User Interrupted')
# exit(1)
if __name__ == '__main__':
img = cv2.imread(img_file)
encode = encode_image(img)
response = requests.post(test_url, data={"img": encode})
result = json.loads(response.text)['result']
print(result)
result = decode_result(result)
render(img, result)