aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/ArUcoMarkers/ArUcoBoard.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/argaze/ArUcoMarkers/ArUcoBoard.py')
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoBoard.py49
1 files changed, 14 insertions, 35 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoBoard.py b/src/argaze/ArUcoMarkers/ArUcoBoard.py
index ce4abd8..de50363 100644
--- a/src/argaze/ArUcoMarkers/ArUcoBoard.py
+++ b/src/argaze/ArUcoMarkers/ArUcoBoard.py
@@ -1,47 +1,19 @@
#!/usr/bin/env python
+from argaze.ArUcoMarkers import ArUcoMarkersDictionary
+
import numpy
import cv2 as cv
import cv2.aruco as aruco
-# Built-in ArUco dictionaries from OpenCV library
-ARUCO_DICT = {
- 'DICT_4X4_50': aruco.DICT_4X4_50,
- 'DICT_4X4_100': aruco.DICT_4X4_100,
- 'DICT_4X4_250': aruco.DICT_4X4_250,
- 'DICT_4X4_1000': aruco.DICT_4X4_1000,
- 'DICT_5X5_50': aruco.DICT_5X5_50,
- 'DICT_5X5_100': aruco.DICT_5X5_100,
- 'DICT_5X5_250': aruco.DICT_5X5_250,
- 'DICT_5X5_1000': aruco.DICT_5X5_1000,
- 'DICT_6X6_50': aruco.DICT_6X6_50,
- 'DICT_6X6_100': aruco.DICT_6X6_100,
- 'DICT_6X6_250': aruco.DICT_6X6_250,
- 'DICT_6X6_1000': aruco.DICT_6X6_1000,
- 'DICT_7X7_50': aruco.DICT_7X7_50,
- 'DICT_7X7_100': aruco.DICT_7X7_100,
- 'DICT_7X7_250': aruco.DICT_7X7_250,
- 'DICT_7X7_1000': aruco.DICT_7X7_1000,
- 'DICT_ARUCO_ORIGINAL': aruco.DICT_ARUCO_ORIGINAL
-}
-
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."""
- # check aruco dictionary name
- if ARUCO_DICT.get(aruco_dictionary_name, None) is None:
- raise NameError(f'Bad ArUco dictionnary name: {aruco_dictionary_name}')
-
- dict_name_split = aruco_dictionary_name.split('_')
-
- self.__aruco_dict_format = dict_name_split[1]
- self.__aruco_dict_number = int(dict_name_split[2])
-
- # load ArUco dictionary
- self.__aruco_dict = aruco.Dictionary_get(ARUCO_DICT[aruco_dictionary_name])
+ # load ArUco markers dictionary
+ self.__aruco_dict = ArUcoMarkersDictionary.ArUcoMarkersDictionary(aruco_dictionary_name)
# store property
self.__columns = columns
@@ -50,7 +22,7 @@ class ArUcoBoard():
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)
+ 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
@@ -65,13 +37,20 @@ class ArUcoBoard():
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_format}_{self.__marker_size}cm.png'
+ 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