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
|
#!/usr/bin/env python
import argparse
from argaze.TobiiGlassesPro2 import TobiiEntities, TobiiData, TobiiVideo
import matplotlib.pyplot as mpyplot
import matplotlib.patches as mpatches
def main():
"""
Explore Tobii Glasses Pro 2 interface's SD Card
"""
# manage arguments
parser = argparse.ArgumentParser(description=main.__doc__.split('-')[0])
parser.add_argument('-d', '--drive_path', metavar='DRIVE_PATH', type=str, default=None, help='drive path')
parser.add_argument('-p', '--project_path', metavar='PROJECT_PATH', type=str, default=None, help='project path')
parser.add_argument('-r', '--recording_path', metavar='RECORDING_PATH', type=str, default=None, help='recording path')
parser.add_argument('-s', '--segment_path', metavar='SEGMENT_PATH', type=str, default=None, help='segment path')
args = parser.parse_args()
if args.drive_path != None:
# Load all projects from a tobii drive
tobii_drive = TobiiEntities.TobiiDrive(args.drive_path)
for project in tobii_drive.projects():
print(f'Project id: {project.id}, name: {project.name}')
elif args.project_path != None:
# Load one tobii project
tobii_project = TobiiEntities.TobiiProject(args.project_path)
for participant in tobii_project.participants():
print(f'Participant id: {participant.id}, name: {participant.name}')
for recording in tobii_project.recordings():
print(f'Recording id: {recording.id}, name: {recording.name}')
print(f'\tProject: {recording.project.name}')
print(f'\tParticipant: {recording.participant.name}')
elif args.recording_path != None:
# Load a tobii segment
tobii_recording = TobiiEntities.TobiiRecording(args.recording_path)
for segment in tobii_recording.segments():
print(f'Segment id: {segment.id}')
elif args.segment_path != None:
# Load a tobii segment
tobii_segment = TobiiEntities.TobiiSegment(args.segment_path)
tobii_segment_video = tobii_segment.load_video()
print(f'Video properties:\n\tduration: {tobii_segment_video.duration/1e6} s\n\twidth: {tobii_segment_video.width} px\n\theight: {tobii_segment_video.height} px')
tobii_segment_data = tobii_segment.load_data()
print(f'Loaded data count:')
for name in tobii_segment_data.keys():
print(f'\t{name}: {len(tobii_segment_data[name])} data')
# Edit figure
figure_width = min(tobii_segment_video.duration/10, 56) # maximal width to display: 56 inches at 144 dpi < 2^16 pixels
data_sample = 8064 # 56 inches * 144 dpi = 8064 data can be displayed at max
figure = mpyplot.figure(figsize=(figure_width, 5), dpi=144)
# Plot data
subplot = figure.add_subplot(111)
subplot.set_title('VideoTimeStamps', loc='left')
patches = tobii_segment_data['VideoTimeStamp'].plot(names=['offset','value'], colors=['#276FB6','#9427B6'], samples=data_sample)
subplot.legend(handles=patches, loc='upper left')
# Display figure
mpyplot.show()
figure.clear()
if __name__ == '__main__':
main()
|