pupil_recording_interface.PupilDetector

class pupil_recording_interface.PupilDetector(method='2d c++', camera_id=None, resolution=None, focal_length=None, folder=None, record=False, display=True, **kwargs)

Bases: pupil_recording_interface.process.BaseProcess

Pupil detector for eye video streams.

This process detects pupils in eye camera frames. Attach one to each eye video stream.

__init__(method='2d c++', camera_id=None, resolution=None, focal_length=None, folder=None, record=False, display=True, **kwargs)

Constructor.

Parameters
  • method (str) – Detection method. Currently supported are “2d c++” and “pye3d”, provided that the necessary dependencies are installed.

  • camera_id (Optional[int]) – ID of the eye camera (0 or 1). This is important if you use the result of the pupil detection for a Calibration or GazeMapper process.

  • resolution (Optional[tuple]) – Resolution of the eye camera. Required for “pye3d” detection method.

  • focal_length (Optional[float]) – Focal length of the eye camera. Required for “pye3d” detection method.

  • folder (Optional[os.PathLike]) – Folder for recording detected pupils.

  • record (bool) – If True, record pupils to a pupil.pldata file in the recording folder.

  • display (bool) – If True, add this instance’s display_hook method to the packet returned by process_packet. A VideoDisplay later in the pipeline will pick this up to draw the extent of the currently detected pupil over the camera image.

Methods

Config(*args, **kwargs)

Configuration for this class.

__init__([method, camera_id, resolution, …])

Constructor.

batch_run(video_reader[, start, end, …])

Detect pupils in an eye video.

detect_pupil(frame, timestamp)

Detect pupil in frame.

display_hook(packet)

Add pupil overlay onto frame.

from_config(config, stream_config, device, …)

Create a process from a ProcessConfig.

process(packet, notifications)

Process new data.

process_notifications(notifications)

Process new notifications.

process_packet(packet)

Process a new packet.

record_data(pupil)

Write pupil datum to disk.

start()

Start the process.

stop()

Stop the process.

Attributes

process_type

classmethod Config(*args, **kwargs)

Configuration for this class.

batch_run(video_reader, start=None, end=None, return_type='list')

Detect pupils in an eye video.

Parameters
  • video_reader (pri.VideoReader instance) – Video reader for an eye camera recording.

  • start (int or pandas.Timestamp, optional) – If specified, start the detection at this frame index or timestamp.

  • end (int or pandas.Timestamp, optional) – If specified, stop the detection at this frame index or timestamp.

  • return_type (str or None, default "list") – The data type that this method should return. “list” returns o list of dicts with pupil data for each frame. “dataset” returns an xarray Dataset. Can also be None, in that case pupil data is not loaded into memory and this method returns nothing, which is useful when recording detected pupils to disk.

Returns

  • pupil_list (list of dict) – List of detected pupils if return_type=”list” (one per frame).

  • ds (xarray.Dataset) – Dataset with pupil data if return_type=”dataset”.

detect_pupil(frame, timestamp)

Detect pupil in frame.

display_hook(packet)

Add pupil overlay onto frame.

classmethod from_config(config, stream_config, device, **kwargs)

Create a process from a ProcessConfig.

process(packet, notifications)

Process new data.

process_notifications(notifications)

Process new notifications.

process_packet(packet)

Process a new packet.

record_data(pupil)

Write pupil datum to disk.

start()

Start the process.

stop()

Stop the process.