camera.ir.mlx90640
camera.ir.mlx90640
- class platypush.plugins.camera.ir.mlx90640.CameraIrMlx90640Plugin(rawrgb_path: Optional[str] = None, resolution: Tuple[int, int] = (32, 24), warmup_frames: Optional[int] = 5, **kwargs)[source]
Plugin to interact with a ML90640 infrared thermal camera.
In order to use this plugin you’ll need to download and compile the mlx90640 C++ bindings and examples for the device. Instructions on Raspbian:
# Install the dependencies $ [sudo] apt-get install libi2c-dev $ cd $PLATYPUSH_SRC_DIR $ git submodule init $ git submodule update $ cd platypush/plugins/camera/ir/mlx90640/lib $ make clean $ make bcm2835 $ make examples/rawrgb I2C_MODE=LINUX
Requires:
mlx90640-library installation (see instructions above)
PIL image library (
pip install Pillow
)
- __init__(rawrgb_path: Optional[str] = None, resolution: Tuple[int, int] = (32, 24), warmup_frames: Optional[int] = 5, **kwargs)[source]
- Parameters:
rawrgb_path – Specify it if the rawrgb executable compiled from https://github.com/pimoroni/mlx90640-library is in another folder than <directory of this file>/lib/examples.
resolution – Device resolution (default: 32x24).
warmup_frames – Number of frames to be skipped on sensor initialization/warmup (default: 2).
kwargs – Extra parameters to be passed to
platypush.plugins.camera.CameraPlugin
.
- capture(output_file=None, *args, **kwargs)[source]
Back-compatibility alias for
capture_image()
.
- capture_frame(device: 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.
- capture_image(image_file: str, preview: bool = False, **camera) str
Capture an image.
- Parameters:
image_file – Path where the output image will be stored.
camera – Camera parameters override - see constructors parameters.
preview – Show a preview of the camera frames.
- Returns:
The local path to the saved image.
- capture_preview(duration: Optional[float] = None, n_frames: Optional[int] = None, **camera) dict
Start a camera preview session.
- Parameters:
duration – Preview duration (default: until
stop_capture()
is called).n_frames – Number of frames to display before closing (default: until
stop_capture()
is called).camera – Camera object properties.
- Returns:
The status of the device.
- capture_sequence(duration: Optional[float] = None, n_frames: Optional[int] = None, preview: bool = False, **camera) str
Capture a sequence of frames from a camera and store them to a directory.
- Parameters:
duration – Duration of the sequence in seconds (default: until
stop_capture()
is called).n_frames – Number of images to be captured (default: until
stop_capture()
is called).camera – Camera parameters override - see constructors parameters.
frames_dir
andfps
in particular can be specifically tuned forcapture_sequence
.preview – Show a preview of the camera frames.
- Returns:
The directory where the image files have been stored.
- capture_video(duration: Optional[float] = None, video_file: Optional[str] = None, preview: bool = False, **camera) Union[str, dict]
Capture a video.
- Parameters:
duration – Record duration in seconds (default: None, record until
stop_capture
).video_file – If set, the stream will be recorded to the specified video file (default: None).
camera – Camera parameters override - see constructors parameters.
preview – Show a preview of the camera frames.
- Returns:
If duration is specified, the method will wait until the recording is done and return the local path to the recorded resource. Otherwise, it will return the status of the camera device after starting it.
- capturing_thread(camera: Camera, duration: Optional[float] = None, video_file: Optional[str] = None, image_file: Optional[str] = None, n_frames: Optional[int] = None, preview: bool = False, **kwargs)
Camera capturing thread.
- Parameters:
camera – An initialized
platypush.plugins.camera.Camera
object.duration – Capturing session duration in seconds (default: until
stop_capture()
is called).video_file – If set, the session will be recorded to this output video file (video capture mode).
image_file – If set, the output of the session will be a single image file (photo mode).
n_frames – Number of frames to be captured (default: until
stop_capture()
is called).preview – Start a preview window.
kwargs – Extra arguments to be passed to
capture_frame()
.
- static encode_frame(frame, encoding: str = 'jpeg') bytes
Encode a frame to a target type. The default implementation assumes that frame is a
PIL.Image
object.- Parameters:
frame – Image frame (default: a
PIL.Image
object).encoding – Image encoding (e.g.
jpeg
).
- static flip_frame(frame, horizontal_flip: bool = False, vertical_flip: bool = False)
Frame flip logic. Does nothing unless implemented by a derived plugin.
- Parameters:
frame – Image frame (default: a
PIL.Image
object).horizontal_flip – Flip along the horizontal axis.
vertical_flip – Flip along the vertical axis.
- open(device: Optional[Union[int, str]] = None, stream: bool = None, **info) Camera
Initialize and open a device using a context manager pattern.
- Parameters:
device – Capture device by name, path or ID.
stream – If set, the frames will be streamed to
camera.stream
.info – Camera parameters override - see constructors parameters.
- Returns:
The initialized
platypush.plugins.camera.Camera
object.
- open_device(device: Optional[Union[int, str]] = None, stream: bool = False, **params) Camera
Initialize and open a device.
- Returns:
The initialized camera device.
- Raises:
platypush.plugins.camera.CaptureSessionAlreadyRunningException
- 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 rotate_frame(frame, rotation: Optional[Union[int, float]] = None)
Frame rotation logic. The default implementation assumes that frame is a
PIL.Image
object.- Parameters:
frame – Image frame (default: a
PIL.Image
object).rotation – Rotation angle in degrees.
- static scale_frame(frame, scale_x: Optional[float] = None, scale_y: Optional[float] = None)
Frame scaling logic. The default implementation assumes that frame is a
PIL.Image
object.- Parameters:
frame – Image frame (default: a
PIL.Image
object).scale_x – X-scale factor.
scale_y – Y-scale factor.
- start_camera(camera: Camera, preview: bool = False, *args, **kwargs)
Start a camera capture session.
- Parameters:
camera – An initialized
platypush.plugins.camera.Camera
object.preview – Show a preview of the camera frames.
- start_streaming(duration: Optional[float] = None, stream_format: str = 'mkv', **camera) dict
Expose the video stream of a camera over a TCP connection.
- Parameters:
duration – Streaming thread duration (default: until
stop_streaming()
is called).stream_format – Format of the output stream - e.g.
h264
,mjpeg
,mkv
etc. (default:mkv
).camera – Camera object properties - see constructor parameters.
- Returns:
The status of the device.
- status(device: Optional[Union[int, str]] = None)
Returns the status of the specified camera or all the active cameras if
device
isNone
.
- stop_capture(device: Optional[Union[int, str]] = None)
Stop any capturing session on the specified device.
- Parameters:
device – Name/path/ID of the device to stop (default: all the active devices).
- stop_streaming(device: Optional[Union[int, str]] = None)
Stop a camera over TCP session.
- Parameters:
device – Name/path/ID of the device to stop (default: all the active devices).
- static store_frame(frame, filepath: str, format: Optional[str] = None)
Capture a frame to the filesystem using the
PIL
library - it can be overridden by derived classes.- Parameters:
frame – Frame object (default: a byte-encoded object or a
PIL.Image
object).filepath – Destination file.
format – Output format.
- take_picture(image_file: str, preview: bool = False, **camera) str
Alias for
capture_image()
.- Parameters:
image_file – Path where the output image will be stored.
camera – Camera parameters override - see constructors parameters.
preview – Show a preview of the camera frames.
- Returns:
The local path to the saved image.
- to_grayscale(image)[source]
Convert a frame to grayscale. The default implementation assumes that frame is a
PIL.Image
object.- Parameters:
frame – Image frame (default: a
PIL.Image
object).
- static transform_frame(frame, color_transform)
Frame color space (e.g.
RGB24
,YUV
etc.) transform logic. Does nothing unless implemented by a derived plugin.