class StreamingPiCamera2(BaseCamera, ABC): (source)
Known subclasses: openflexure_microscope_server.things.camera.picamera.PiCameraHQ, openflexure_microscope_server.things.camera.picamera.PiCameraV2
Constructor: StreamingPiCamera2(thing_server_interface, camera_num)
A Thing that provides and interface to the Raspberry Pi Camera.
This is an abstract base class for all picamera models. Use a subclass specific to the camera model.
| Method | __enter__ |
Start streaming when the Thing context manager is opened. |
| Method | __exit__ |
Close the picamera connection when the Thing context manager is closed. |
| Method | __init__ |
Initialise the camera with the given camera number. |
| Method | analogue |
The Analogue gain applied by the camera sensor. |
| Method | analogue |
Undocumented |
| Method | auto |
Adjust exposure until a the target white level is reached. |
| Method | calibrate |
Take an image and use it for flat-field correction. |
| Method | capture |
Acquire one image from the camera and return as an array. |
| Method | colour |
Undocumented |
| Method | colour |
The red and blue colour gains, must be between 0.0 and 32.0. |
| Method | colour |
Undocumented |
| Method | discard |
Discard frames so that the next frame captured is fresh. |
| Method | exposure |
The camera exposure time in microseconds. |
| Method | exposure |
Undocumented |
| Method | flat |
Disable flat-field correction. |
| Method | flat |
Disable flat-field correction for colour only. |
| Method | full |
Perform a full auto-calibration. |
| Method | reset |
Overwrite the colour correction matrix in camera tuning with default values. |
| Method | reset |
Revert to default lens shading settings. |
| Method | save |
Override save_settings to ensure that camera properties don't recurse. |
| Method | set |
Set the contrast enhancement to disabled. |
| Method | set |
Set the green equalisation to a static value. |
| Class Variable | mjpeg |
Bitrate for MJPEG stream (None for default). |
| Class Variable | supports |
Undocumented |
| Instance Variable | default |
Undocumented |
| Instance Variable | stream |
Whether the MJPEG stream is active. |
| Instance Variable | streaming |
Undocumented |
| Instance Variable | tuning |
The Raspberry PiCamera Tuning File JSON. |
| Property | calibration |
Whether the camera needs calibrating. |
| Property | camera |
The "configuration" dictionary of the picamera2 object. |
| Property | capture |
Return the metadata from the camera. |
| Property | capture |
Modes the camera can use for capturing. |
| Property | colour |
The colour_correction_matrix from the tuning file. |
| Property | focus |
Return the focus figure of merit. |
| Property | gamma |
Return the gamma correction curve from the tuning file. |
| Property | lens |
The current lens shading (i.e. flat-field correction). |
| Property | manual |
The camera settings to expose as property controls in the settings panel. |
| Property | primary |
The calibration actions for both calibration wizard and settings panel. |
| Property | secondary |
The calibration actions that appear only in settings panel. |
| Property | sensor |
The native resolution of the camera's sensor. |
| Property | streaming |
True if the camera is streaming. |
| Property | streaming |
Modes the camera can stream in. |
| Property | thing |
Update generic camera metadata with Picamera-specific data. |
| Method | _capture |
Acquire one image from the camera and return it as a PIL Image. |
| Method | _create |
Create the dictionary to pass to Picamera2.configure. |
| Method | _ensure |
Ensure in correct mode for capture. |
| Method | _get |
Undocumented |
| Method | _initialise |
Acquire the picamera device and store it as self._picamera. |
| Method | _on |
Undocumented |
| Method | _start |
Start the MJPEG stream. This is where persistent controls are sent to camera. |
| Method | _stop |
Stop the MJPEG stream. |
| Method | _streaming |
Lock access to picamera and return the underlying Picamera2 instance. |
| Class Variable | _camera |
Undocumented |
| Class Variable | _sensor |
Undocumented |
| Instance Variable | _analogue |
Undocumented |
| Instance Variable | _camera |
Undocumented |
| Instance Variable | _colour |
Undocumented |
| Instance Variable | _exposure |
Undocumented |
| Instance Variable | _focus |
Undocumented |
| Instance Variable | _picamera |
Undocumented |
| Instance Variable | _picamera |
Undocumented |
| Instance Variable | _setting |
Undocumented |
Inherited from BaseCamera:
| Method | background |
The name of the active background selector. |
| Method | background |
Validate and set background_detector_name. |
| Method | capture |
Acquire one image from the camera. |
| Method | capture |
Capture an image and save it to disk. |
| Method | capture |
Acquire one image from the camera, downsample, and return as an array. |
| Method | capture |
Capture an image to memory. This can be saved later with save_from_memory. |
| Method | change |
Change the mode the camera is streaming in. |
| Method | clear |
Clear all images in memory. |
| Method | grab |
Acquire one image from the preview stream and return as an array. |
| Method | grab |
Acquire one image from the preview stream and return as blob of JPEG data. |
| Method | grab |
Acquire one image from the preview stream and return its size. |
| Method | image |
Label the current image as either background or sample. |
| Method | kill |
Kill the streams now as the server is shutting down. |
| Method | record |
Record MJPEG stream framerate statistics. |
| Method | save |
Save an image that has been captured to memory. |
| Method | set |
Grab an image, and use its statistics to set the background. |
| Method | settle |
Sleep for the settling time, ready to provide a fresh frame. |
| Async Method | snapshot |
Return a snapshot from the microscope. |
| Class Variable | downsampled |
The downsampling factor when calling capture_downsampled_array. |
| Class Variable | lores |
Undocumented |
| Class Variable | mjpeg |
Undocumented |
| Class Variable | settling |
The settling time when calling the settle() method. |
| Class Variable | supported |
Undocumented |
| Property | background |
The active background detector instance. |
| Method | _add |
Add the EXIF metadata for a JPEG image. |
| Method | _collect |
Return the metadata for a capture. |
| Async Method | _monitor |
Asynchronously monitor the timing on incoming frames. |
| Method | _validate |
Check input capture mode exists, always returns a valid mode. |
| Class Variable | _all |
Undocumented |
| Class Variable | _class |
Undocumented |
| Class Variable | _memory |
Undocumented |
| Instance Variable | _background |
Undocumented |
| Instance Variable | _default |
Undocumented |
| Instance Variable | _framerate |
Undocumented |
Inherited from OFMThing (via BaseCamera):
| Method | create |
Create a RelativeDataPath object with this Thing set as the saving Thing. |
| Property | data |
The data directory for this thing. |
| Property | show |
Whether to show in the Gallery. |
| Class Variable | _show |
Undocumented |
| Instance Variable | _data |
Undocumented |
Start streaming when the Thing context manager is opened.
This opens the picamera connection, initialises the camera, sets the property, and then starts the streams.
type[ BaseException], exc_value: BaseException | None, traceback: TracebackType | None):
(source)
¶
Close the picamera connection when the Thing context manager is closed.
lt.ThingServerInterface, camera_num: int = 0):
(source)
¶
Initialise the camera with the given camera number.
This makes no connection to the camera (except to get the default tuning file).
| Parameters | |
thinglt.ThingServerInterface | The interface between this Thing and the server. |
cameraint | The number of the camera. This should generally be left as 0 as most Raspberry Pi boards only support 1 camera. |
int | None = None, percentile: float = 99.9):
(source)
¶
Adjust exposure until a the target white level is reached.
Starting from the minimum exposure, gradually increase exposure until the image reaches the specified white level.
| Parameters | |
targetint | None | Raw target white level, this should be an integer within the range set by the bit-depth of the camera sensor (10-bit for PiCamera v2, 12 Bit for Picamera HQ. If None the default will be used for the current sensor. This is approximately 40% saturated, but after gamma curve is applied, the pixel values will have a value around 200. |
percentile:float | The percentile to use instead of maximum. Default 99.9. When calculating the brightest pixel, a percentile is used rather than the maximum in order to be robust to a small number of noisy/bright pixels. |
Take an image and use it for flat-field correction.
This method requires an empty (i.e. bright) field of view. It will take a raw image and effectively divide every subsequent image by the current one. This uses the camera's "tuning" file to correct the preview and the processed images. It should not affect raw images.
str = 'standard', raw: bool = False) -> NDArray:
(source)
¶
Acquire one image from the camera and return as an array.
This function will produce a nested list containing an uncompressed RGB image. It's likely to be highly inefficient - raw and/or uncompressed captures using binary image formats will be added in due course.
| Parameters | |
capturestr | (Optional) The name of the capture mode as defined by the camera. |
raw:bool | Whether to capture RAW data. Capturing RAW data may ignore some of the camera mode settings. |
| Returns | |
NDArray | Undocumented |
| Raises | |
TimeoutError | if this time is exceeded during capture. |
tuple[ float, float, float, float, float, float, float, float, float]):
(source)
¶
Undocumented
The camera exposure time in microseconds.
When setting this property the camera will adjust the set value to the nearest allowed value that is lower than the current setting.
Disable flat-field correction.
This method will set a completely flat lens shading table. It is not the same as the default behaviour, which is to use an adaptive lens shading table.
This flat table is used to take an image with no lens shading so that the correct lens shading table can be calibrated.
Disable flat-field correction for colour only.
This method will set the chrominance of the lens shading table to be flat, i.e. we'll correct vignetting of intensity, but not any change in colour across the image.
Perform a full auto-calibration.
This function will call the other calibration actions in sequence:
- flat_lens_shading to disable flat-field
- auto_expose_from_minimum
- set_static_green_equalisation to set geq offset to max
- calibrate_lens_shading (also sets colour gains for white balance)
- set_background
Revert to default lens shading settings.
This method will restore the default "adaptive" lens shading method used by the Raspberry Pi camera.
Override save_settings to ensure that camera properties don't recurse.
This method is run by any Thing when a setting is saved. However, the method reads the setting. As reading the setting talks to the camera and calls save_settings if the value is not as expected, this could cause recursion. Also this means that saving one setting causes all others to be read each time.
Set the contrast enhancement to disabled.
Adaptive contrast enhancement modifies settings to adapt to each field of view, causing inconsistent settings when capturing.
Set the green equalisation to a static value.
Green equalisation avoids the debayering algorithm becoming confused by the two green channels having different values, which is a problem when the chief ray angle isn't what the sensor was designed for, and that's the case in e.g. a microscope using camera module v2.
A value of 0 here does nothing, a value of 65535 is maximum correction.
The "configuration" dictionary of the picamera2 object.
The "configuration" sets the resolution and format of the camera's streams. Together with the "tuning" it determines how the sensor is configured and how the data is processed.
Note that the configuration may be modified when taking still images, and this property refers to whatever configuration is currently in force - usually the one used for the preview stream.
openflexure_microscope_server.things.camera.picamera.PiCameraHQ, openflexure_microscope_server.things.camera.picamera.PiCameraV2Modes the camera can use for capturing.
tuple[ float, float, float, float, float, float, float, float, float] =
(source)
¶
The colour_correction_matrix from the tuning file.
This is broken out into its own property for convenience and compatibility with the micromanager API
It is a 9 value tuple used to specify the 3x3 matrix that the GPU pipeline uses to convert from the camera R,G,B vector to the standard R,G,B.
The current lens shading (i.e. flat-field correction).
Return the current lens shading correction, as three 2D lists each with dimensions 16x12.
The colour temperature is returned. If the colour temperature us 5000 then this means the lens shading tables have been calibrated (with our illumination which has a 5000k colour temperature). Other numbers are set when flatening or resetting the table.
openflexure_microscope_server.things.camera.picamera.PiCameraHQ, openflexure_microscope_server.things.camera.picamera.PiCameraV2Modes the camera can stream in.
Acquire one image from the camera and return it as a PIL Image.
| Parameters | |
capturestr | The capture mode to use. See the description field of each mode in capture_modes for more detail. |
| Returns | |
Image.Image | Undocumented |
| Raises | |
TimeoutError | if this time is exceeded during capture. |
Picamera2, controls: dict[ str, Any], mode_info: PiCamera2StreamingMode) -> dict[ str, Any]:
(source)
¶
Create the dictionary to pass to Picamera2.configure.
| Parameters | |
picam:Picamera2 | Undocumented |
controls:dict[ | The controls for the camera. Note that running _get_persistent_controls() should be done before getting the picamera lock to ensure that the current settings are read from the camera. |
modePiCamera2StreamingMode | Undocumented |
| Returns | |
dict[ | Undocumented |
PiCamera2CaptureMode) -> Iterator[ Picamera2]:
(source)
¶
Ensure in correct mode for capture.
If the camera is already in the correct mode, the stream isn't paused and this is the same as using self._streaming_picamera().
Otherwise, pause stream, and switch mode. Mode is reset and stream restarts after the context manager closes.
Acquire the picamera device and store it as self._picamera.
This duplicates logic in Picamera2.__init__ to provide a tuning file that will be read when the camera system initialises.
| Parameters | |
checkbool | Set to true to check the sensor model is the expected sensor model. This is used on __enter__ to confirm that the real camera matches the expected camera. |
| Raises | |
PicameraModelError | If check_sensor_model is True and the real camera sensor model doesn't match the expected sensor model. |
Start the MJPEG stream. This is where persistent controls are sent to camera.
Sets the camera stream resoltuons based on input mode
Create two streams:
- lores_mjpeg_stream for autofocus at lores_resolution
- mjpeg_stream for preview. This is at the main_resolution unless
- use_lores_as_preview is True, in which case it is a copy of lores_mjpeg_stream
bool = False) -> Iterator[ Picamera2]:
(source)
¶
Lock access to picamera and return the underlying Picamera2 instance.
Optionally the stream can be paused to allow updating the camera settings.
| Parameters | |
pausebool | If False the Picamera2 instance is simply yielded. If True:
|
| Returns | |
Iterator[ | Undocumented |