Raspberry Pi Streaming Camera

Raspberry Pi camera implementation of the PiCameraStreamer class.

NOTES:

Still port used for image capture. Preview port reserved for onboard GPU preview.

Video port:

  • Splitter port 0: Image capture (if use_video_port == True)
  • Splitter port 1: Streaming frames
  • Splitter port 2: Video capture
  • Splitter port 3: [Currently unused]

PiCameraStreamer streams at video_resolution

Camera capture resolution set to stream_resolution in frames()

Video port uses that resolution for everything. If a different resolution is specified for video capture, this is handled by the resizer.

Still capture (if use_video_port == False) uses pause_stream to temporarily increase the capture resolution.

class openflexure_microscope.camera.pi.PiCameraStreamer[source]

Raspberry Pi camera implementation of PiCameraStreamer.

picamera = None

Attached Picamera object

Type:picamerax.PiCamera
image_resolution = None

Resolution for image captures

Type:tuple
stream_resolution = None

Resolution for stream and video captures

Type:tuple
numpy_resolution = None

Resolution for numpy array captures

Type:tuple
jpeg_quality = None

JPEG quality

Type:int
mjpeg_quality = None

MJPEG quality

Type:int
mjpeg_bitrate = None

MJPEG quality

Type:int
configuration

The current camera configuration.

state

The current read-only camera state.

close()[source]

Close the Raspberry Pi PiCameraStreamer.

read_settings() → dict[source]

Return config dictionary of the PiCameraStreamer.

update_settings(config: dict)[source]

Write a config dictionary to the PiCameraStreamer config.

The passed dictionary may contain other parameters not relevant to camera config. Eg. Passing a general config file will work fine.

Parameters:config (dict) – Dictionary of config parameters.
apply_picamera_settings(settings_dict: dict, pause_for_effect: bool = True)[source]
Parameters:
  • settings_dict (dict) – Dictionary of properties to apply to the picamerax.PiCamera: object
  • pause_for_effect (bool) – Pause tactically to reduce risk of timing issues
set_zoom(zoom_value: Union[float, int] = 1.0) → None[source]

Change the camera zoom, handling re-centering and scaling.

start_preview(fullscreen: bool = True, window: Tuple[int, int, int, int] = None)[source]

Start the on board GPU camera preview.

stop_preview()[source]

Stop the on board GPU camera preview.

start_recording(output: Union[str, BinaryIO], fmt: str = 'h264', quality: int = 15)[source]

Start recording.

Start a new video recording, writing to a output object.

Parameters:
  • output – String or file-like object to write capture data to
  • fmt (str) – Format of the capture.
  • quality (int) – Video recording quality.
Returns:

Target object.

Return type:

output_object (str/BytesIO)

stop_recording()[source]

Stop the last started video recording on splitter port 2.

start_stream() → None[source]

Sets the camera resolution to the video/stream resolution, and starts recording if the stream should be active.

stop_stream() → None[source]

Sets the camera resolution to the still-image resolution, and stops recording if the stream is active.

Parameters:splitter_port (int) – Splitter port to stop recording on
capture(output: Union[str, BinaryIO], fmt: str = 'jpeg', use_video_port: bool = False, resize: Tuple[int, int] = None, bayer: bool = True, thumbnail: Tuple[int, int, int] = None)[source]

Capture a still image to a StreamObject.

Defaults to JPEG format. Target object can be overridden for development purposes.

Parameters:
  • output – String or file-like object to write capture data to
  • fmt – Format of the capture.
  • use_video_port – Capture from the video port used for streaming. Lower resolution, faster.
  • resize – Resize the captured image.
  • bayer – Store raw bayer data in capture
  • thumbnail – Dimensions and quality (x, y, quality) of a thumbnail to generate, if supported
Returns:

Target object.

Return type:

output_object (str/BytesIO)

array(use_video_port: bool = True) → numpy.ndarray[source]

Capture an uncompressed still RGB image to a Numpy array.

Parameters:
  • use_video_port (bool) – Capture from the video port used for streaming. Lower resolution, faster.
  • resize ((int, int)) – Resize the captured image.
Returns:

Output array of capture

Return type:

output_array (np.ndarray)