Skip to content

OPEN_WEBCAM

Download Flojoy Studio to try this app
Open a connection with the selected camera. Params: camera : Camera The camera to use. resolution : select Camera resolution. Choose from a few options. Returns: out : None
Python Code
import cv2
from flojoy import CameraDevice, flojoy, DataContainer
from flojoy.connection_manager import DeviceConnectionManager
from typing import Optional


@flojoy(deps={"opencv-python-headless": "4.8.1.78"})
def OPEN_WEBCAM(
    camera: CameraDevice,
    default: Optional[DataContainer] = None,
) -> Optional[DataContainer]:
    """Open a connection with the selected camera.

    Parameters
    ----------
    camera : Camera
        The camera to use.
    resolution : select
        Camera resolution. Choose from a few options.

    Returns
    -------
    None
    """

    if not camera:
        raise ValueError("No camera selected")

    cam = cv2.VideoCapture(camera.get_id())
    DeviceConnectionManager.register_connection(camera, cam)

    return None

Find this Flojoy Block on GitHub

Videos

Control Camera with Flojoy

Example App

Having problems with this example app? Join our Discord community and we will help you out!
React Flow mini map

In this example app, the CAMERA node takes and returns a picture from a camera connected to the computer.

The camera first has to be opened with the OPEN_CAMERA node, which requires you to select which camera to use.

The IMSHOW node displays the image taken by the camera that was selected.