Skip to content

Streaming Gaze Data

Use receive_gaze_data to subscribe to gaze data.

This function can return different types of gaze data (GazeDataType) depending on the device and its configuration:

See below samples for each type of gaze data.

GazeData(
    x=784.0623779296875,
    y=537.4524536132812,
    worn=False,
    timestamp_unix_seconds=1744294828.3579288
)

Neon +2.8.8 +1.2.0

EyestateGazeData(
    x=784.0623779296875,
    y=537.4524536132812,
    worn=False,
    pupil_diameter_left=4.306737899780273,
    eyeball_center_left_x=-29.3125,
    eyeball_center_left_y=11.6875,
    eyeball_center_left_z=-42.15625,
    optical_axis_left_x=0.09871648252010345,
    optical_axis_left_y=0.15512824058532715,
    optical_axis_left_z=0.9829498529434204,
    pupil_diameter_right=3.2171919345855713,
    eyeball_center_right_x=33.21875,
    eyeball_center_right_y=12.84375,
    eyeball_center_right_z=-45.34375,
    optical_axis_right_x=-0.20461124181747437,
    optical_axis_right_y=0.1512681096792221,
    optical_axis_right_z=0.9670844078063965,
    timestamp_unix_seconds=1744294828.3579288
)
This method also provides pupil diameter and eye poses.

Neon +2.9.0 +1.3.6

EyestateEyelidGazeData(
    x=784.0623779296875,
    y=537.4524536132812,
    worn=False,
    pupil_diameter_left=4.306737899780273,
    eyeball_center_left_x=-29.3125,
    eyeball_center_left_y=11.6875,
    eyeball_center_left_z=-42.15625,
    optical_axis_left_x=0.09871648252010345,
    optical_axis_left_y=0.15512824058532715,
    optical_axis_left_z=0.9829498529434204,
    pupil_diameter_right=3.2171919345855713,
    eyeball_center_right_x=33.21875,
    eyeball_center_right_y=12.84375,
    eyeball_center_right_z=-45.34375,
    optical_axis_right_x=-0.20461124181747437,
    optical_axis_right_y=0.1512681096792221,
    optical_axis_right_z=0.9670844078063965,
    eyelid_angle_top_left=-1.1484375,
    eyelid_angle_bottom_left=-1.2763671875,
    eyelid_aperture_left=1.6408717632293701,
    eyelid_angle_top_right=-0.6259765625,
    eyelid_angle_bottom_right=-1.2216796875,
    eyelid_aperture_right=7.2039408683776855,
    timestamp_unix_seconds=1744294828.3579288
)
This method also provides eye openness data.

You can learn more about the payload in the Under the Hood guide.

Full Code Examples

Check the whole example code here
stream_gaze.py
 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
import asyncio
import contextlib

from pupil_labs.realtime_api import Device, Network, receive_gaze_data


async def main():
    async with Network() as network:
        dev_info = await network.wait_for_new_device(timeout_seconds=5)
    if dev_info is None:
        print("No device could be found! Abort")
        return

    async with Device.from_discovered_device(dev_info) as device:
        status = await device.get_status()
        sensor_gaze = status.direct_gaze_sensor()
        if not sensor_gaze.connected:
            print(f"Gaze sensor is not connected to {device}")
            return

        restart_on_disconnect = True
        async for gaze in receive_gaze_data(
            sensor_gaze.url, run_loop=restart_on_disconnect
        ):
            print(gaze)


if __name__ == "__main__":
    with contextlib.suppress(KeyboardInterrupt):
        asyncio.run(main())