diff options
Diffstat (limited to 'src/argaze/ArUcoMarkers/ArUcoCamera.py')
-rw-r--r-- | src/argaze/ArUcoMarkers/ArUcoCamera.py | 47 |
1 files changed, 22 insertions, 25 deletions
diff --git a/src/argaze/ArUcoMarkers/ArUcoCamera.py b/src/argaze/ArUcoMarkers/ArUcoCamera.py index 93a0b8f..bf4e5d3 100644 --- a/src/argaze/ArUcoMarkers/ArUcoCamera.py +++ b/src/argaze/ArUcoMarkers/ArUcoCamera.py @@ -16,22 +16,18 @@ __credits__ = [] __copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" __license__ = "GPLv3" -from typing import Self import logging -import json -import os -import time - -from argaze import ArFeatures, DataFeatures -from argaze.ArUcoMarkers import ArUcoMarkersDictionary, ArUcoDetector, ArUcoOpticCalibrator, ArUcoScene -from argaze.AreaOfInterest import AOI2DScene import cv2 import numpy -# Define default ArUcoCamera image_paremeters values +from argaze import ArFeatures, DataFeatures +from argaze.ArUcoMarkers import ArUcoDetector, ArUcoOpticCalibrator, ArUcoScene +from argaze.AreaOfInterest import AOI2DScene + +# Define default ArUcoCamera image_parameters values DEFAULT_ARUCOCAMERA_IMAGE_PARAMETERS = { - "draw_detected_markers": { + "draw_detected_markers": { "color": (0, 255, 0), "draw_axes": { "thickness": 3 @@ -39,6 +35,7 @@ DEFAULT_ARUCOCAMERA_IMAGE_PARAMETERS = { } } + class ArUcoCamera(ArFeatures.ArCamera): """ Define an ArCamera based on ArUco marker detection. @@ -57,7 +54,7 @@ class ArUcoCamera(ArFeatures.ArCamera): # Init protected attributes self._image_parameters = {**ArFeatures.DEFAULT_ARFRAME_IMAGE_PARAMETERS, **DEFAULT_ARUCOCAMERA_IMAGE_PARAMETERS} - + @property def aruco_detector(self) -> ArUcoDetector.ArUcoDetector: """ArUco marker detector.""" @@ -74,26 +71,30 @@ class ArUcoCamera(ArFeatures.ArCamera): # Optic parameters dimensions should be equal to camera frame size if self.__aruco_detector.optic_parameters.dimensions != self.size: - - raise DataFeatures.PipelineStepLoadingFaile('ArUcoCamera: aruco_detector.optic_parameters.dimensions have to be equal to size.') + raise DataFeatures.PipelineStepLoadingFaile( + 'ArUcoCamera: aruco_detector.optic_parameters.dimensions have to be equal to size.') # No optic parameters loaded else: # Create default optic parameters adapted to frame size # Note: The choice of 1000 for default focal length should be discussed... - self.__aruco_detector.optic_parameters = ArUcoOpticCalibrator.OpticParameters(rms=-1, dimensions=self.size, K=ArUcoOpticCalibrator.K0(focal_length=(1000., 1000.), width=self.size[0], height=self.size[1])) + self.__aruco_detector.optic_parameters = ArUcoOpticCalibrator.OpticParameters(rms=-1, dimensions=self.size, + K=ArUcoOpticCalibrator.K0( + focal_length=( + 1000., 1000.), + width=self.size[0], + height=self.size[1])) # Edit parent if self.__aruco_detector is not None: - self.__aruco_detector.parent = self @property def sides_mask(self) -> int: """Size of mask (pixel) to hide video left and right sides.""" return self.__sides_mask - + @sides_mask.setter def sides_mask(self, size: int): @@ -106,12 +107,10 @@ class ArUcoCamera(ArFeatures.ArCamera): self._scenes = {} for scene_name, scene_data in scenes.items(): - - self._scenes[scene_name] = ArUcoScene.ArUcoScene(name = scene_name, **scene_data) + self._scenes[scene_name] = ArUcoScene.ArUcoScene(name=scene_name, **scene_data) # Edit parent for name, scene in self._scenes.items(): - scene.parent = self # Update expected and excluded aoi @@ -128,7 +127,6 @@ class ArUcoCamera(ArFeatures.ArCamera): # Draw black rectangles to mask sides if self.__sides_mask > 0: - logging.debug('\t> drawing sides mask (%i px)', self.__sides_mask) height, width, _ = image.shape @@ -178,7 +176,8 @@ class ArUcoCamera(ArFeatures.ArCamera): tvec, rmat, _ = scene.estimate_pose(self.__aruco_detector.detected_markers(), timestamp=self.timestamp) # Project scene into camera frame according estimated pose - for layer_name, layer_projection in scene.project(tvec, rmat, self.visual_hfov, self.visual_vfov, timestamp=self.timestamp): + for layer_name, layer_projection in scene.project(tvec, rmat, self.visual_hfov, self.visual_vfov, + timestamp=self.timestamp): logging.debug('\t> project %s scene %s layer', scene_name, layer_name) @@ -195,7 +194,8 @@ class ArUcoCamera(ArFeatures.ArCamera): pass @DataFeatures.PipelineStepImage - def image(self, draw_detected_markers: dict = None, draw_scenes: dict = None, draw_optic_parameters_grid: dict = None, **kwargs: dict) -> numpy.array: + def image(self, draw_detected_markers: dict = None, draw_scenes: dict = None, + draw_optic_parameters_grid: dict = None, **kwargs: dict) -> numpy.array: """Get frame image with ArUco detection visualisation. Parameters: @@ -216,7 +216,6 @@ class ArUcoCamera(ArFeatures.ArCamera): # Draw optic parameters grid if required if draw_optic_parameters_grid is not None: - logging.debug('\t> drawing optic parameters') self.__aruco_detector.optic_parameters.draw(image, **draw_optic_parameters_grid) @@ -225,14 +224,12 @@ class ArUcoCamera(ArFeatures.ArCamera): if draw_scenes is not None: for scene_name, draw_scenes_parameters in draw_scenes.items(): - logging.debug('\t> drawing %s scene', scene_name) self.scenes[scene_name].draw(image, **draw_scenes_parameters) # Draw detected markers if required if draw_detected_markers is not None: - logging.debug('\t> drawing detected markers') self.__aruco_detector.draw_detected_markers(image, draw_detected_markers) |