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.

camera = None

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
picamera_lst_path = None

Path of .npy lens shading table file

Type:str
configuration

The current camera configuration.

state

The current read-only camera state.

initialisation()[source]

Run any initialisation code when the frame iterator starts.

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: float = 1.0) → None[source]

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

start_preview(fullscreen=True, window=None)[source]

Start the on board GPU camera preview.

stop_preview()[source]

Stop the on board GPU camera preview.

start_recording(output, 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.

stop_stream_recording(splitter_port: int = 1, **kwargs) → 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
start_stream_recording(splitter_port: int = 1, **kwargs) → None[source]

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

Parameters:splitter_port (int) – Splitter port to start recording on
capture(output, fmt: str = 'jpeg', use_video_port: bool = False, resize: Tuple[int, int] = None, bayer: bool = True, thumbnail: tuple = 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 (str) – Format of the capture.
  • use_video_port (bool) – Capture from the video port used for streaming. Lower resolution, faster.
  • resize ((int, int)) – Resize the captured image.
  • bayer (bool) – Store raw bayer data in capture
Returns:

Target object.

Return type:

output_object (str/BytesIO)

array(use_video_port=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)

wait_for_camera(timeout=5)[source]

Wait for camera object, with 5 second timeout.

frames()[source]

Create generator that returns frames from the camera.

Records video from port 1 to a byte stream, and iterates sequential frames.