-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_fiducial_footprints.py
38 lines (31 loc) · 1.31 KB
/
create_fiducial_footprints.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
"""Creates a silkscreen footprints with no pads, from small images.
White pixels in the image are silkscreened, and black pixels are left blank.
It's intended that the silkscreen be placed on a dark soldermask.
April tags are downloaded from: https://github.com/AprilRobotics/apriltag-imgs/tree/master/tag36h11.
"""
import cv2
import numpy as np
import requests
from tempfile import NamedTemporaryFile
from dmfwizard.kicad import write_silkscreen_footprint
# List of fiducial codes to create footprints for
FIDUCIAL_IDS = [13, 14, 15]
SIZE = 7 # mm
BORDER = 1 # px
for fid in FIDUCIAL_IDS:
tag_name = 'tag36_11_%05d' % fid
footprint_name = f'{tag_name}_%.2fmm' % SIZE
download_url = f'https://github.com/AprilRobotics/apriltag-imgs/raw/master/tag36h11/{tag_name}.png'
tempfile = NamedTemporaryFile('wb')
r = requests.get(download_url)
r.raise_for_status()
tempfile.write(r.content)
tempfile.flush()
image = cv2.imread(tempfile.name)
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
w = image.shape[1] + BORDER * 2
h = image.shape[0] + BORDER * 2
borderimage = np.ones((h, w)) * 255
borderimage[BORDER:h-BORDER, BORDER:w-BORDER] = image
pixel_size = SIZE / w
write_silkscreen_footprint(borderimage, pixel_size, footprint_name, 'PurpleDrop.pretty', "Fiducial Tag")