class BaseCamera(OFMThing, ABC): (source)
Known subclasses: openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCamera
Constructor: BaseCamera(thing_server_interface)
The base class for all cameras. All cameras must directly inherit from this class.
The connection to the camera hardware should be added to the __enter__ method not __init__ method of the subclass.
| Method | __enter__ |
Open hardware connection when the Thing context manager is opened. |
| Method | __exit__ |
Close hardware connection when the Thing context manager is closed. |
| Method | __init__ |
Initialise the base camera, this creates the background detectors. |
| 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 and return as an array. |
| 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 | discard |
Discard frames so that the next frame captured is fresh. |
| 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 | streaming |
Undocumented |
| Class Variable | supported |
Undocumented |
| Class Variable | supports |
Undocumented |
| Property | background |
The active background detector instance. |
| Property | calibration |
Whether the camera needs calibrating. |
| Property | capture |
Modes the camera can use for capturing. |
| Property | focus |
Return the focus figure of merit. |
| 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 | stream |
Whether the MJPEG stream is active. |
| Property | streaming |
Modes the camera can stream in. |
| Property | thing |
Return camera-specific metadata. |
| Method | _add |
Add the EXIF metadata for a JPEG image. |
| Method | _capture |
Capture a PIL image from the camera. |
| Method | _collect |
Return the metadata for a capture. |
| Async Method | _monitor |
Asynchronously monitor the timing on incoming frames. |
| Method | _start |
Start (or stop and restart) the camera. |
| 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:
| 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 |
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraOpen hardware connection when the Thing context manager is opened.
type[ BaseException], _exc_value: BaseException | None, _traceback: TracebackType | None):
(source)
¶
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraClose hardware connection when the Thing context manager is closed.
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraInitialise the base camera, this creates the background detectors.
This must be run by all child camera classes.
To add a new background detector to the server it must be added to the dictionary in this function. Configuration will be added at a later date.
str = 'standard', image_format: str = 'jpeg', retain_image: bool = True) -> lt.blob.Blob:
(source)
¶
Acquire one image from the camera.
This will use the internal capture image functionally of _capture_image of the specific camera being used.
| Parameters | |
capturestr | The mode to use, must be one of capture_modes. |
imagestr | The image format to use, must be one of supported_image_formats |
retainbool | (Default True) True to save image to the microscope, False to only save temporarily for transfer. |
| Returns | |
lt.blob.Blob | A LabThings Blob that with access to the captured file. |
RelativeDataPath, capture_mode: str = 'standard'):
(source)
¶
Capture an image and save it to disk.
This is not an action as it exposes a direct path for saving
| Parameters | |
path:RelativeDataPath | The path to save the file to, this should be a RelativeDataPath object. If the saving Thing is not set for the path, the camera's data directory will be used. |
capturestr | (Optional) The name of the capture mode as defined by the camera. |
@lt.action
str = 'standard', raw: bool = False) -> NDArray:
(source)
¶
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraAcquire one image from the camera and return as an array.
Acquire one image from the camera, downsample, and return as an array.
- The array is downsampled by the thing property
downsampled_array_factor. - The default capture array arguments are used.
This method provides the interface expected by the camera_stage_mapping.
str = 'standard', buffer_max: int = 1, max_attempts: int = 5) -> int:
(source)
¶
Capture an image to memory. This can be saved later with save_from_memory.
Note that only one image is held in memory so this will overwrite any image in memory.
| Parameters | |
capturestr | Undocumented |
bufferint | The maximum number of images that should be in the buffer once this images is added. Default is 1. |
maxint | The maximum number of times to attempt the capture. |
| Returns | |
int | the buffer id of the image captured |
Change the mode the camera is streaming in.
When creating a subclass. Subclass the method _start_streaming rather than this method.
| Parameters | |
mode:str | Must be a key from streaming_modes |
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraDiscard frames so that the next frame captured is fresh.
Literal[ 'main', 'lores'] = 'main') -> NDArray:
(source)
¶
Acquire one image from the preview stream and return as an array.
It works like grab_jpeg but reliably handles broken streams. Prefer using this method over directly grabbing the frame and converting to a numpy array via PIL.
This differs from capture_as_array in that it does not pause the MJPEG preview stream.
Literal[ 'main', 'lores'] = 'main') -> lt.blob.Blob:
(source)
¶
Acquire one image from the preview stream and return as blob of JPEG data.
Note: in rare cases the JPEG stream may be broken. This can cause an OS error when loading the image. If loading with PIL, as long as the header data is complete, this error will not be raised until the data is accessed. Consider using grab_jpeg_as_array instead.
This differs from capture in that it does not pause the MJPEG preview stream. Instead, we simply return the next frame from that stream (either "main" for the preview stream, or "lores" for the low resolution preview). No metadata is returned.
Literal[ 'main', 'lores'] = 'main') -> int:
(source)
¶
Acquire one image from the preview stream and return its size.
Kill the streams now as the server is shutting down.
This is called when uvicorn gets the a shutdown signal. As this is called from the event loop it cannot interact with the our ThingProperties or run self.mjpeg_stream.stop() as the portal cannot be called from this loop.
Instead we just set the _streaming value to False. This stops the async frame generator when the next frame notifies.
RelativeDataPath, buffer_id: int | None = None):
(source)
¶
Save an image that has been captured to memory.
Note this is not exposed as an action as it allows arbitrary paths on disk to be written to.
| Parameters | |
path:RelativeDataPath | The path to save the file to |
bufferint | None | The buffer id of the image to save, this was returned by capture_to_memory |
Grab an image, and use its statistics to set the background.
This should be run when the microscope is looking at an empty region, and will calculate the mean and standard deviation of the pixel values in the LUV colourspace. These values will then be used to compare future images to the distribution, to determine if each pixel is foreground or background.
Sleep for the settling time, ready to provide a fresh frame.
This function will sleep for the given time, and clear the buffer after sleeping. As such, the next frame captured from the camera after running this function will always be captured after settling.
This method provides the interface expected by the camera_stage_mapping.
Response:
(source)
¶
Return a snapshot from the microscope.
openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraWhether the camera needs calibrating.
This always returns False in BaseCamera. It should be reimplemented by child classes if calibration is required.
Return the focus figure of merit.
This returns a NotImplementedError if not supported by the camera. To use, requires self.supports_focus_fom to be set to True.
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraThe camera settings to expose as property controls in the settings panel.
openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraThe calibration actions for both calibration wizard and settings panel.
openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraThe calibration actions that appear only in settings panel.
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraWhether the MJPEG stream is active.
Return camera-specific metadata.
By default, this just adds the subclass name as the camera type. Subclasses can extend by overriding this property and calling super().thing_state.
Add the EXIF metadata for a JPEG image.
This adds: - UserComment (JSON-encoded metadata from the Things) - Capture time (DateTimeOriginal, DateTimeDigitized, 0th DateTime) - Camera Make and Model
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraCapture a PIL image from the camera.
This unlike the grab_* methods this may pause the stream or temporarily switch streaming mode to capture the image if required by the mode.
Return the metadata for a capture.
This is information from the thing states, the time, and make/model names.
float, sample_interval: float = 0.1) -> tuple[ float, int, list[ dict[ str, float | int]]]:
(source)
¶
Asynchronously monitor the timing on incoming frames.
openflexure_microscope_server.things.camera.opencv.OpenCVCamera, openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraStart (or stop and restart) the camera.