-
Notifications
You must be signed in to change notification settings - Fork 12
/
tile_test.py
71 lines (56 loc) · 2.04 KB
/
tile_test.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
"""
Walk-Assistant : Recognizing sidewalk for the visually impaired
Copyright (C) 2018 Yoongi Kim ([email protected])
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 cv2
import numpy as np
import matplotlib.pyplot as plt
from model import MyModel
def brighter(img, multiply, max_value):
for i in range(len(img)):
for j in range(len(img[i])):
img[i][j] = min(img[i][j]*multiply, max_value)
return img
bgr = cv2.imread('data/test1.jpg')
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
rgb = np.array(rgb)
X = np.array([rgb / 255.0])
model = MyModel(True, 720, 1280, 80, 80, 1e-6, 'main')
res = model.model.predict(X, 1)[0]
res = np.squeeze(res[:,:,1])
res = brighter(res, 2.0, 1.0)
probs = res.flatten()
print(res)
tiles = []
for i in range(0, 720, 80):
for j in range(0, 1280, 80):
tiles.append(rgb[i:i+80, j:j+80])
for index, tile in enumerate(tiles):
# plt.imshow(tile)
# plt.show()
plt.imsave('data/tiles/%d_%.2f.jpg'%(index, probs[index]), tile)
visual = res*255.0
visual = np.array(cv2.resize(visual, (1280, 720))).astype(np.uint8)
visual = cv2.cvtColor(visual, cv2.COLOR_GRAY2BGR)
visual[:,:,0] = 0
visual[:,:,2] = 0
visual = cv2.add(bgr, visual)
cv2.imshow('visual', visual)
cv2.imwrite('data/result_test1.jpg', visual)
cv2.waitKey(0)