From 59b55607ff2d118a748a3343befd5e246a5dbd46 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Thu, 14 Apr 2022 00:44:03 +0200 Subject: Allowing to track only a list of markers. Replacing roi by aoi. --- src/argaze/TobiiGlassesPro2/TobiiData.py | 12 +++++++++--- src/argaze/TobiiGlassesPro2/TobiiEntities.py | 2 +- src/argaze/utils/README.md | 16 ++++++++-------- src/argaze/utils/export_tobii_segment_aruco_aois.py | 18 +++++++++++++++--- src/argaze/utils/live_tobii_aruco_aois.py | 16 ++++++++++++++-- 5 files changed, 47 insertions(+), 17 deletions(-) diff --git a/src/argaze/TobiiGlassesPro2/TobiiData.py b/src/argaze/TobiiGlassesPro2/TobiiData.py index 8024fa2..bcd2264 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiData.py +++ b/src/argaze/TobiiGlassesPro2/TobiiData.py @@ -37,8 +37,11 @@ class TobiiDataSegment(DataStructures.DictObject): ts -= self.__first_ts # ignore timestamps out of the given time range - if ts < start_timestamp or ts >= end_timestamp: - return + if ts < start_timestamp: + return True # continue + + if ts >= end_timestamp: + return False # stop # convert json data into data object data_object_type = '_'.join(json_data.keys()) @@ -51,11 +54,14 @@ class TobiiDataSegment(DataStructures.DictObject): # store data object into the timestamped buffer dedicated to its type ts_data_buffer_dict[data_object.get_type()][ts] = data_object + return True # continue + # start loading with gzip.open(self.__segment_data_path) as f: for item in f: - json.loads(item.decode('utf-8'), object_hook=decode) + if not json.loads(item.decode('utf-8'), object_hook=decode): + break super().__init__(type(self).__name__, **ts_data_buffer_dict) diff --git a/src/argaze/TobiiGlassesPro2/TobiiEntities.py b/src/argaze/TobiiGlassesPro2/TobiiEntities.py index 17cd29f..ea4994d 100644 --- a/src/argaze/TobiiGlassesPro2/TobiiEntities.py +++ b/src/argaze/TobiiGlassesPro2/TobiiEntities.py @@ -43,7 +43,7 @@ class TobiiSegment: raise RuntimeError(f'JSON fails to load {self.__segment_path}/{TOBII_SEGMENT_INFO_FILENAME}') self.__start_timestamp = start_timestamp - self.__end_timestamp = min(end_timestamp, int(item["seg_length_us"])) if end_timestamp != None else int(item["seg_length_us"]) + self.__end_timestamp = min(end_timestamp, int(item["seg_length"] * 1000000)) if end_timestamp != None else int(item["seg_length"] * 1000000) if self.__start_timestamp >= self.__end_timestamp: raise ValueError('start time is equal or greater than end time.') diff --git a/src/argaze/utils/README.md b/src/argaze/utils/README.md index 8e5341c..03dd7ec 100644 --- a/src/argaze/utils/README.md +++ b/src/argaze/utils/README.md @@ -60,26 +60,26 @@ python ./src/argaze/utils/explore_tobii_sdcard.py -r RECORDING_PATH python ./src/argaze/utils/explore_tobii_sdcard.py -s SEGMENT_PATH ``` -- Replay a Tobii Glasses Pro 2 session (replace SEGMENT_PATH) synchronizing video and data together. +- Replay a time range selection (replace IN OUT) Tobii Glasses Pro 2 session (replace SEGMENT_PATH) synchronizing video and data together. ``` -python ./src/argaze/utils/replay_tobii_session.py -s SEGMENT_PATH +python ./src/argaze/utils/replay_tobii_session.py -s SEGMENT_PATH -r IN OUT ``` -- Export Tobii segment fixations (replace SEGMENT_PATH) into a fixations.json file into the segment folder +- Export Tobii segment fixations (replace SEGMENT_PATH) from a time range selection (replace IN OUT) as a fixations.json file saved into the segment folder ``` -python ./src/argaze/utils/export_tobii_segment_fixations.py -s SEGMENT_PATH +python ./src/argaze/utils/export_tobii_segment_fixations.py -s SEGMENT_PATH -r IN OUT ``` -- Track ArUco markers into a Tobii camera video segment (replace SEGMENT_PATH). Load an roi scene (replace AOI_SCENE) .obj file, position it virtually relatively to any detected ArUco markers and project the scene into camera frame. Then, detect if Tobii gaze point is inside any AOI. Export AOIs video and data. +- Track ArUco markerinto a Tobii camera video segment (replace SEGMENT_PATH) into a time range selection (replace IN OUT). Load an aoi scene (replace AOI_SCENE) .obj file, position it virtually relatively to any detected ArUco markers and project the scene into camera frame. Then, detect if Tobii gaze point is inside any AOI. Export AOIs video and data. ``` -python ./src/argaze/utils/export_tobii_segment_aruco_aois.py -s SEGMENT_PATH -c export/tobii_camera.json -m 7.5 -a AOI_SCENE +python ./src/argaze/utils/export_tobii_segment_aruco_aois.py -s SEGMENT_PATH -c export/tobii_camera.json -m 7.5 -a AOI_SCENE -r IN OUT ``` -- Track ArUco markers into Tobii camera video stream (replace IP_ADDRESS). Load an roi scene (replace AOI_SCENE) .obj file, position it virtually relatively to any detected ArUco markers and project the scene into camera frame. Then, detect if Tobii gaze point is inside any AOI. +- Track ArUco markers (replace MARKER_ID) into Tobii camera video stream (replace IP_ADDRESS). Load an aoi scene (replace AOI_SCENE) .obj file, position it virtually relatively to any detected ArUco markers and project the scene into camera frame. Then, detect if Tobii gaze point is inside any AOI. ``` -python ./src/argaze/utils/live_tobii_aruco_aois.py -t IP_ADDRESS -c export/tobii_camera.json -m 7.5 -a AOI_SCENE +python ./src/argaze/utils/live_tobii_aruco_aois.py -t IP_ADDRESS -c export/tobii_camera.json -m 7.5 -a AOI_SCENE -i MARKER_ID ``` diff --git a/src/argaze/utils/export_tobii_segment_aruco_aois.py b/src/argaze/utils/export_tobii_segment_aruco_aois.py index f833111..004805e 100644 --- a/src/argaze/utils/export_tobii_segment_aruco_aois.py +++ b/src/argaze/utils/export_tobii_segment_aruco_aois.py @@ -28,14 +28,21 @@ def main(): parser.add_argument('-s', '--segment_path', metavar='SEGMENT_PATH', type=str, default=None, help='segment path') parser.add_argument('-r', '--time_range', metavar=('START_TIME', 'END_TIME'), nargs=2, type=float, default=(0., None), help='start and end time (in second)') parser.add_argument('-c', '--camera_calibration', metavar='CAM_CALIB', type=str, default='tobii_camera.json', help='json camera calibration filepath') - parser.add_argument('-a', '--roi_scene', metavar='AOI_SCENE', type=str, default='aoi3D_scene.obj', help='obj roi scene filepath') + parser.add_argument('-a', '--aoi_scene', metavar='AOI_SCENE', type=str, default='aoi3D_scene.obj', help='obj aoi scene filepath') parser.add_argument('-d', '--dictionary', metavar='DICT', type=str, default='DICT_ARUCO_ORIGINAL', help='aruco marker dictionnary') - parser.add_argument('-m', '--marker_size', metavar='MKR', type=float, default=6, help='aruco marker size (cm)') + parser.add_argument('-m', '--marker_size', metavar='MARKER_SIZE', type=float, default=6, help='aruco marker size (cm)') + parser.add_argument('-i', '--markers_id', metavar='MARKERS_ID', nargs='*', type=int, default=[], help='markers id to track') parser.add_argument('-o', '--output', metavar='OUT', type=str, default=None, help='destination folder path (segment folder by default)') args = parser.parse_args() if args.segment_path != None: + empty_marker_set = len(args.markers_id) == 0 + if empty_marker_set: + print(f'Track any Aruco markers from the {args.dictionary} dictionary') + else: + print(f'Track Aruco markers {args.markers_id} from the {args.dictionary} dictionary') + # Manage destination path if args.output != None: @@ -79,7 +86,7 @@ def main(): # Create AOIs 3D scene aoi3D_scene = AOI3DScene.AOI3DScene() - aoi3D_scene.load(args.roi_scene) + aoi3D_scene.load(args.aoi_scene) print(f'AOIs names: {aoi3D_scene.keys()[2::]}') # Create Timestamped buffer to store 2D AOIs @@ -119,6 +126,11 @@ def main(): # TODO : Select different 3D scenes depending on aruco id + in_marker_set = marker_id in list(args.markers_id) + + if not empty_marker_set and not in_marker_set: + continue + marker_rotation = aruco_tracker.get_marker_rotation(i) marker_translation = aruco_tracker.get_marker_translation(i) diff --git a/src/argaze/utils/live_tobii_aruco_aois.py b/src/argaze/utils/live_tobii_aruco_aois.py index 51c244c..6e0e005 100644 --- a/src/argaze/utils/live_tobii_aruco_aois.py +++ b/src/argaze/utils/live_tobii_aruco_aois.py @@ -23,11 +23,18 @@ def main(): parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0]) parser.add_argument('-t', '--tobii_ip', metavar='TOBII_IP', type=str, default='192.168.1.10', help='tobii glasses ip') parser.add_argument('-c', '--camera_calibration', metavar='CAM_CALIB', type=str, default='tobii_camera.json', help='json camera calibration filepath') - parser.add_argument('-r', '--roi_scene', metavar='AOI_SCENE', type=str, default='aoi3D_scene.obj', help='obj roi scene filepath') + parser.add_argument('-a', '--aoi_scene', metavar='AOI_SCENE', type=str, default='aoi3D_scene.obj', help='obj aoi scene filepath') parser.add_argument('-d', '--dictionary', metavar='DICT', type=str, default='DICT_ARUCO_ORIGINAL', help='aruco marker dictionnary') parser.add_argument('-m', '--marker_size', metavar='MKR', type=float, default=6, help='aruco marker size (cm)') + parser.add_argument('-i', '--markers_id', metavar='MARKERS_ID', nargs='*', type=int, default=[], help='markers id to track') args = parser.parse_args() + empty_marker_set = len(args.markers_id) == 0 + if empty_marker_set: + print(f'Track any Aruco markers from the {args.dictionary} dictionary') + else: + print(f'Track Aruco markers {args.markers_id} from the {args.dictionary} dictionary') + # Create tobii controller tobii_controller = TobiiController.TobiiController(args.tobii_ip, 'myProject', 'mySelf') @@ -49,7 +56,7 @@ def main(): # Create AOIs 3D scene aoi3D_scene = AOI3DScene.AOI3DScene() - aoi3D_scene.load(args.roi_scene) + aoi3D_scene.load(args.aoi_scene) # Start streaming tobii_controller.start_streaming() @@ -93,6 +100,11 @@ def main(): for (i, marker_id) in enumerate(aruco_tracker.get_markers_ids()): # TODO : Select different 3D scenes depending on aruco id + + in_marker_set = marker_id in list(args.markers_id) + + if not empty_marker_set and not in_marker_set: + continue marker_rotation = aruco_tracker.get_marker_rotation(i) marker_translation = aruco_tracker.get_marker_translation(i) -- cgit v1.1