.md →
WebcamCapture API#
WebcamCapture puts a live camera preview in the notebook with a capture button and an
auto-capture toggle. Each snapshot lands in image_base64, and get_pil() or
get_bytes() turn it into something a model can eat. Set interval_ms and flip
capturing to pull frames on a cadence — enough to run inference on a rough video
stream. facing_mode picks the front or rear camera; error reports refused access.
See also: Paint for drawing on a canvas instead of photographing one, HoverZoom for inspecting a captured frame up close, and FramePlayer for replaying a run of captures as a loop.
Bases: AnyWidget
Webcam capture widget with manual and interval snapshots.
The widget shows a live webcam preview plus a capture button and an
auto-capture toggle. When capturing is enabled, the browser updates
image_base64 on the cadence specified by interval_ms.
Examples:
import marimo as mo
from wigglystuff import WebcamCapture
cam = mo.ui.anywidget(WebcamCapture(interval_ms=1000))
cam
Create a WebcamCapture widget.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
interval_ms
|
int
|
Capture interval in milliseconds when auto-capture is on. |
1000
|
facing_mode
|
str
|
Camera facing mode ("user" or "environment"). |
'user'
|
Source code in wigglystuff/webcam_capture.py
get_bytes #
Return the captured frame as raw bytes.
Source code in wigglystuff/webcam_capture.py
get_pil #
Return the captured frame as a PIL Image.
Source code in wigglystuff/webcam_capture.py
Synced traitlets#
| Traitlet | Type | Notes |
|---|---|---|
image_base64 |
str |
PNG data URL for the latest frame. |
capturing |
bool |
Enable auto-capture mode. |
interval_ms |
int |
Auto-capture interval in milliseconds. |
facing_mode |
str |
Camera facing mode ("user" or "environment"). |
ready |
bool |
True when the preview stream is ready. |
error |
str |
Error message when webcam access fails. |