import cv2
import numpy as np

# ---- Board parameters (CHANGE THESE ONLY IF YOU REPRINT) ----
squares_x = 4        # number of chessboard squares in X
squares_y = 5        # number of chessboard squares in Y
square_length = 50  # mm
marker_length = 36  # mm (must be < square_length)
dictionary_id = cv2.aruco.DICT_4X4_50
dpi = 300            # print DPI
# ------------------------------------------------------------

dictionary = cv2.aruco.getPredefinedDictionary(dictionary_id)
board = cv2.aruco.CharucoBoard(
    (squares_x, squares_y),
    square_length,
    marker_length,
    dictionary
)

# Convert physical size (mm) to pixels for printing
mm_to_inch = 1 / 25.4
width_mm = squares_x * square_length
height_mm = squares_y * square_length

width_px = int(width_mm * mm_to_inch * dpi)
height_px = int(height_mm * mm_to_inch * dpi)

img = board.generateImage((width_px, height_px))
img = 255 - img
cv2.imwrite("H:\Table\charuco_A4.png", img)
print("Saved charuco_A4.png")