diff options
author | Théo de la Hogue | 2024-06-27 21:20:41 +0200 |
---|---|---|
committer | Théo de la Hogue | 2024-06-27 21:20:41 +0200 |
commit | 284c2b12c2e6cd987414618b71d9ac244857bb9e (patch) | |
tree | dcabdcbd924af36f4b734276c4eeca46567ed315 | |
parent | 46ec14351ab21e74e80651e3ae7fd9e41572bbba (diff) | |
download | argaze-284c2b12c2e6cd987414618b71d9ac244857bb9e.zip argaze-284c2b12c2e6cd987414618b71d9ac244857bb9e.tar.gz argaze-284c2b12c2e6cd987414618b71d9ac244857bb9e.tar.bz2 argaze-284c2b12c2e6cd987414618b71d9ac244857bb9e.tar.xz |
Moving pose estimation outside of demo folder.
-rw-r--r-- | src/argaze/__main__.py | 7 | ||||
-rw-r--r-- | src/argaze/utils/demo/recorders.py | 60 | ||||
-rw-r--r-- | src/argaze/utils/estimate_markers_pose/context.json | 7 | ||||
-rw-r--r-- | src/argaze/utils/estimate_markers_pose/observers.py | 82 | ||||
-rw-r--r-- | src/argaze/utils/estimate_markers_pose/pipeline.json | 33 |
5 files changed, 187 insertions, 2 deletions
diff --git a/src/argaze/__main__.py b/src/argaze/__main__.py index f9433c0..77875a8 100644 --- a/src/argaze/__main__.py +++ b/src/argaze/__main__.py @@ -62,7 +62,10 @@ def load_context(args): cv2.rectangle(image, (int(width/4), int(height/3)), (int(width*3/4), int(height*2/3)), (127, 127, 127), -1) info_stack = 1 - cv2.putText(image, f'Help', (int(width/4)+20, int(height/3)+(info_stack*40)), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) + cv2.putText(image, f'HELP', (int(width/4)+20, int(height/3)+(info_stack*40)), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) + + # Blanck line + info_stack += 1 if issubclass(type(context), LiveProcessingContext): @@ -75,7 +78,7 @@ def load_context(args): if issubclass(type(context), PostProcessingContext): info_stack += 1 - cv2.putText(image, f'Press Space bar to pause/resume processing', (int(width/3)+20, int(height/3)+(info_stack*40)), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) + cv2.putText(image, f'Press Space bar to pause/resume processing', (int(width/4)+20, int(height/3)+(info_stack*40)), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) info_stack += 1 cv2.putText(image, f'Press f to pause/resume visualisation', (int(width/4)+20, int(height/3)+(info_stack*40)), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) diff --git a/src/argaze/utils/demo/recorders.py b/src/argaze/utils/demo/recorders.py index 63a2fa2..6295c8f 100644 --- a/src/argaze/utils/demo/recorders.py +++ b/src/argaze/utils/demo/recorders.py @@ -19,8 +19,10 @@ __license__ = "GPLv3" import logging import time +import pathlib from argaze import DataFeatures, GazeFeatures +from argaze.ArUcoMarker import ArUcoMarkerGroup from argaze.utils import UtilsFeatures class LookPerformanceRecorder(UtilsFeatures.FileWriter): @@ -165,3 +167,61 @@ class AOIScanPathAnalysisRecorder(UtilsFeatures.FileWriter): ) self.write(log) + + +class ArUcoMarkersPoseRecorder(DataFeatures.PipelineStepObject): + + @DataFeatures.PipelineStepInit + def __init__(self, **kwargs): + + # Init private attributes + self.__output_folder = None + self.__size = None + + @property + def output_folder(self) -> str: + """folder path where to write ArUco markers pose.""" + return self.__output_folder + + @output_folder.setter + def output_folder(self, output_folder: str): + + self.__output_folder = output_folder + + @property + def size(self) -> float: + """Expected size in centimeters of detected markers.""" + return self.__output_folder + + @size.setter + def size(self, size: float): + + self.__size = size + + @property + def ids(self) -> list: + """Ids of markers to estimate pose (default all).""" + return self.__ids + + @ids.setter + def ids(self, ids: list): + + self.__ids = ids + + def on_detect_markers(self, timestamp, aruco_detector, exception): + + logging.info('%s writes estimated markers pose into %s', DataFeatures.get_class_path(self), self.__output_folder) + + if self.__size is not None: + + # Estimate all detected markers pose + aruco_detector.estimate_markers_pose(self.__size, ids = self.__ids) + + # Build ArUco markers group from detected markers + aruco_markers_group = ArUcoMarkerGroup.ArUcoMarkerGroup(dictionary=aruco_detector.dictionary, places=aruco_detector.detected_markers()) + + if self.__output_folder is not None: + + # Write ArUco markers group + aruco_markers_group.to_obj(f'{self.__output_folder}/{int(timestamp)}-aruco_markers_group.obj') +
\ No newline at end of file diff --git a/src/argaze/utils/estimate_markers_pose/context.json b/src/argaze/utils/estimate_markers_pose/context.json new file mode 100644 index 0000000..ecb3066 --- /dev/null +++ b/src/argaze/utils/estimate_markers_pose/context.json @@ -0,0 +1,7 @@ +{ + "argaze.utils.contexts.OpenCV.Movie" : { + "name": "ArUco markers pose estimator", + "path": "./src/argaze/utils/demo/tobii_record/segments/1/fullstream.mp4", + "pipeline": "pipeline.json" + } +}
\ No newline at end of file diff --git a/src/argaze/utils/estimate_markers_pose/observers.py b/src/argaze/utils/estimate_markers_pose/observers.py new file mode 100644 index 0000000..23316ca --- /dev/null +++ b/src/argaze/utils/estimate_markers_pose/observers.py @@ -0,0 +1,82 @@ +""" """ + +""" +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 <https://www.gnu.org/licenses/>. +""" + +__author__ = "Théo de la Hogue" +__credits__ = [] +__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" +__license__ = "GPLv3" + +import logging + +from argaze import DataFeatures +from argaze.ArUcoMarker import ArUcoMarkerGroup + + +class ArUcoMarkersPoseRecorder(DataFeatures.PipelineStepObject): + + @DataFeatures.PipelineStepInit + def __init__(self, **kwargs): + + # Init private attributes + self.__output_folder = None + self.__size = None + self.__ids = None + + @property + def output_folder(self) -> str: + """folder path where to write ArUco markers pose.""" + return self.__output_folder + + @output_folder.setter + def output_folder(self, output_folder: str): + + self.__output_folder = output_folder + + @property + def size(self) -> float: + """Expected size in centimeters of detected markers.""" + return self.__output_folder + + @size.setter + def size(self, size: float): + + self.__size = size + + @property + def ids(self) -> list: + """Ids of markers to estimate pose (default all).""" + return self.__ids + + @ids.setter + def ids(self, ids: list): + + self.__ids = ids + + def on_detect_markers(self, timestamp, aruco_detector, exception): + + logging.info('%s writes estimated markers pose into %s', DataFeatures.get_class_path(self), self.__output_folder) + + if self.__size is not None: + + # Estimate all detected markers pose + aruco_detector.estimate_markers_pose(self.__size, ids = self.__ids) + + # Build ArUco markers group from detected markers + aruco_markers_group = ArUcoMarkerGroup.ArUcoMarkerGroup(dictionary=aruco_detector.dictionary, places=aruco_detector.detected_markers()) + + if self.__output_folder is not None: + + # Write ArUco markers group + aruco_markers_group.to_obj(f'{self.__output_folder}/{int(timestamp)}-aruco_markers_group.obj') +
\ No newline at end of file diff --git a/src/argaze/utils/estimate_markers_pose/pipeline.json b/src/argaze/utils/estimate_markers_pose/pipeline.json new file mode 100644 index 0000000..c3034e8 --- /dev/null +++ b/src/argaze/utils/estimate_markers_pose/pipeline.json @@ -0,0 +1,33 @@ +{ + "argaze.ArUcoMarker.ArUcoCamera.ArUcoCamera": { + "name": "Full HD Camera", + "size": [1920, 1080], + "aruco_detector": { + "dictionary": "DICT_APRILTAG_16h5", + "parameters": { + "useAruco3Detection": 1 + }, + "observers":{ + "observers.ArUcoMarkersPoseRecorder": { + "output_folder": "_export/records/aruco_markers_group", + "size": 4, + "ids": [] + } + } + }, + "sides_mask": 420, + "image_parameters": { + "background_weight": 1, + "draw_gaze_positions": { + "color": [0, 255, 255], + "size": 4 + }, + "draw_detected_markers": { + "color": [255, 255, 255], + "draw_axes": { + "thickness": 4 + } + } + } + } +}
\ No newline at end of file |