-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate_aruco_textures.py
34 lines (29 loc) · 1.04 KB
/
generate_aruco_textures.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
import os
import cv2
from cv2 import aruco
dicts_to_generate = {
aruco.DICT_4X4_50: ("4X4_50", 50, 4),
aruco.DICT_5X5_100: ("5X5_100", 100, 5),
}
white_border = 1
script_dir = os.path.dirname(__file__)
textures_dir = f"{script_dir}/Assets/Simulation/ArUco/Textures"
# Generate all possible markers and save them to ./Textures/{dict_name}/{id}.png
for dict_id, (dict_name, dict_size, marker_size) in dicts_to_generate.items():
aruco_dict = aruco.getPredefinedDictionary(dict_id)
out_dir = f"{textures_dir}/{dict_name}"
os.makedirs(out_dir, exist_ok=True)
for i in range(dict_size):
marker = aruco.generateImageMarker(aruco_dict, i, marker_size + 2)
# Add white border
marker = cv2.copyMakeBorder(
marker,
white_border,
white_border,
white_border,
white_border,
cv2.BORDER_CONSTANT,
value=[255, 255, 255],
)
cv2.imwrite(f"{out_dir}/{i}.png", marker)
print(f"Generated marker {i} from dictionary {dict_name}")