aboutsummaryrefslogtreecommitdiff
path: root/src/argaze/utils/replay_tobii_session.py
blob: b911d095853cac2cd20f1089289ab27f88a15b18 (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
#!/usr/bin/env python

import argparse
import bisect

from argaze import GazeFeatures
from argaze.TobiiGlassesPro2 import TobiiEntities, TobiiVideo, TobiiData

import numpy

import cv2 as cv

def main():
    """
    Replay Tobii segment video
    """

    # 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')
    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_positions = tobii_segment_data.gidx_l_gp

        print(f'{len(tobii_ts_gaze_positions)} gaze positions loaded')

        # video and data replay loop
        try:

            for frame_ts, frame in tobii_segment_video.frames():

                # close window using 'Esc' key
                if cv.waitKey(1) == 27:
                    break

                cv.imshow(f'Segment {tobii_segment.get_id()} video', frame.matrix)

        # exit on 'ctrl+C' interruption
        except KeyboardInterrupt:
            pass

        # stop frame display
        cv.destroyAllWindows()

if __name__ == '__main__':

    main()