platypush.plugins.camera

class platypush.plugins.camera.CameraPlugin(device_id=0, frames_dir=None, warmup_frames=5, video_type=0, sleep_between_frames=0, max_stored_frames=100, color_transform='COLOR_BGR2BGRA', scale_x=None, scale_y=None, rotate=None, flip=None, stream_raw_frames=False, **kwargs)[source]

Plugin to control generic cameras over OpenCV.

Triggers:

Requires:

  • opencv (pip install opencv-python)
__init__(device_id=0, frames_dir=None, warmup_frames=5, video_type=0, sleep_between_frames=0, max_stored_frames=100, color_transform='COLOR_BGR2BGRA', scale_x=None, scale_y=None, rotate=None, flip=None, stream_raw_frames=False, **kwargs)[source]
Parameters:
  • device_id (int) – Index of the default video device to be used for capturing (default: 0)
  • frames_dir (str) – Directory where the camera frames will be stored (default: ~/.local/share/platypush/camera/frames)
  • warmup_frames (int) – Cameras usually take a while to adapt their luminosity and focus to the environment when taking a picture. This parameter allows you to specify the number of “warmup” frames to capture upon picture command before actually capturing a frame (default: 5 but you may want to calibrate this parameter for your camera)
  • video_type (str or int) – 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’ etc’)
  • sleep_between_frames (float) – If set, the process will sleep for the specified amount of seconds between two frames when recording (default: 0)
  • max_stored_frames (int) – Maximum number of frames to store in frames_dir when recording with no persistence (e.g. streaming over HTTP) (default: 100)
  • color_transform (str) – 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_BGR2BGRA”)
  • scale_x (float) – If set, the images will be scaled along the x axis by the specified factor
  • scale_y (float) – If set, the images will be scaled along the y axis by the specified factor
  • rotate (float) – If set, the images will be rotated by the specified number of degrees
  • flip (int) –

    If set, the images will be flipped around the specified axis. Possible values:

    - ``0`` - flip along the x axis
    - ``1`` - flip along the y axis
    - ``-1`` - flip along both the axis
    
start_recording(duration: Optional[float] = None, video_file: Optional[str] = None, video_type: Optional[str] = None, device_id: Optional[int] = None, frames_dir: Optional[str] = None, sleep_between_frames: Optional[float] = None, max_stored_frames: Optional[int] = None, color_transform: Optional[str] = None, scale_x: Optional[float] = None, scale_y: Optional[float] = None, rotate: Optional[float] = None, flip: Optional[int] = None)[source]

Start recording

Parameters:
  • duration – Record duration in seconds (default: None, record until stop_recording)
  • video_file – If set, the stream will be recorded to the specified video file (default: None)
  • video_type – Overrides the default configured video_type
  • device_id – Override default device_id
  • frames_dir – Override default frames_dir
  • sleep_between_frames – Override default sleep_between_frames
  • max_stored_frames – Override default max_stored_frames
  • color_transform – Override default color_transform
  • scale_x – Override default scale_x
  • scale_y – Override default scale_y
  • rotate – Override default rotate
  • flip – Override default flip
status(device_id=None)[source]

Returns the status of the specified device_id or all the device in a { device_id => device_info } map format. Device info includes video_file, image_file, frames_dir and additional video info

stop_recording(device_id=None)[source]

Stop recording

take_picture(image_file: str, device_id: Optional[int] = None, warmup_frames: Optional[int] = None, color_transform: Optional[str] = None, scale_x: Optional[float] = None, scale_y: Optional[float] = None, rotate: Optional[float] = None, flip: Optional[int] = None)[source]

Take a picture.

Parameters:
  • image_file – Path where the output image will be stored.
  • device_id – Override default device_id
  • warmup_frames – Override default warmup_frames
  • color_transform – Override default color_transform
  • scale_x – Override default scale_x
  • scale_y – Override default scale_y
  • rotate – Override default rotate
  • flip – Override default flip