blob: 8856bec16d1ec3883dabb16090d52b5a3953fb4d (
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
Gaze position
=============
[GazeFeatures](../../../argaze/#argaze.GazeFeatures) defines a [GazePosition](../../../argaze/#argaze.GazeFeatures.GazePosition) class to handle point coordinates with a precision value.
``` python
from argaze import GazeFeatures
# Define a basic gaze position
gaze_position = GazeFeatures.GazePosition((123, 456))
# Define a gaze position with a precision value
gaze_position = GazeFeatures.GazePosition((789, 765), precision=10)
# Access to gaze position value and precision
print(f'position: {gaze_position.value}')
print(f'precision: {gaze_position.precision}')
```
## Validity
[GazeFeatures](../../../argaze/#argaze.GazeFeatures) defines also a [UnvalidGazePosition](../../../argaze/#argaze.GazeFeatures.UnvalidGazePosition) class that inherits from [GazePosition](../../../argaze/#argaze.GazeFeatures.GazePosition) to handle case where no gaze position exists because of any specific device reason.
``` python
from argaze import GazeFeatures
# Define a basic unvalid gaze position
gaze_position = GazeFeatures.UnvalidGazePosition()
# Define a basic unvalid gaze position with a message value
gaze_position = GazeFeatures.UnvalidGazePosition("Something bad happened")
# Access to gaze position validity
print(f'validity: {gaze_position.valid}')
```
## Distance
[GazePosition](../../../argaze/#argaze.GazeFeatures.GazePosition) class provides a **distance** method to calculate the distance to another gaze position instance.
![Distance](../../img/distance.png)
``` python
# Distance between A and B positions
d = gaze_position_A.distance(gaze_position_B)
```
## Overlapping
[GazePosition](../../../argaze/#argaze.GazeFeatures.GazePosition) class provides an **overlap** method to test if a gaze position overlaps another one considering their precisions.
![Gaze overlapping](../../img/overlapping.png)
``` python
# Check that A overlaps B
if gaze_position_A.overlap(gaze_position_B):
# Do something if A overlaps B
...
# Check that A overlaps B and B overlaps A
if gaze_position_A.overlap(gaze_position_B, both=True):
# Do something if A overlaps B AND B overlaps A
...
```
## Timestamped gaze positions
[TimeStampedGazePositions](../../../argaze/#argaze.GazeFeatures.TimeStampedGazePositions) inherits from [TimeStampedBuffer](../../../argaze/#argaze.DataStructures.TimeStampedBuffer) class to handle especially gaze positions.
### Import from dataframe
It is possible to load timestamped gaze positions from a [Pandas DataFrame](https://pandas.pydata.org/docs/getting_started/intro_tutorials/01_table_oriented.html#min-tut-01-tableoriented) object.
```python
import pandas
# Load gaze positions from a CSV file into Panda Dataframe
dataframe = pandas.read_csv('gaze_positions.csv', delimiter="\t", low_memory=False)
# Convert Panda dataframe into TimestampedGazePositions buffer precising the use of each specific column labels
ts_gaze_positions = GazeFeatures.TimeStampedGazePositions.from_dataframe(dataframe, timestamp = 'Recording timestamp [ms]', x = 'Gaze point X [px]', y = 'Gaze point Y [px]')
```
|