Skip to content

Instantly share code, notes, and snippets.

@CGCooke
Created February 8, 2021 14:35
Show Gist options
  • Save CGCooke/673129366806b7f3ade511ea9a5b1718 to your computer and use it in GitHub Desktop.
Save CGCooke/673129366806b7f3ade511ea9a5b1718 to your computer and use it in GitHub Desktop.
import numpy as np
import cv2
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
# load the ArUCo dictionary
arucoDict = cv2.aruco.Dictionary_get(cv2.aruco.DICT_4X4_50)
dpi = 100
width = 15*0.393701 #15cm
height = width #15cm
pixels = int(width*dpi)
with PdfPages('Tag_Book.pdf') as pdf:
for tag_number in range(0,50):
tag = np.zeros((pixels, pixels, 1), dtype="uint8")
cv2.aruco.drawMarker(arucoDict, tag_number, pixels, tag, 1);
fig = plt.figure(figsize=(width, height), dpi=dpi)
ax = fig.add_axes([0, 0, 1, 1], frameon=False, aspect=1)
ax.imshow(tag,cmap='gray', extent=[0,1,0,1], interpolation="nearest")
ax.set_xticks([])
ax.set_yticks([])
text = (f'Tag #{tag_number}, DICT_4X4_50' )
ax.text(0.02,0.02, text, color="white", fontsize=12, alpha=0.5)
pdf.savefig() # saves the current figure into a pdf page
plt.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment