#!/usr/bin/env python from argaze.ArUcoMarkers import ArUcoMarkersDictionary import numpy import cv2 as cv import cv2.aruco as aruco class ArUcoBoard(): """Calibration chess board with ArUco markers inside.""" def __init__(self, aruco_dictionary: ArUcoMarkersDictionary.ArUcoMarkersDictionary, columns: int, rows: int, square_size: float, marker_size: float): """Create columns x rows chess board with ArUco markers at given size in centimeters.""" # Store ArUco markers dictionary self.__aruco_dict = aruco_dictionary # Store properties self.__columns = columns self.__rows = rows self.__square_size = square_size # in cm self.__marker_size = marker_size # in cm # Create board model self.__board = aruco.CharucoBoard_create(self.__columns, self.__rows, self.__square_size/100., self.__marker_size/100., self.__aruco_dict.markers) def __del__(self): pass @property def model(self) -> aruco.CharucoBoard: """Get the board model.""" return self.__board @property def identifiers(self) -> list[int]: """Get board markers identifiers.""" return self.__board.ids @property def size(self)-> int: """Get numbers of columns and rows.""" return self.__board.getChessboardSize() @property def markers_number(self) -> int: """Get number of markers.""" return len(self.__board.ids) @property def corners_number(self) -> int: """Get number of corners.""" return (self.__board.getChessboardSize()[0] - 1 ) * (self.__board.getChessboardSize()[1] - 1) def save(self, destination_folder: str, dpi: int): """Save a picture of the calibration board.""" output_filename = f'{self.__aruco_dict.name}_{self.__marker_size}cm_{self.__columns*self.__square_size}cmx{self.__rows*self.__square_size}cm.png' dimension = [round(d * self.__board.getSquareLength() * 100 * dpi / 2.54) for d in self.__board.getChessboardSize()] # 1 cm = 2.54 inches cv.imwrite(f'{destination_folder}/{output_filename}', self.__board.draw(dimension))