#!/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_name: str, columns: int, rows: int, square_size: float, marker_size: float): """Create columnsxrows chess board with ArUco markers type at given sizes in centimeters.""" # load ArUco markers dictionary self.__aruco_dict = ArUcoMarkersDictionary.ArUcoMarkersDictionary(aruco_dictionary_name) # store property 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.get_markers()) def __del__(self): pass def get_model(self): """Get the board model.""" return self.__board def get_ids(self): """Get board markers ids.""" return self.__board.ids def get_size(self): """Get numbers of columns and rows.""" return self.__board.getChessboardSize() def get_markers_number(self): """Get number of markers.""" return len(self.__board.ids) def get_corners_number(self): """Get number of corners.""" return (self.__board.getChessboardSize()[0] - 1 ) * (self.__board.getChessboardSize()[1] - 1) def export(self, destination_folder: str, dpi: int): """Save a picture of the calibration board.""" output_filename = f'board_{self.__columns*self.__square_size}cmx{self.__rows*self.__square_size}cm_markers_{self.__aruco_dict.get_markers_format()}_{self.__marker_size}cm.png' dimension = [int(e * self.__board.getSquareLength() * 254 * dpi) for e in self.__board.getChessboardSize()] # 1 meter = 254 inches cv.imwrite(f'{destination_folder}/{output_filename}', self.__board.draw(dimension))