Skip to content

Webcam Capture

A user input component that allows users to capture images using their webcam.

Fields

NameTypeDescriptionOptions
Refresh rate (ms)NumberSet to 0 for manual capture.
ButtonColor
Button textColor
Button shadowShadow
SeparatorColor
Custom CSS classesTextCSS classes, separated by spaces. You can define classes in custom stylesheets.

Events

NameDescriptionUsage
ss-webcamSent when a frame is captured. Its payload contains the captured frame in PNG format.
def webcam_handler(payload):

  # This handler will save the captured images based on timestamp

  import time
  timestamp = time.time()

  # The payload is a file-like object which contains the captured image
  # in PNG format

  image_file = payload
  with open(f"capture-{timestamp}.png", "wb") as file_handle:
    file_handle.write(image_file)

Low code usage

This component can be declared directly in Python, using backend-driven UI.

python
ui.WebcamCapture(content={
        "refreshRate": 0.0, # Union[float, str] 
        "buttonColor": "", # str 
        "buttonTextColor": "", # str 
        "buttonShadow": "", # str 
        "separatorColor": "", # str 
        "cssClasses": "", # str 
    },
    handlers={
        "ss-webcam": handle_event,
    }
)
A function, in this example handle_event, should be implemented in your code to handle events.
python
def handle_event(state, payload, context, ui):
  pass

Reference