aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/GazeAnalysis/FocusPointInside.py
blob: bcb77b1fafd603c586150b0d70f08612bd3fab57 (plain)
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
#!/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