1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#!/usr/bin/env python
""" """
__author__ = "Théo de la Hogue"
__credits__ = []
__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)"
__license__ = "BSD"
from argaze import DataFeatures, GazeFeatures
from argaze.utils import UtilsFeatures
class FixationLogger(DataFeatures.PipelineStepObserver, UtilsFeatures.FileWriter):
def on_look(self, timestamp, frame, exception):
"""Log fixations."""
# Log fixations
if GazeFeatures.is_fixation(frame.last_gaze_movement()) and frame.last_gaze_movement().is_finished():
log = (
timestamp,
frame.last_gaze_movement().focus,
frame.last_gaze_movement().duration,
frame.layers['demo_layer'].last_looked_aoi_name()
)
self.write(log)
class ScanPathAnalysisLogger(DataFeatures.PipelineStepObserver, UtilsFeatures.FileWriter):
def on_look(self, timestamp, frame, exception):
"""Log scan path metrics."""
if frame.is_analysis_available():
log = (
timestamp,
frame.scan_path_analyzers['argaze.GazeAnalysis.Basic'].path_duration,
frame.scan_path_analyzers['argaze.GazeAnalysis.Basic'].steps_number,
frame.scan_path_analyzers['argaze.GazeAnalysis.KCoefficient'].K,
frame.scan_path_analyzers['argaze.GazeAnalysis.NearestNeighborIndex'].nearest_neighbor_index,
frame.scan_path_analyzers['argaze.GazeAnalysis.ExploreExploitRatio'].explore_exploit_ratio
)
self.write(log)
class VideoRecorder(DataFeatures.PipelineStepObserver, UtilsFeatures.VideoWriter):
def on_look(self, timestamp, frame, exception):
"""Write frame image."""
self.write(frame.image())
# Export loggers instances to register them as pipeline step object observers
__observers__ = {
"Fixation logger": FixationLogger(path="_export/logs/fixations.csv", header=("Timestamp (ms)", "Focus (px)", "Duration (ms)", "AOI")),
"Scan path analysis logger": ScanPathAnalysisLogger(path="_export/logs/scan_path_metrics.csv", header=("Timestamp (ms)", "Duration (ms)", "Step", "K", "NNI", "XXR")),
"Video recorder": VideoRecorder(path="_export/logs/video.mp4", width=1920, height=1080, fps=15)
}
|