diff options
Diffstat (limited to 'src/argaze/ArUcoMarkers/ArUcoMarkers.py')
-rw-r--r-- | src/argaze/ArUcoMarkers/ArUcoMarkers.py | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoMarkers.py b/src/argaze/ArUcoMarkers/ArUcoMarkers.py new file mode 100644 index 0000000..1499218 --- /dev/null +++ b/src/argaze/ArUcoMarkers/ArUcoMarkers.py @@ -0,0 +1,71 @@ +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 ArUcoMarkers(): + + # initialisation + def __init__(self, aruco_dictionary_name): + + # 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]) + + # destruction + def __del__(self): + pass + + # save one marker + def export(self, destination_folder, dpi, i): + + if i >= 0 and i < self.__aruco_dict_number: + + output_filename = f'marker_{self.__aruco_dict_format}_{i}.png' + + # create marker + marker = numpy.zeros((dpi, dpi, 1), dtype="uint8") + aruco.drawMarker(self.__aruco_dict, i, dpi, marker, 1) + + # save marker into destination folder + cv.imwrite(f'{destination_folder}/{output_filename}', marker) + + else: + raise ValueError(f'Bad ArUco index: {i}') + + # save all markers + def export_all(self, destination_folder, dpi): + + for i in range(self.__aruco_dict_number): + + self.export(destination_folder, dpi, i) + + |