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:

  • EyeCamera

    Provides an interface for handling the Neon eye cameras.

  • Frame
  • 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.

EyeCamera

EyeCamera(spec: CameraSpec = NEON_EYE_CAMERA_SPEC)

Bases: Camera

Provides an interface for handling the Neon eye cameras.

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

Note that the two eye cameras is Neon are treated as a single device. Grabbing a frame from the EyeCam class will return a single frame containing images from both cameras.

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

Source code in src/pupil_labs/neon_usb/cameras/eye.py
108
109
110
111
112
113
114
115
116
117
def __init__(self, spec: CameraSpec = NEON_EYE_CAMERA_SPEC) -> None:
    """Initialize the eye cameras 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__(spec, V4l2Backend)
    self.exposure_algorithm: Exposure_Time | None = Exposure_Time(
        max_ET=28, frame_rate=200, mode="auto"
    )

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

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
11
12
13
14
15
16
17
18
19
20
21
22
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