Skip to content

Webcam

Just like video files, you can extract frames from your local webcam using landingai.pipeline.image_source.Webcam.

The example below iterates over the first 100 frames captured by the webcam, resizes it and saves it to a new video file.

from landingai.pipeline.image_source import Webcam
from landingai.pipeline.frameset import FrameSet

frameset = FrameSet() 
with Webcam(fps=1) as camera: 
    for i, frame in enumerate(camera): 
        if i >= 100:
            break
        frame.resize(width=256) 
        frameset.append(frame) 
frameset.save_video("/tmp/resized-video.mp4") 

Webcam on Collab and Remote Jupyter Notebooks

If you want to use your webcam while running a remote Jupyter Notebook or Google Collab, you might want to capture images from your local webcam (the one in the computer running the web UI, not the machine running the kernel).

In this case, landingai.pipeline.image_source.Webcam will not work. Instead, you should capture the images from your webcam using take_photo_from_webcam() function, from landingai.image_source_ops package:

from landingai.image_source_ops import take_photo_from_webcam
from landingai.pipeline.frameset import Frame

frame = Frame(image=take_photo_from_webcam())
frame.resize(width=256)