From 99421d660869b0795ed4f2e2303f0dd95ebce3da Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Mon, 8 Jul 2024 09:46:24 +0200 Subject: Moving LookPerformanceRecorder and WatchPerformanceRecorder into UtilsFeatures file. --- src/argaze/utils/UtilsFeatures.py | 55 +++++++++++++++++++++++ src/argaze/utils/demo/aruco_markers_pipeline.json | 4 +- src/argaze/utils/demo/gaze_analysis_pipeline.json | 2 +- src/argaze/utils/demo/recorders.py | 50 --------------------- 4 files changed, 58 insertions(+), 53 deletions(-) (limited to 'src') diff --git a/src/argaze/utils/UtilsFeatures.py b/src/argaze/utils/UtilsFeatures.py index 23d6b24..ce92e35 100644 --- a/src/argaze/utils/UtilsFeatures.py +++ b/src/argaze/utils/UtilsFeatures.py @@ -23,6 +23,7 @@ import time import csv import types import traceback +import logging from argaze import DataFeatures @@ -433,3 +434,57 @@ class VideoWriter(DataFeatures.PipelineStepObject, DataFeatures.SharedObject): output = cv2.resize(image, dsize=(self.__width, self.__height), interpolation=cv2.INTER_LINEAR) self.__process.stdin.write(output.tobytes()) + + +class LookPerformanceRecorder(FileWriter): + """Record look method performance into a CSV file.""" + + def __init__(self, **kwargs): + + super().__init__(**kwargs) + + self.header = "Timestamp (ms)", "Time (ms)", "Frequency (Hz)" + + self.__start_time = time.perf_counter() + + logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path) + + def on_look(self, timestamp, frame, exception): + """Log frame look execution performance.""" + + t, f = frame.execution_info('look') + + log = ( + (time.perf_counter() - self.__start_time) * 1e3, + t * 1e3, + f + ) + + self.write(log) + + +class WatchPerformanceRecorder(FileWriter): + """Record watch method performance into a CSV file.""" + + def __init__(self, **kwargs): + + super().__init__(**kwargs) + + self.header = "Timestamp (ms)", "Time (ms)", "Frequency (Hz)" + + self.__start_time = time.perf_counter() + + logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path) + + def on_watch(self, timestamp, camera, exception): + """Log camera watch execution performance.""" + + t, f = camera.execution_info('watch') + + log = ( + (time.perf_counter() - self.__start_time) * 1e3, + t * 1e3, + f + ) + + self.write(log) \ No newline at end of file diff --git a/src/argaze/utils/demo/aruco_markers_pipeline.json b/src/argaze/utils/demo/aruco_markers_pipeline.json index 86da9bc..f29111b 100644 --- a/src/argaze/utils/demo/aruco_markers_pipeline.json +++ b/src/argaze/utils/demo/aruco_markers_pipeline.json @@ -122,10 +122,10 @@ } }, "observers": { - "recorders.LookPerformanceRecorder": { + "argaze.utils.UtilsFeatures.LookPerformanceRecorder": { "path": "_export/records/look_performance.csv" }, - "recorders.WatchPerformanceRecorder": { + "argaze.utils.UtilsFeatures.WatchPerformanceRecorder": { "path": "_export/records/watch_performance.csv" } } diff --git a/src/argaze/utils/demo/gaze_analysis_pipeline.json b/src/argaze/utils/demo/gaze_analysis_pipeline.json index 768e2c1..8b8212e 100644 --- a/src/argaze/utils/demo/gaze_analysis_pipeline.json +++ b/src/argaze/utils/demo/gaze_analysis_pipeline.json @@ -115,7 +115,7 @@ } }, "observers": { - "recorders.LookPerformanceRecorder": { + "argaze.utils.UtilsFeatures.LookPerformanceRecorder": { "path": "_export/records/look_performance.csv" }, "recorders.FixationRecorder": { diff --git a/src/argaze/utils/demo/recorders.py b/src/argaze/utils/demo/recorders.py index 6295c8f..82022ce 100644 --- a/src/argaze/utils/demo/recorders.py +++ b/src/argaze/utils/demo/recorders.py @@ -25,56 +25,6 @@ from argaze import DataFeatures, GazeFeatures from argaze.ArUcoMarker import ArUcoMarkerGroup from argaze.utils import UtilsFeatures -class LookPerformanceRecorder(UtilsFeatures.FileWriter): - - def __init__(self, **kwargs): - - super().__init__(**kwargs) - - self.header = "Timestamp (ms)", "Time (ms)", "Frequency (Hz)" - - self.__start_time = time.perf_counter() - - logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path) - - def on_look(self, timestamp, frame, exception): - """Log frame look execution performance.""" - - t, f = frame.execution_info('look') - - log = ( - (time.perf_counter() - self.__start_time) * 1e3, - t * 1e3, - f - ) - - self.write(log) - -class WatchPerformanceRecorder(UtilsFeatures.FileWriter): - - def __init__(self, **kwargs): - - super().__init__(**kwargs) - - self.header = "Timestamp (ms)", "Time (ms)", "Frequency (Hz)" - - self.__start_time = time.perf_counter() - - logging.info('%s writes into %s', DataFeatures.get_class_path(self), self.path) - - def on_watch(self, timestamp, camera, exception): - """Log camera watch execution performance.""" - - t, f = camera.execution_info('watch') - - log = ( - (time.perf_counter() - self.__start_time) * 1e3, - t * 1e3, - f - ) - - self.write(log) - class FixationRecorder(UtilsFeatures.FileWriter): def __init__(self, **kwargs): -- cgit v1.1