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
|
#!/usr/bin/env python
import argparse
from argaze import GazeFeatures
from argaze.TobiiGlassesPro2 import TobiiEntities
def main():
"""
Analyse Tobii segment fixations
"""
# manage arguments
parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0])
parser.add_argument('-s', '--segment_path', metavar='SEGMENT_PATH', type=str, default=None, help='segment path')
parser.add_argument('-d', '--dispersion_threshold', metavar='DISPERSION_THRESHOLD', type=int, default=10, help='dispersion threshold in pixel')
parser.add_argument('-t', '--duration_threshold', metavar='DURATION_THRESHOLD', type=int, default=100, help='duration threshold in ms')
args = parser.parse_args()
if args.segment_path != None:
# Load a tobii segment
tobii_segment = TobiiEntities.TobiiSegment(args.segment_path)
# Load a tobii segment video
tobii_segment_video = tobii_segment.load_video()
print(f'Video duration: {tobii_segment_video.get_duration()}, frame number: {tobii_segment_video.get_frame_number()}, width: {tobii_segment_video.get_width()}, height: {tobii_segment_video.get_height()}')
# Load a tobii segment data
tobii_segment_data = tobii_segment.load_data()
print(f'Data keys: {tobii_segment_data.keys()}')
# Access to timestamped gaze position data buffer
tobii_ts_gaze_position_buffer = tobii_segment_data['gidx-l-gp']
print(f'{len(tobii_ts_gaze_position_buffer)} gaze positions loaded')
# format tobii gaze data into generic gaze data
generic_ts_gaze_position_buffer = GazeFeatures.TimeStampedGazePositions()
for ts, tobii_data in tobii_ts_gaze_position_buffer.items():
generic_data = GazeFeatures.GazePosition(tobii_data.gp[0] * tobii_segment_video.get_width(), tobii_data.gp[1] * tobii_segment_video.get_height())
generic_ts_gaze_position_buffer[ts] = generic_data
print(f'dispersion_threshold = {args.dispersion_threshold}')
print(f'duration_threshold = {args.duration_threshold}')
fixation_analyser = GazeFeatures.DispersionBasedFixationIdentifier(generic_ts_gaze_position_buffer, args.dispersion_threshold, args.duration_threshold)
print(f'{len(fixation_analyser.fixations)} fixations found')
for ts, f in fixation_analyser.fixations.items():
print(f'start time = {ts}, duration = {f.duration}, dispertion = {f.dispersion}, centroid = {f.centroid}')
# TODO : synchronise video and gaze
#for ts, frame in tobii_segment_video:
#print(ts)
if __name__ == '__main__':
main()
|