"""Calibration chess board with ArUco markers inside. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . """ __author__ = "Théo de la Hogue" __credits__ = [] __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" __license__ = "GPLv3" from dataclasses import dataclass, field from argaze.ArUcoMarkers import ArUcoMarkersDictionary import numpy import cv2 as cv import cv2.aruco as aruco @dataclass class ArUcoBoard(): """ """ columns: int = field(default=0) """Number of columns.""" rows: int = field(default=0) """Number of rows.""" square_size: float = field(default=0.) """Size of board square in centimeter.""" marker_size: float = field(default=0.) """Size of ArUco markers inside board squares in centimeter.""" dictionary: ArUcoMarkersDictionary.ArUcoMarkersDictionary = field(default_factory=ArUcoMarkersDictionary.ArUcoMarkersDictionary) """ArUco markers dictionary.""" def __post_init__(self): # Create board model self.model = aruco.CharucoBoard((self.columns, self.rows), self.square_size/100., self.marker_size/100., self.dictionary.markers) @property def identifiers(self) -> list[int]: """Get board markers identifiers.""" return self.model.getIds() @property def size(self)-> int: """Get numbers of columns and rows.""" return self.model.getChessboardSize() @property def markers_number(self) -> int: """Get number of markers.""" return len(self.model.getIds()) @property def corners_number(self) -> int: """Get number of corners.""" return (self.model.getChessboardSize()[0] - 1 ) * (self.model.getChessboardSize()[1] - 1) def save(self, filepath: str, dpi: int): """Save calibration board picture at a given resolution.""" dimension = [round(d * self.model.getSquareLength() * 100 * dpi / 2.54) for d in self.model.getChessboardSize()] # 1 cm = 2.54 inches cv.imwrite(filepath, self.model.generateImage(dimension))