Camera¶
raspbot.camera.opencv_camera.Camera
OpenCV VideoCapture wrapper for the Raspbot V2.
Optional extra
This module requires the camera extras group:
All methods that need cv2 raise ImportError with a helpful message if it is not installed.
Access via Robot.camera.
Constructor¶
| Parameter | Type | Default | Description |
|---|---|---|---|
device |
int or str |
0 |
Camera index or device path (e.g. "/dev/video0") |
width |
int |
640 |
Requested capture width (driver may differ) |
height |
int |
480 |
Requested capture height (driver may differ) |
fps |
int |
30 |
Requested frame rate (driver may differ) |
The capture device is not opened until open() is called.
Properties¶
is_open¶
True when the capture device is open and ready.
width¶
Actual capture width reported by the driver (0 when not open).
height¶
Actual capture height reported by the driver (0 when not open).
fps¶
Actual FPS reported by the driver (0 when not open).
Methods¶
open()¶
Open the capture device.
Returns: True on success, False if the device cannot be opened (not connected, driver not
loaded, or cv2 not installed).
close()¶
Release the capture device. Safe to call even if the device is already closed.
read_frame()¶
Capture one frame from the camera.
Returns: A BGR image array with shape (height, width, 3) and dtype uint8, or None if
the frame could not be read.
Raises: RuntimeError if the camera has not been opened first.
read_frame_rgb()¶
Capture one frame and convert from BGR to RGB.
Convenience wrapper for callers that expect RGB order (e.g. for display with matplotlib or Pillow).
Context manager¶
Camera supports the context manager protocol.
open() is called on entry, close() on exit.
Raspberry Pi camera notes¶
For a Pi Camera Module (V1/V2/3) on Pi OS Bullseye or earlier:
This exposes the camera as /dev/video0 which OpenCV can open normally.
For Pi OS Bookworm with libcamera, use libcamera-apps or configure the V4L2 bridge in
/boot/config.txt. USB webcams work without extra configuration.