platypush.plugins.camera.pi

class platypush.plugins.camera.pi.CameraPiPlugin(resolution=(800, 600), framerate=24, hflip=False, vflip=False, sharpness=0, contrast=0, brightness=50, video_stabilization=False, iso=0, exposure_compensation=0, exposure_mode='auto', meter_mode='average', awb_mode='auto', image_effect='none', color_effects=None, rotation=0, zoom=(0.0, 0.0, 1.0, 1.0), listen_port: int = 5000, **kwargs)[source]

Plugin to control a Pi camera.

Requires:

  • picamera (pip install picamera)
  • numpy (pip install numpy)
__init__(resolution=(800, 600), framerate=24, hflip=False, vflip=False, sharpness=0, contrast=0, brightness=50, video_stabilization=False, iso=0, exposure_compensation=0, exposure_mode='auto', meter_mode='average', awb_mode='auto', image_effect='none', color_effects=None, rotation=0, zoom=(0.0, 0.0, 1.0, 1.0), listen_port: int = 5000, **kwargs)[source]

See https://www.raspberrypi.org/documentation/usage/camera/python/README.md for a detailed reference about the Pi camera options.

Parameters:listen_port – Default port that will be used for streaming the feed (default: 5000)
capture_sequence(n_images, directory, name_format='image_%04d.jpg', preview=False, warmup_time=2, resize=None, **opts)[source]

Capture a sequence of images

Parameters:
  • n_images (int) – Number of images to capture
  • directory (str) – Path where the images will be stored
  • name_format (str) – Format for the name of the stored images. Use %d or any other format string for representing the image index (default: image_%04d.jpg)
  • preview (bool) – Show a preview before taking the picture (default: False)
  • warmup_time (float) – Time before taking the picture (default: 2 seconds)
  • resize (list or tuple (with two elements)) – Set if you want to resize the picture to a new format
  • opts – Extra options to pass to the camera (see https://www.raspberrypi.org/documentation/usage/camera/python/README.md)
Returns:

dict:

{"image_files": [list of captured images]}

close()[source]

Close an active connection to the camera.

is_streaming()[source]
Returns:True if the Pi Camera network streaming thread is running, False otherwise.
start_preview(**opts)[source]

Start camera preview.

Parameters:opts – Extra options to pass to the camera (see https://www.raspberrypi.org/documentation/usage/camera/python/README.md)
start_recording(video_file=None, directory=None, name_format='video_%04d.h264', duration=None, split_duration=None, **opts)[source]

Start recording to a video file or to multiple video files

Parameters:
  • video_file (str) – Path of the video file, if you want to keep the recording all in one file
  • directory (str) – Path of the directory that will store the video files, if you want to split the recording on multiple files. Note that you need to specify either video_file (to save the recording to one single file) or directory (to split the recording on multiple files)
  • name_format (str) – If you’re splitting the recording to multiple files, then you can specify the name format for those files (default: ‘video_%04d.h264’) on multiple files. Note that you need to specify either video_file (to save the recording to one single file) or directory (to split the recording on multiple files)
  • duration (float) – Video duration in seconds (default: None, record until stop_recording is called)
  • split_duration (float) – If you’re splitting the recording to multiple files, then you should specify how long each video should be in seconds
  • opts – Extra options to pass to the camera (see https://www.raspberrypi.org/documentation/usage/camera/python/README.md)
start_streaming(listen_port: Optional[int] = None, format='h264', **opts)[source]

Start recording to a network stream

Parameters:
start_time_lapse(directory, n_images=None, interval=0, warmup_time=2, resize=None, **opts)[source]

Start a time lapse capture

Parameters:
  • directory (str) – Path where the images will be stored
  • n_images (int) – Number of images to capture (default: None, capture until stop_time_lapse)
  • interval (float) – Interval in seconds between two pictures (default: 0)
  • warmup_time (float) – Time before taking the picture (default: 2 seconds)
  • resize (list or tuple (with two elements)) – Set if you want to resize the picture to a new format
  • opts – Extra options to pass to the camera (see https://www.raspberrypi.org/documentation/usage/camera/python/README.md)
stop_preview()[source]

Stop camera preview.

stop_recording(**kwargs)[source]

Stop a camera recording

stop_streaming()[source]

Stop a camera streaming session

stop_time_lapse()[source]

Stop a time lapse sequence if it’s running

take_picture(image_file, preview=False, warmup_time=2, resize=None, close=True, **opts)[source]

Take a picture.

Parameters:
  • image_file (str) – Path where the output image will be stored.
  • preview (bool) – Show a preview before taking the picture (default: False)
  • warmup_time (float) – Time before taking the picture (default: 2 seconds)
  • resize (list or tuple (with two elements)) – Set if you want to resize the picture to a new format
  • opts – Extra options to pass to the camera (see https://www.raspberrypi.org/documentation/usage/camera/python/README.md)
  • close – If True (default) close the connection to the camera after capturing, otherwise keep the connection open (e.g. if you want to take a sequence of pictures). If you set close=False you should remember to call close when you don’t need the connection anymore.
Returns:

dict:

{"image_file": path_to_the_image}