Camera
Continuously captures frames from a document camera in a background thread.Constructor
Camera device index. Uses
config.camera_device_index if NoneFrame width in pixels. Uses
config.camera_frame_width if NoneFrame height in pixels. Uses
config.camera_frame_height if NoneRotation mode: “auto”, “none”, “90”, “180”, “270”. Uses
config.camera_rotation if NoneMethods
start()
Open the camera and begin background frame capture.RuntimeError if camera cannot be opened or device index is invalid.
Location: camera.py:89-118
get_frame()
Return the most recent frame as a BGR numpy array, or None.BGR image array (OpenCV format), or None if no frame captured yet
get_frame_rgb()
Return the most recent frame converted to RGB.RGB image array, or None if no frame captured yet
capture_base64_jpeg()
Grab the current frame and return it as a base64-encoded JPEG string.JPEG compression quality (0-100)
Base64-encoded JPEG string, or None if no frame available
capture_thumbnail_bytes()
Return a small JPEG thumbnail as raw bytes (for the chat feed).Maximum width in pixels (height scaled proportionally)
JPEG-encoded thumbnail bytes, or None if no frame available
stop()
Stop the capture thread and release the camera.Properties
Whether the camera is actively capturing
Current camera device index
Utility Functions
enumerate_cameras()
Return available cameras as dicts for backward compatibility.Maximum device index to probe
List of camera info dicts with keys:
index, name, width, heightdevice_catalog.list_camera_devices() and converts to dict format.
Camera Rotation
The Camera class supports automatic rotation for portrait-oriented document cameras:"auto"(default): Detects portrait frames (height > width) and rotates 90° clockwise"none": No rotation"90","180","270": Fixed rotation angles
Platform Notes
- Uses OpenCV (
cv2.VideoCapture) withCAP_DSHOWbackend on Windows,CAP_ANYelsewhere - Camera enumeration on macOS uses AVFoundation (via
device_catalog) for friendly device names - Background capture thread runs as daemon