camera.cv#

class platypush.plugins.camera.cv.CameraCvPlugin(color_transform: str | None = 'COLOR_BGR2RGB', video_type: str = 'XVID', video_writer: str = 'ffmpeg', **kwargs)[source]#

Bases: CameraPlugin

Plugin to control generic cameras over OpenCV.

Requires:

  • opencv (pip install opencv-python)

  • Pillow (pip install Pillow)

__init__(color_transform: str | None = 'COLOR_BGR2RGB', video_type: str = 'XVID', video_writer: str = 'ffmpeg', **kwargs)[source]#
Parameters:
  • device – Device ID (0 for the first camera, 1 for the second etc.) or path (e.g. /dev/video0).

  • video_type – Default video type to use when exporting captured frames to camera (default: 0, infers the type from the video file extension). See here for a reference on the supported types (e.g. ‘MJPEG’, ‘XVID’, ‘H264’, ‘X264’, ‘AVC1’ etc.)

  • color_transform – Color transformation to apply to the captured frames. See https://docs.opencv.org/3.2.0/d7/d1b/group__imgproc__misc.html for a full list of supported color transformations (default: “COLOR_RGB2BGR”)

  • video_writer

    Class to be used to write frames to a video file. Supported values:

    • ffmpeg: Use the FFmpeg writer (default, and usually more reliable - it requires ffmpeg

      installed).

    • cv: Use the native OpenCV writer.

    The FFmpeg video writer requires scikit-video (pip install scikit-video) and ffmpeg.

  • kwargs – Extra arguments to be passed up to platypush.plugins.camera.CameraPlugin.

capture_frame(camera: Camera, *args, **kwargs)[source]#

Capture a frame from a device using the plugin-specific logic - to be implemented by the derived classes.

Parameters:

device – An initialized platypush.plugins.camera.Camera object.

prepare_device(device: Camera)[source]#

Prepare a device using the plugin-specific logic - to be implemented by the derived classes.

Parameters:

device – An initialized platypush.plugins.camera.Camera object.

release_device(device: Camera)[source]#

Release a device using the plugin-specific logic - to be implemented by the derived classes.

Parameters:

device – An initialized platypush.plugins.camera.Camera object.

static transform_frame(frame, color_transform: str | int)[source]#

Frame color space (e.g. RGB24, YUV etc.) transform logic. Does nothing unless implemented by a derived plugin.