Base Streaming Camera

class openflexure_microscope.camera.base.TrackerFrame(size, time)[source]
size

Alias for field number 0

time

Alias for field number 1

class openflexure_microscope.camera.base.FrameStream(*args, **kwargs)[source]

A file-like object used to analyse and stream MJPEG frames.

Instead of analysing a load of real MJPEG frames after they’ve been stored in a BytesIO stream, we tell the camera to write frames to this class instead.

We then do analysis as the frames are written, and discard old frames as each new frame is written.

start_tracking()[source]

Start tracking frame sizes

stop_tracking()[source]

Stop tracking frame sizes

reset_tracking()[source]

Empty the array of tracked frame sizes

write(s)[source]

Write a new frame to the FrameStream. Does a few things: 1. If tracking frame size, store the size in self.frames 2. Rewind and truncate the stream (delete previous frame) 3. Store the new frame image 4. Set the new_frame event

getvalue() → bytes[source]

Clear tne new_frame event and return frame data

getframe() → bytes[source]

Wait for a new frame to be available, then return it

class openflexure_microscope.camera.base.BaseCamera[source]

Base implementation of StreamingCamera.

lock = None

Access lock for the camera

Type:labthings.StrictLock
stream = None

Streaming and analysis frame buffer

Type:FrameStream
configuration

The current camera configuration.

state

The current read-only camera state.

start_stream()[source]

Ensure the frame stream is actively running

stop_stream()[source]

Stop the active stream, if possible

update_settings(config: dict)[source]

Update settings from a config dictionary

read_settings() → dict[source]

Return the current settings as a dictionary

capture(output: Union[str, BinaryIO], fmt: str = 'jpeg', use_video_port: bool = False, resize: Optional[Tuple[int, int]] = None, bayer: bool = True, thumbnail: Optional[Tuple[int, int, int]] = None)[source]

Perform a basic capture to output

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
start_worker(**_) → bool[source]

Start the background camera thread if it isn’t running yet.

get_frame() → bytes[source]

Return the current camera frame.

Just an alias of self.stream.getframe()

close()[source]

Close the BaseCamera and all attached StreamObjects.