-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathhelpers.py
91 lines (85 loc) · 3.09 KB
/
helpers.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import cv2
import numpy as np
def stack_images(scale, images):
rows = len(images)
cols = len(images[0])
rowsAvailable = isinstance(images[0], list)
width = images[0][0].shape[1]
height = images[0][0].shape[0]
if rowsAvailable:
for x in range(0, rows):
for y in range(0, cols):
if images[x][y].shape[:2] == images[0][0].shape[:2]:
images[x][y] = cv2.resize(images[x][y], (0, 0), None, scale, scale)
else:
images[x][y] = cv2.resize(
images[x][y],
(images[0][0].shape[1], images[0][0].shape[0]),
None,
scale,
scale,
)
if len(images[x][y].shape) == 2:
images[x][y] = cv2.cvtColor(images[x][y], cv2.COLOR_GRAY2BGR)
imageBlank = np.zeros((height, width, 3), np.uint8)
hor = [imageBlank] * rows
for x in range(0, rows):
hor[x] = np.hstack(images[x])
ver = np.vstack(hor)
else:
for x in range(0, rows):
if images[x].shape[:2] == images[0].shape[:2]:
images[x] = cv2.resize(images[x], (0, 0), None, scale, scale)
else:
images[x] = cv2.resize(
images[x],
(images[0].shape[1], images[0].shape[0]),
None,
scale,
scale,
)
if len(images[x].shape) == 2:
images[x] = cv2.cvtColor(images[x], cv2.COLOR_GRAY2BGR)
hor = np.hstack(images)
ver = hor
return ver
def new_coordinates_resize(original_size, new_size, original_coordinate):
original_size = np.array(original_size)
new_size = np.array(new_size)
original_coordinate = np.array(original_coordinate)
xy = original_coordinate / (original_size / new_size)
x, y = int(xy[0]), int(xy[1])
x = x if x > 0 else 0
y = y if y > 0 else 0
return np.array([x, y], dtype=np.uint16)
def setup_resolution(size_each_camera_image, resize_all_camera_image, total_cam):
if total_cam % 2 == 0:
return stack_images(
resize_all_camera_image,
(
[
np.random.randint(
0, 255, size=(*size_each_camera_image, 3), dtype=np.uint8
)
for _ in range(0, total_cam // 2)
],
[
np.random.randint(
0, 255, size=(*size_each_camera_image, 3), dtype=np.uint8
)
for _ in range(total_cam // 2, total_cam)
],
),
).shape[:2]
else:
return stack_images(
resize_all_camera_image,
(
[
np.random.randint(
0, 255, size=(*size_each_camera_image, 3), dtype=np.uint8
)
for _ in range(total_cam)
],
),
).shape[:2]