From 08bb1e067bc02190519023810b70c08897972804 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 6 Sep 2023 08:56:58 +0200 Subject: Renaming utils scripts. --- docs/user_guide/utils/demonstrations_scripts.md | 6 +- src/argaze/utils/demo_aruco_markers_run.py | 117 ++++++++++++++++++++ src/argaze/utils/demo_augmented_reality_run.py | 114 ------------------- .../utils/demo_data/demo_aruco_markers_setup.json | 123 +++++++++++++++++++++ .../demo_data/demo_augmented_reality_setup.json | 123 --------------------- 5 files changed, 243 insertions(+), 240 deletions(-) create mode 100644 src/argaze/utils/demo_aruco_markers_run.py delete mode 100644 src/argaze/utils/demo_augmented_reality_run.py create mode 100644 src/argaze/utils/demo_data/demo_aruco_markers_setup.json delete mode 100644 src/argaze/utils/demo_data/demo_augmented_reality_setup.json diff --git a/docs/user_guide/utils/demonstrations_scripts.md b/docs/user_guide/utils/demonstrations_scripts.md index 1592115..0da09b3 100644 --- a/docs/user_guide/utils/demonstrations_scripts.md +++ b/docs/user_guide/utils/demonstrations_scripts.md @@ -17,12 +17,12 @@ Load ArFrame with a single ArLayer from **demo_gaze_analysis_setup.json** file t python ./src/argaze/utils/demo_gaze_analysis_run.py ./src/argaze/utils/demo_data/demo_gaze_analysis_setup.json ``` -## Augmented reality pipeline demonstration +## ArUco markers pipeline demonstration -Load ArCamera from **demo_augmented_reality_setup.json** file then, detect ArUco markers into a demo video source and estimate camera pose. +Load ArUcoCamera from **demo_aruco_markers_setup.json** file then, detect ArUco markers into a demo video source and estimate camera pose. ```shell -python ./src/argaze/utils/demo_augmented_reality_run.py ./src/argaze/utils/demo_data/demo_augmented_reality_setup.json -s ./src/argaze/utils/demo_data/demo.mov +python ./src/argaze/utils/demo_aruco_markers_run.py ./src/argaze/utils/demo_data/demo_aruco_markers_setup.json -s ./src/argaze/utils/demo_data/demo.mov ``` !!! note diff --git a/src/argaze/utils/demo_aruco_markers_run.py b/src/argaze/utils/demo_aruco_markers_run.py new file mode 100644 index 0000000..dd79569 --- /dev/null +++ b/src/argaze/utils/demo_aruco_markers_run.py @@ -0,0 +1,117 @@ +#!/usr/bin/env python + +"""Augmented Reality pipeline demo script.""" + +__author__ = "Théo de la Hogue" +__credits__ = [] +__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" +__license__ = "BSD" + +import argparse +import contextlib +import os +import time + +from argaze import ArFeatures, GazeFeatures +from argaze.ArUcoMarkers import ArUcoCamera + +import cv2 +import numpy + +def main(): + """ + Load ArUcoCamera from .json file, detect ArUco markers into camera device images and project it. + """ + + current_directory = os.path.dirname(os.path.abspath(__file__)) + + # Manage arguments + parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0]) + parser.add_argument('aruco_camera', metavar='ARUCO_CAMERA', type=str, help='ArUco camera filepath') + parser.add_argument('-s', '--source', metavar='SOURCE', type=str, default='0', help='video capture source (a number to select camera device or a filepath to load a movie)') + args = parser.parse_args() + + # Load ArUcoCamera + aruco_camera = ArUcoCamera.ArUcoCamera.from_json(args.aruco_camera) + + # Create a window to display ArUcoCamera + cv2.namedWindow(aruco_camera.name, cv2.WINDOW_AUTOSIZE) + + # Init timestamp + start_time = time.time() + + # Fake gaze position with mouse pointer + def on_mouse_event(event, x, y, flags, param): + + # Edit millisecond timestamp + timestamp = int((time.time() - start_time) * 1e3) + + # Project gaze position into camera + for frame, look_data in aruco_camera.look(timestamp, GazeFeatures.GazePosition((x, y))): + + # Unpack look data + if look_data: + + gaze_movement, scan_step_analysis, layer_analysis, execution_times, exception = look_data + + # Do something with look data + # ... + + # Attach mouse callback to window + cv2.setMouseCallback(aruco_camera.name, on_mouse_event) + + # Enable camera video capture into separate thread + video_capture = cv2.VideoCapture(int(args.source) if args.source.isdecimal() else args.source) + + # Waiting for 'ctrl+C' interruption + with contextlib.suppress(KeyboardInterrupt): + + # Capture images + while video_capture.isOpened(): + + # Read video image + success, video_image = video_capture.read() + + if success: + + # Detect and project AR features + detection_time, exceptions = aruco_camera.detect_and_project(video_image) + + # Get ArUcoCamera frame image + aruco_camera_image = aruco_camera.image() + + # Write detection fps + cv2.rectangle(aruco_camera_image, (0, 0), (420, 50), (63, 63, 63), -1) + cv2.putText(aruco_camera_image, f'Detection fps: {1e3/detection_time:.1f}', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) + + # Handle exceptions + for i, (scene_name, e) in enumerate(exceptions.items()): + + # Write errors + cv2.rectangle(aruco_camera_image, (0, (i+1)*50), (720, (i+2)*50), (127, 127, 127), -1) + cv2.putText(aruco_camera_image, f'{scene_name} error: {e}', (20, (i+1)*90), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA) + + # Write hint + cv2.putText(aruco_camera_image, 'Mouve mouse pointer over gray rectangle area', (450, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA) + + # Display ArUcoCamera frame image + cv2.imshow(aruco_camera.name, aruco_camera_image) + + # Draw and display each scene frames + for scene_frame in aruco_camera.scene_frames: + + # Display scene frame + cv2.imshow(f'{scene_frame.parent.name}:{scene_frame.name}', scene_frame.image()) + + # Stop by pressing 'Esc' key + if cv2.waitKey(10) == 27: + + # Close camera video capture + video_capture.release() + + # Stop image display + cv2.destroyAllWindows() + +if __name__ == '__main__': + + main() diff --git a/src/argaze/utils/demo_augmented_reality_run.py b/src/argaze/utils/demo_augmented_reality_run.py deleted file mode 100644 index c3492b3..0000000 --- a/src/argaze/utils/demo_augmented_reality_run.py +++ /dev/null @@ -1,114 +0,0 @@ -#!/usr/bin/env python - -"""Augmented Reality pipeline demo script.""" - -__author__ = "Théo de la Hogue" -__credits__ = [] -__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" -__license__ = "BSD" - -import argparse -import contextlib -import os -import time - -from argaze import ArFeatures, GazeFeatures -from argaze.ArUcoMarkers import ArUcoCamera - -import cv2 -import numpy - -def main(): - """ - Load ArUcoCamera from .json file, detect ArUco markers into camera device images and project it. - """ - - current_directory = os.path.dirname(os.path.abspath(__file__)) - - # Manage arguments - parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0]) - parser.add_argument('aruco_camera', metavar='ARUCO_CAMERA', type=str, help='ArUco camera filepath') - parser.add_argument('-s', '--source', metavar='SOURCE', type=str, default='0', help='video capture source (a number to select camera device or a filepath to load a movie)') - args = parser.parse_args() - - # Load ArUcoCamera - aruco_camera = ArUcoCamera.ArUcoCamera.from_json(args.aruco_camera) - - # Create a window to display ArUcoCamera - cv2.namedWindow(aruco_camera.name, cv2.WINDOW_AUTOSIZE) - - # Init timestamp - start_time = time.time() - - # Fake gaze position with mouse pointer - def on_mouse_event(event, x, y, flags, param): - - # Edit millisecond timestamp - timestamp = int((time.time() - start_time) * 1e3) - - # Project gaze position into camera - for frame, look_data in aruco_camera.look(timestamp, GazeFeatures.GazePosition((x, y))): - - # Unpack look data - if look_data: - - gaze_movement, scan_step_analysis, layer_analysis, execution_times, exception = look_data - - # Do something with look data - # ... - - # Attach mouse callback to window - cv2.setMouseCallback(aruco_camera.name, on_mouse_event) - - # Enable camera video capture into separate thread - video_capture = cv2.VideoCapture(int(args.source) if args.source.isdecimal() else args.source) - - # Waiting for 'ctrl+C' interruption - with contextlib.suppress(KeyboardInterrupt): - - # Capture images - while video_capture.isOpened(): - - # Read video image - success, video_image = video_capture.read() - - if success: - - # Detect and project AR features - detection_time, exceptions = aruco_camera.detect_and_project(video_image) - - # Get ArUcoCamera frame image - aruco_camera_image = aruco_camera.image() - - # Write detection fps - cv2.rectangle(aruco_camera_image, (0, 0), (420, 50), (63, 63, 63), -1) - cv2.putText(aruco_camera_image, f'Detection fps: {1e3/detection_time:.1f}', (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 1, cv2.LINE_AA) - - # Handle exceptions - for i, (scene_name, e) in enumerate(exceptions.items()): - - # Write errors - cv2.rectangle(aruco_camera_image, (0, (i+1)*50), (720, (i+2)*50), (127, 127, 127), -1) - cv2.putText(aruco_camera_image, f'{scene_name} error: {e}', (20, (i+1)*90), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 255), 1, cv2.LINE_AA) - - # Display ArUcoCamera frame image - cv2.imshow(aruco_camera.name, aruco_camera_image) - - # Draw and display each scene frames - for scene_frame in aruco_camera.scene_frames: - - # Display scene frame - cv2.imshow(f'{scene_frame.parent.name}:{scene_frame.name}', scene_frame.image()) - - # Stop by pressing 'Esc' key - if cv2.waitKey(10) == 27: - - # Close camera video capture - video_capture.release() - - # Stop image display - cv2.destroyAllWindows() - -if __name__ == '__main__': - - main() diff --git a/src/argaze/utils/demo_data/demo_aruco_markers_setup.json b/src/argaze/utils/demo_data/demo_aruco_markers_setup.json new file mode 100644 index 0000000..3511b98 --- /dev/null +++ b/src/argaze/utils/demo_data/demo_aruco_markers_setup.json @@ -0,0 +1,123 @@ +{ + "name": "ArUcoCamera Demo", + "size": [1280, 720], + "aruco_detector": { + "dictionary": { + "name": "DICT_APRILTAG_16h5" + }, + "marker_size": 5, + "optic_parameters": "optic_parameters.json", + "parameters": { + "cornerRefinementMethod": 1, + "aprilTagQuadSigma": 2, + "aprilTagDeglitch": 1 + } + }, + "layers": { + "main_layer": {} + }, + "image_parameters": { + "background_weight": 1, + "draw_layers": { + "main_layer": { + "draw_aoi_scene": { + "draw_aoi": { + "color": [255, 255, 255], + "border_size": 1 + } + } + } + }, + "draw_gaze_position": { + "color": [0, 255, 255], + "size": 4 + }, + "draw_detected_markers": { + "color": [0, 255, 0], + "draw_axes": { + "thickness": 3 + } + } + }, + "scenes": { + "ArScene Demo" : { + "aruco_markers_group": "aruco_markers_group.json", + "layers": { + "main_layer" : { + "aoi_scene": "aoi_3d_scene.obj" + } + }, + "frames": { + "GrayRectangle": { + "size": [640, 383], + "background": "frame_background.jpg", + "gaze_movement_identifier": { + "DispersionThresholdIdentification": { + "deviation_max_threshold": 25, + "duration_min_threshold": 200 + } + }, + "scan_path": { + "duration_max": 10000 + }, + "layers": { + "GrayRectangle": { + "aoi_scene": "aoi_3d_scene.obj", + "aoi_matcher": { + "FocusPointInside": {} + } + } + }, + "heatmap": { + "size": [320, 240] + }, + "image_parameters": { + "background_weight": 1, + "heatmap_weight": 0.5, + "draw_scan_path": { + "draw_fixations": { + "deviation_circle_color": [0, 255, 255], + "duration_border_color": [0, 127, 127], + "duration_factor": 1e-2 + }, + "draw_saccades": { + "line_color": [0, 255, 255] + } + }, + "draw_layers": { + "GrayRectangle": { + "draw_aoi_scene": { + "draw_aoi": { + "color": [255, 255, 255], + "border_size": 1 + } + }, + "draw_aoi_matching": { + "draw_matched_fixation": { + "deviation_circle_color": [255, 255, 255] + }, + "draw_matched_fixation_positions": { + "position_color": [0, 255, 255], + "line_color": [0, 0, 0] + }, + "draw_looked_aoi": { + "color": [0, 255, 0], + "border_size": 2 + }, + "looked_aoi_name_color": [255, 255, 255], + "looked_aoi_name_offset": [10, 10] + } + } + }, + "draw_gaze_position": { + "color": [0, 255, 255], + "size": 2 + } + } + } + }, + "angle_tolerance": 15.0, + "distance_tolerance": 2.54 + } + } +} \ No newline at end of file diff --git a/src/argaze/utils/demo_data/demo_augmented_reality_setup.json b/src/argaze/utils/demo_data/demo_augmented_reality_setup.json deleted file mode 100644 index 3511b98..0000000 --- a/src/argaze/utils/demo_data/demo_augmented_reality_setup.json +++ /dev/null @@ -1,123 +0,0 @@ -{ - "name": "ArUcoCamera Demo", - "size": [1280, 720], - "aruco_detector": { - "dictionary": { - "name": "DICT_APRILTAG_16h5" - }, - "marker_size": 5, - "optic_parameters": "optic_parameters.json", - "parameters": { - "cornerRefinementMethod": 1, - "aprilTagQuadSigma": 2, - "aprilTagDeglitch": 1 - } - }, - "layers": { - "main_layer": {} - }, - "image_parameters": { - "background_weight": 1, - "draw_layers": { - "main_layer": { - "draw_aoi_scene": { - "draw_aoi": { - "color": [255, 255, 255], - "border_size": 1 - } - } - } - }, - "draw_gaze_position": { - "color": [0, 255, 255], - "size": 4 - }, - "draw_detected_markers": { - "color": [0, 255, 0], - "draw_axes": { - "thickness": 3 - } - } - }, - "scenes": { - "ArScene Demo" : { - "aruco_markers_group": "aruco_markers_group.json", - "layers": { - "main_layer" : { - "aoi_scene": "aoi_3d_scene.obj" - } - }, - "frames": { - "GrayRectangle": { - "size": [640, 383], - "background": "frame_background.jpg", - "gaze_movement_identifier": { - "DispersionThresholdIdentification": { - "deviation_max_threshold": 25, - "duration_min_threshold": 200 - } - }, - "scan_path": { - "duration_max": 10000 - }, - "layers": { - "GrayRectangle": { - "aoi_scene": "aoi_3d_scene.obj", - "aoi_matcher": { - "FocusPointInside": {} - } - } - }, - "heatmap": { - "size": [320, 240] - }, - "image_parameters": { - "background_weight": 1, - "heatmap_weight": 0.5, - "draw_scan_path": { - "draw_fixations": { - "deviation_circle_color": [0, 255, 255], - "duration_border_color": [0, 127, 127], - "duration_factor": 1e-2 - }, - "draw_saccades": { - "line_color": [0, 255, 255] - } - }, - "draw_layers": { - "GrayRectangle": { - "draw_aoi_scene": { - "draw_aoi": { - "color": [255, 255, 255], - "border_size": 1 - } - }, - "draw_aoi_matching": { - "draw_matched_fixation": { - "deviation_circle_color": [255, 255, 255] - }, - "draw_matched_fixation_positions": { - "position_color": [0, 255, 255], - "line_color": [0, 0, 0] - }, - "draw_looked_aoi": { - "color": [0, 255, 0], - "border_size": 2 - }, - "looked_aoi_name_color": [255, 255, 255], - "looked_aoi_name_offset": [10, 10] - } - } - }, - "draw_gaze_position": { - "color": [0, 255, 255], - "size": 2 - } - } - } - }, - "angle_tolerance": 15.0, - "distance_tolerance": 2.54 - } - } -} \ No newline at end of file -- cgit v1.1