class BaseCamera(lt.Thing): (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 |
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 a PIL image from stream stream_name with timeout wait. |
| Method | capture |
Acquire one image from the camera as a JPEG. |
| Method | capture |
Capture an image to memory. This can be saved later with save_from_memory. |
| 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 | 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. |
| Method | start |
Start (or stop and restart) the camera. |
| 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. |
| Property | background |
The active background detector instance. |
| Property | calibration |
Whether the camera needs calibrating. |
| 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 | thing |
Empty metadata dict for subclasses to populate. |
| Method | _add |
Add the EXIF metadata for a JPEG image. |
| Method | _capture |
Return the metadata for a capture, from the thing states, time and known names. |
| Method | _robust |
Capture an image in memory and return it with metadata. |
| Method | _save |
Save the captured image and metadata to disk. |
| Class Variable | _all |
Undocumented |
| Class Variable | _memory |
Undocumented |
| Instance Variable | _background |
Undocumented |
| Instance Variable | _default |
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, save_resolution: tuple[ int, int] | None = None):
(source)
¶
Capture an image and save it to disk.
| Parameters | |
jpegstr | The path to save the file to |
savetuple[ | can be set to resize the image before saving. By default this is None meaning that the image is saved at original resolution. |
Literal[ 'main', 'lores', 'raw', 'full'] = 'main', wait: float | None = 5) -> 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 downsamples 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.
Literal[ 'main', 'lores', 'full'], wait: float | None = None) -> Image.Image:
(source)
¶
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 stream stream_name with timeout wait.
Literal[ 'main', 'lores', 'full'] = 'main', wait: float | None = None) -> JPEGBlob:
(source)
¶
Acquire one image from the camera as a JPEG.
This will use the internal capture image functionally of capture_image of the specific camera being used.
| Parameters | |
streamLiteral[ | A stream name supported by this camera. |
wait:float | None | (Optional, float) Set a timeout in seconds. If None it will use the default for the underlying camera. |
| Returns | |
JPEGBlob | Undocumented |
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 | |
bufferint | The maximum number of images that should be in the buffer once this images is added. Default is 1. |
| Returns | |
int | the buffer id of the image captured |
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_array in that it does not pause the MJPEG preview stream.
Literal[ 'main', 'lores'] = 'main') -> JPEGBlob:
(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_jpeg 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.
str, save_resolution: tuple[ int, int] | None = None, buffer_id: int | None = None):
(source)
¶
Save an image that has been captured to memory.
| Parameters | |
jpegstr | The path to save the file to |
savetuple[ | can be set to resize the image before saving. By default this is None meaning that the image is saved at original resolution. |
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.
tuple[ int, int] = (int = 1):
(source)
¶
openflexure_microscope_server.things.camera.picamera.StreamingPiCamera2, openflexure_microscope_server.things.camera.simulation.SimulatedCameraStart (or stop and restart) the camera.
Note that the default values for both parameters should be set appropriately for the specific camera when defining a new Camera Thing.
| Parameters | |
maintuple[ | the resolution to use for the main stream. |
bufferint | number of images in the stream buffer. |
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.
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.
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
Capture an image in memory and return it with metadata.
This robust capturing method attempts to capture the image five times each time with a 5 second timeout set.
| Returns | |
tuple[ | tuple with PIL Image, and dictionary of metadata. |
| Raises | |
CaptureError | if the capture fails for any reason |
str, image: Image.Image, metadata: Mapping[ str, Any], save_resolution: tuple[ int, int] | None = None):
(source)
¶
Save the captured image and metadata to disk.
A warning is logged if metadata cannot be added.
nothing is returned on success
| Raises | |
IOError | if the file cannot be saved |