malphite.camera

Module Contents

Classes

Camera

CameraConfig

Base configuration class for cameras.

OpenCVCamera

A camera class that uses OpenCV to capture images.

OpenCVCameraConfig

Configuration for an OpenCV camera.

SharedCamera

A camera class that uses shared memory to capture images.

SharedCameraConfig

ManagedCamera

API

exception malphite.camera.CameraConfigurationError

Bases: Exception

Raised when camera configuration parameters cannot be set.

Initialization

Initialize self. See help(type(self)) for accurate signature.

class malphite.camera.Camera(camera_config: malphite.camera.CameraConfig)

Bases: abc.ABC

abstractmethod read_once() numpy.ndarray

Reads a single frame from the camera.

Returns:

The captured frame.

Return type:

np.ndarray

class malphite.camera.CameraConfig

Bases: abc.ABC

Base configuration class for cameras.

name: str | None = None

The name of the camera.

width: int | None = None

The width of the camera image in pixels.

height: int | None = None

The height of the camera image in pixels.

fps: float | None = None

The frames per second (FPS) of the camera.

type: str | None = None
target_class: malphite.camera.CameraConfig.type = None

The target class to instantiate with. This should be a subclass of Camera.

class malphite.camera.OpenCVCamera(camera_config: malphite.camera.OpenCVCameraConfig)

Bases: malphite.camera.Camera

A camera class that uses OpenCV to capture images.

Initialization

Initialize the camera with the given configuration.

Parameters:

camera_config (CameraConfig) – The configuration for the camera.

read_once() numpy.ndarray

Reads a single frame from the camera.

class malphite.camera.OpenCVCameraConfig

Bases: malphite.camera.CameraConfig

Configuration for an OpenCV camera.

camera_path: str = None

The path to the camera device, e.g., ‘/dev/video0’.

type: str = 'opencv'
target_class: malphite.camera.OpenCVCameraConfig.type = None
class malphite.camera.SharedCamera(camera_config: malphite.camera.SharedCameraConfig)

Bases: malphite.camera.Camera

A camera class that uses shared memory to capture images.

Initialization

Initialize the camera with the given configuration.

Parameters:

camera_config (CameraConfig) – The configuration for the camera.

read_once() numpy.ndarray

Reads a single frame from the shared memory.

class malphite.camera.SharedCameraConfig

Bases: malphite.camera.CameraConfig

type: str = 'shared'
target_class: malphite.camera.SharedCameraConfig.type = None
shared_memory_name: str | None = None

The name of the shared memory segment.

shared_memory_size: int | None = None

The size of the shared memory segment in bytes.

For example, if the camera resolution is width x height and the image is in 8-bit RGB format, the size can be calculated as:

shared_memory_size = int(width * height * 3  * np.uint8().itemsize)
__post_init__()
class malphite.camera.ManagedCamera(camera_config: malphite.camera.CameraConfig, shared_memory_name: str = None)

Bases: malphite.camera.Camera

_instance: malphite.camera.Camera = None
read_once() numpy.ndarray

Reads a single frame from the camera.

export_shared_camera_config() malphite.camera.SharedCameraConfig

Exports the camera configuration as a SharedCameraConfig.