cameras¶
Camera classes represent a particular capture session or recording duration. A camera is typically created from a capture device, though cameras can also operate independently (e.g. opening a USB device directly via OpenCV). Cameras are started and stopped each time the user begins and ends a recording, while the underlying capture device may remain powered on across multiple recordings.
omgrab.cameras.cameras
¶
Camera module for omgrab.
CameraConfig(fps, width, height)
dataclass
¶
Base camera configuration.
Attributes:
| Name | Type | Description |
|---|---|---|
fps |
int
|
Target capture frame rate. |
width |
int
|
Frame width in pixels. |
height |
int
|
Frame height in pixels. |
FrameUnavailableError
¶
Bases: RuntimeError
Exception raised when a frame is not available.
Camera(config, enforce_frame_timing=True)
¶
Bases: Generic[FrameT], ABC
Camera class for omgrab.
Initialize the camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CameraConfig
|
Camera configuration. |
required |
enforce_frame_timing
|
bool
|
If True, get_next_frame will sleep to enforce the configured FPS. Set to False for queue-based cameras where the hardware already controls frame timing. |
True
|
config
property
¶
Get the camera configuration.
get_next_frame(timeout_s=None)
abstractmethod
¶
Get the next frame from the camera.
setup()
abstractmethod
¶
Setup the camera.
close()
abstractmethod
¶
Close the camera.
__enter__()
¶
Enter the context manager.
__exit__(exc_type, exc_value, traceback)
¶
Exit the context manager.
omgrab.cameras.oakd_camera
¶
OAK-D camera implementations.
Camera classes that read frames from queues populated by the OAK-D capture device (see omgrab.devices.oakd_capture_device). Each camera instance represents a single stream (RGB or depth) for the duration of a recording session.
omgrab.cameras.queue_reader_camera
¶
omgrab.cameras.usb_camera
¶
USB camera implementation using OpenCV VideoCapture.
USBCamera(config, device_path='', usb_port_path='')
¶
Bases: Camera[RGBFrame]
Camera that reads frames from a USB camera via OpenCV.
Initialize the USB camera.
Exactly one of device_path or usb_port_path must be provided.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CameraConfig
|
Camera configuration (fps, width, height). |
required |
device_path
|
str
|
Path to the video device (e.g. '/dev/video2'). |
''
|
usb_port_path
|
str
|
USB port path (e.g. '3-2'). The device path is resolved from sysfs each time setup() is called. |
''
|
setup()
¶
Open the USB camera and configure resolution/fps.
close()
¶
Release the USB camera.
get_next_frame(timeout_s=None)
¶
Read the next frame from the USB camera.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout_s
|
Optional[float]
|
Not used. On V4L2 with BUFFERSIZE=1, grab() blocks for at most one frame period (~33ms at 30fps). If the device is disconnected, grab() returns False immediately. |
None
|
Returns:
| Type | Description |
|---|---|
tuple[RGBFrame, datetime]
|
Tuple of (frame, timestamp). |
Raises:
| Type | Description |
|---|---|
FrameUnavailableError
|
If the frame could not be read. |