BaseCameraInterface
Purpose
This module provides:
- A uniform API across all supported camera hardware.
- SOLID design principles to promote single-responsibility, extensibility, and decoupling.
- Type safety through Python type hints.
- Easy testing via dependency injection and mockability.
Key Interface: CameraInterface
CameraInterface
is an abstract base class defining the essential operations expected from any camera implementation.
Core Lifecycle Methods
Method | Description |
---|---|
__init__(**kwargs) |
Sets up camera SDK, applies configuration, and prepares for acquisition. |
start_capture() |
Begins image acquisition or live streaming. |
stop_capture() |
Halts image acquisition or live streaming. |
get_image(wait=True) |
Retrieves the latest frame, optionally blocking until a new one is ready. |
close() |
Releases hardware resources and shuts down the camera safely. |
Camera Settings as Properties
Common camera parameters are exposed as Python properties, allowing both reading and writing through a uniform interface:
Property | Type | Description |
---|---|---|
exposure |
float | Camera exposure time (in seconds). |
framerate |
float | Frame rate (in frames per second). |
gain |
float | Sensor analog gain. |
These properties standardize hardware parameter control across heterogeneous devices.
Dark Frame Management
CameraInterface
includes methods for managing dark-frame capture and reuse:
Method | Description |
---|---|
take_dark(frames, save_path) |
Captures and averages multiple frames to generate a dark frame. |
load_dark(file) |
Loads a previously saved dark frame from disk for subtraction or QA. |
This is particularly useful for calibration routines and background subtraction workflows.
Design Considerations
- Interface Enforcement: All camera drivers must adhere to the same method/property interface, enabling interchangeability without modification to upstream systems.
- Extensibility: New camera types can be integrated by subclassing
CameraInterface
and implementing the required methods. - Mockability for Testing: By abstracting away hardware-specific logic, the interface enables injection of mocks and stubs in test environments.
- Consistency: Centralized documentation and type annotations help enforce clarity and uniformity across all implementations.
Intended Usage
The module is meant to be subclassed by hardware-specific drivers. This approach enables higher-level tools (e.g. data acquisition scripts, GUIs, or analysis pipelines) to remain agnostic to the underlying camera backend.
For a practical implementation, refer to concrete subclasses such as FliCamera
, which adapts the interface to the FliSdk hardware.
BaseCameraInterface.start_capture
BaseCameraInterface.start_capture ()
Begin image acquisition or live stream.
BaseCameraInterface.stop_capture
BaseCameraInterface.stop_capture ()
Halt image acquisition or live stream.
BaseCameraInterface.exposure
BaseCameraInterface.exposure ()
Get or set the camera exposure time in seconds.
BaseCameraInterface.framerate
BaseCameraInterface.framerate ()
Get or set the camera frame rate in frames per second.
BaseCameraInterface.gain
BaseCameraInterface.gain ()
Get or set the camera gain (e.g., sensor analog gain).
BaseCameraInterface.get_image
BaseCameraInterface.get_image (wait:bool=True)
Retrieve the latest image frame. :param wait: block until a new frame is available :return: 2D numpy array representing the image
BaseCameraInterface.take_dark
BaseCameraInterface.take_dark (frames:int=100, save_path:Optional[pathlib.Path]=None)
Acquire a dark frame by averaging multiple captures. :param frames: number of frames to average :param save_path: optional file path to save the dark frame :return: dark frame array
BaseCameraInterface.load_dark
BaseCameraInterface.load_dark (file:Union[str,pathlib.Path])
Load a previously saved dark frame from disk.
BaseCameraInterface.close
BaseCameraInterface.close ()
Release all resources and shut down the camera.
goodtimer
goodtimer (time_ms)
*Active wait timer for precise timing control.
Unlike time.sleep(), this function actively consumes CPU cycles to ensure more precise timing at the expense of CPU usage.*
Type | Details | |
---|---|---|
time_ms | float | Time to wait in milliseconds. |