Skip to content

Webcam viewer

The live picture of a camera with a frame rate badge

A camera app in 50 lines: examples/audio/webcam.py.

Terminal window
python examples/audio/webcam.py # the default camera
python examples/audio/webcam.py test # moving color bars, without a camera

Snapshot saves the current picture as a PNG next to the script, Pause freezes it.

from pyzed import camera, ui
cam = camera.Camera(0, width=1280, height=720, mirror=True)
cam.start()
def view(self):
return pz.column([
ui.camera.Webcam(camera=cam, width=720, height=405, radius=10),
ui.button("Snapshot", lambda: cam.snapshot("photo.png")),
])

The camera is read on its own thread; each new picture asks the window to redraw, so the app needs no timer. It uses OpenCV when it is installed (pip install opencv-python), else the ffmpeg program, else the test pattern. See Webcam for every option.