aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoBoard.py8
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoCamera.py17
-rw-r--r--src/argaze/ArUcoMarkers/ArUcoMarker.py2
-rw-r--r--src/argaze/utils/tobii_camera_calibrate.py8
4 files changed, 19 insertions, 16 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoBoard.py b/src/argaze/ArUcoMarkers/ArUcoBoard.py
index f51a238..2fa3da7 100644
--- a/src/argaze/ArUcoMarkers/ArUcoBoard.py
+++ b/src/argaze/ArUcoMarkers/ArUcoBoard.py
@@ -22,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.markers)
+ self.__board = aruco.CharucoBoard((self.__columns, self.__rows), self.__square_size/100., self.__marker_size/100., self.__aruco_dict.markers)
def __del__(self):
pass
@@ -37,7 +37,7 @@ class ArUcoBoard():
def identifiers(self) -> list[int]:
"""Get board markers identifiers."""
- return self.__board.ids
+ return self.__board.getIds()
@property
def size(self)-> int:
@@ -49,7 +49,7 @@ class ArUcoBoard():
def markers_number(self) -> int:
"""Get number of markers."""
- return len(self.__board.ids)
+ return len(self.__board.getIds())
@property
def corners_number(self) -> int:
@@ -64,5 +64,5 @@ class ArUcoBoard():
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))
+ cv.imwrite(f'{destination_folder}/{output_filename}', self.__board.generateImage(dimension))
diff --git a/src/argaze/ArUcoMarkers/ArUcoCamera.py b/src/argaze/ArUcoMarkers/ArUcoCamera.py
index b2e4614..97436e9 100644
--- a/src/argaze/ArUcoMarkers/ArUcoCamera.py
+++ b/src/argaze/ArUcoMarkers/ArUcoCamera.py
@@ -2,6 +2,8 @@
from dataclasses import dataclass, field
+from argaze import DataStructures
+
import json
import numpy
import cv2.aruco as aruco
@@ -12,20 +14,20 @@ K0 = numpy.array([[1., 0., 0.], [0., 1., 0.], [0., 0., 0.]])
D0 = numpy.array([0.0, 0.0, 0.0, 0.0, 0.0])
"""Define default camera distorsion coefficients vector."""
-@dataclass(frozen=True)
+@dataclass
class CalibrationData():
"""Define optical camera calibration data."""
rms: float = field(default=0)
"""Root Mean Square error of calibration."""
- dimensions: numpy.array = field(default_factory=numpy.array([0, 0]))
+ dimensions: numpy.array = field(default_factory=lambda : numpy.array([0, 0]))
"""Frame dimensions in pixels from which the calibration have been done."""
- K: numpy.array = field(default_factory=K0)
+ K: numpy.array = field(default_factory=lambda : K0)
"""Intrinsic parameters matrix (focal lengths and principal point)."""
- D: numpy.array = field(default_factory=D0)
+ D: numpy.array = field(default_factory=lambda : D0)
"""Distorsion coefficients vector."""
@classmethod
@@ -41,7 +43,7 @@ class CalibrationData():
with open(json_filepath, 'w', encoding='utf-8') as calibration_file:
- json.dump(self, calibration_file, ensure_ascii=False, indent=4)
+ json.dump(self, calibration_file, ensure_ascii=False, indent=4, cls=DataStructures.JsonEncoder)
def __str__(self) -> str:
"""String display"""
@@ -65,13 +67,12 @@ class ArUcoCamera(CalibrationData):
self.__corners_set = []
self.__corners_set_ids = []
- def calibrate(self, board, frame_width, frame_height):
+ def calibrate(self, board):
"""Retrieve camera K and D from stored calibration data."""
if self.__corners_set_number > 0:
- self.__dimensions = [frame_width, frame_height]
- self.__rms, self.__K, self.__D, r, t = aruco.calibrateCameraCharuco(self.__corners_set, self.__corners_set_ids, board.model, self.__dimensions, None, None)
+ self.rms, self.K, self.D, r, t = aruco.calibrateCameraCharuco(self.__corners_set, self.__corners_set_ids, board.model, self.dimensions, None, None)
def reset_calibration_data(self):
"""Clear all calibration data."""
diff --git a/src/argaze/ArUcoMarkers/ArUcoMarker.py b/src/argaze/ArUcoMarkers/ArUcoMarker.py
index df82523..8f7538d 100644
--- a/src/argaze/ArUcoMarkers/ArUcoMarker.py
+++ b/src/argaze/ArUcoMarkers/ArUcoMarker.py
@@ -45,7 +45,7 @@ class ArUcoMarker():
dimension = round(self.size * dpi / 2.54) # 1 cm = 2.54 inches
matrix = numpy.zeros((dimension, dimension, 1), dtype="uint8")
- aruco.drawMarker(self.dictionary.markers, self.identifier, dimension, matrix, 1)
+ aruco.generateImageMarker(self.dictionary.markers, self.identifier, dimension, matrix, 1)
return numpy.repeat(matrix, 3).reshape(dimension, dimension, 3)
diff --git a/src/argaze/utils/tobii_camera_calibrate.py b/src/argaze/utils/tobii_camera_calibrate.py
index f19cb8b..6d682ed 100644
--- a/src/argaze/utils/tobii_camera_calibrate.py
+++ b/src/argaze/utils/tobii_camera_calibrate.py
@@ -53,7 +53,7 @@ def main():
video_width = tobii_controller.get_configuration()['sys_sc_width']
video_height = tobii_controller.get_configuration()['sys_sc_height']
- # Print current confirugration
+ # Print current confirguration
print(f'Tobii Glasses Pro 2 configuration:')
for key, value in tobii_controller.get_configuration().items():
print(f'\t{key}: {value}')
@@ -62,7 +62,9 @@ def main():
tobii_video_stream = tobii_controller.enable_video_stream()
# Create aruco camera
- aruco_camera = ArUcoCamera.ArUcoCamera()
+ aruco_camera = ArUcoCamera.ArUcoCamera(dimensions=(video_width, video_height))
+
+ print('aruco_camera.dimensions: ', aruco_camera.dimensions)
# Create aruco board
aruco_board = ArUcoBoard.ArUcoBoard(args.dictionary, args.columns, args.rows, args.square_size, args.marker_size)
@@ -124,7 +126,7 @@ def main():
tobii_controller.stop_streaming()
print('\nCalibrating camera...')
- aruco_camera.calibrate(aruco_board, video_width, video_height)
+ aruco_camera.calibrate(aruco_board)
print('\nCalibration succeeded!')
print(f'\nRMS:\n{aruco_camera.rms}')