From e8009b32ab280abc87490d8f6d88007848abcde7 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Wed, 23 Aug 2023 15:54:58 +0200 Subject: Adding new FocusPointInside AOI matching algorithm. --- src/argaze/GazeAnalysis/FocusPointInside.py | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/argaze/GazeAnalysis/FocusPointInside.py (limited to 'src') diff --git a/src/argaze/GazeAnalysis/FocusPointInside.py b/src/argaze/GazeAnalysis/FocusPointInside.py new file mode 100644 index 0000000..bcb77b1 --- /dev/null +++ b/src/argaze/GazeAnalysis/FocusPointInside.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +"""Matching algorithm based on fixation's focus point +""" + +__author__ = "Théo de la Hogue" +__credits__ = [] +__copyright__ = "Copyright 2023, Ecole Nationale de l'Aviation Civile (ENAC)" +__license__ = "BSD" + +from typing import TypeVar, Tuple +from dataclasses import dataclass, field +import math + +from argaze import GazeFeatures + +import numpy +import cv2 + +GazeMovementType = TypeVar('GazeMovement', bound="GazeMovement") +# Type definition for type annotation convenience + +@dataclass +class AOIMatcher(GazeFeatures.AOIMatcher): + + def __post_init__(self): + """Init looked aoi data.""" + + self.__looked_aoi = None + + def match(self, aoi_scene, gaze_movement, exclude=[]) -> str: + """Returns AOI containing fixation focus point.""" + + if GazeFeatures.is_fixation(gaze_movement): + + for name, aoi in aoi_scene.items(): + + if name not in exclude and aoi.contains_point(gaze_movement.focus): + + # Update looked aoi + self.__looked_aoi = name + + return self.__looked_aoi + + elif GazeFeatures.is_saccade(gaze_movement): + + self.__post_init__() + + @property + def looked_aoi(self) -> str: + """Get most likely looked aoi name for current fixation (e.g. the aoi with the highest coverage mean value)""" + + return self.__looked_aoi -- cgit v1.1