Skip to content

neon_usb

pupil_labs.neon_usb package.

Library for connecting to Neon via USB

Modules:

  • cameras
  • frame
  • pyrav4l2
  • queue_utils
  • usb_utils

Classes:

  • Frame
  • IMU

    Cython wrapper for Neon USB IMU device.

  • IMUData

    Data from the Inertial Measurement Unit (IMU).

  • SceneCamera

    Provides an interface for handling the Neon scene camera.

Functions:

  • get_all_items

    Retrieve all items from a queue and always at least one.

Frame dataclass

Frame(img: ndarray, timestamp: float, index: int)

Attributes:

  • bgr (ndarray) –

    Return a 3-channel BGR version of self.img

  • gray (ndarray) –

    Return a grayscale version of self.img

bgr property

bgr: ndarray

Return a 3-channel BGR version of self.img

gray property

gray: ndarray

Return a grayscale version of self.img

IMU

IMU(*args, **kwargs)

Cython wrapper for Neon USB IMU device.

Methods:

get_imu_data method descriptor

get_imu_data() -> IMUData

Get the latest IMU data from the device.

start_sensors method descriptor

start_sensors() -> None

Start the IMU sensors.

stop_sensors method descriptor

stop_sensors() -> None

Stop the IMU sensors.

IMUData

Bases: NamedTuple

Data from the Inertial Measurement Unit (IMU).

Contains gyroscope, accelerometer, and rotation data from the IMU sensor.

Attributes:

accel_data instance-attribute

accel_data: Data3D

Accelerometer data in m/s².

datetime property

datetime: datetime

Get timestamp as a datetime object.

gyro_data instance-attribute

gyro_data: Data3D

Gyroscope data in deg/s.

quaternion instance-attribute

quaternion: Quaternion

Rotation represented as a quaternion.

timestamp_unix_ns property

timestamp_unix_ns: int

Get timestamp in nanoseconds since Unix epoch.

timestamp_unix_seconds instance-attribute

timestamp_unix_seconds: float

Timestamp in seconds since Unix epoch.

SceneCamera

SceneCamera(spec: CameraSpec = NEON_SCENE_CAMERA_SPEC)

Bases: Camera

Provides an interface for handling the Neon scene camera.

The class is assuming that no more than one Neon device is connected to the computer at the same time.

The camera stream will be started right away. If the object fails to grab frames, it will automatically try to reinitialize.

Methods:

  • get_intrinsics

    Retrieve the scene camera intrinsics of the Neon device

Source code in src/pupil_labs/neon_usb/cameras/scene.py
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
def __init__(self, spec: CameraSpec = NEON_SCENE_CAMERA_SPEC) -> None:
    """Initialize the scene camera of the connected Neon device.

    The camera stream will be started right away. If the object fails to grab
    frames, it will automatically try to reinitialize.
    """
    super().__init__(NEON_SCENE_CAMERA_SPEC, UVCBackend)

    assert isinstance(self.backend, UVCBackend)
    self.uvc_controls = {
        c.display_name: c for c in self.backend._uvc_capture.controls
    }
    camera_parameters = {
        "Backlight Compensation": 2,
        "Brightness": 0,
        "Contrast": 32,
        "Gain": 64,
        "Hue": 0,
        "Saturation": 64,
        "Sharpness": 50,
        "Gamma": 300,
        "Auto Exposure Mode": 1,
        "Absolute Exposure Time": 250,
    }
    for key, value in camera_parameters.items():
        try:
            self.uvc_controls[key].value = value
        except KeyError:
            print(f"Setting {key} to {value} failed: Unknown control. Known ")

get_intrinsics staticmethod

get_intrinsics() -> SceneIntrinsics

Retrieve the scene camera intrinsics of the Neon device

Returns:

  • SceneIntrinsics

    Tuple containing camera matrix and distortion coefficients of scene camera.

Source code in src/pupil_labs/neon_usb/cameras/scene.py
64
65
66
67
68
69
70
71
72
73
74
75
76
77
@staticmethod
def get_intrinsics() -> SceneIntrinsics:
    """Retrieve the scene camera intrinsics of the Neon device

    Returns:
        Tuple containing camera matrix and distortion coefficients of scene camera.

    """
    calib_data = get_calibration()
    return SceneIntrinsics(
        calib_data.scene_camera_matrix,
        calib_data.scene_distortion_coefficients,
        calib_data.scene_extrinsics_affine_matrix,
    )

get_all_items

get_all_items(q: Queue[T]) -> list[T]

Retrieve all items from a queue and always at least one.

Source code in src/pupil_labs/neon_usb/queue_utils.py
13
14
15
16
17
18
19
20
21
22
23
24
def get_all_items(q: queue.Queue[T]) -> list[T]:
    """Retrieve all items from a queue and always at least one."""
    items = []
    # Need to get at least one item
    # Otherwise the queue might be spammed with requests
    items.append(q.get())
    while True:
        try:
            items.append(q.get_nowait())
        except queue.Empty:
            break
    return items