class documentation

class CameraMemoryBuffer: (source)

Constructor: CameraMemoryBuffer()

View In Hierarchy

A class that holds images in memory. The images are by default PIL images.

However subclasses of BaseCamera can use this class to store other object types.

Method __init__ Create the buffer instance.
Method add_image Add an image to the Memory buffer.
Method clear Clear all images from memory.
Method get_image Return the image with the given id.
Method _create_space Create space to add an image.
Instance Variable _latest_id Undocumented
Instance Variable _storage Undocumented
def __init__(self): (source)

Create the buffer instance.

def add_image(self, image: Any, metadata: dict | None = None, buffer_max: int = 1) -> int: (source)

Add an image to the Memory buffer.

This will add an image to the memory buffer. By default the buffer will be cleared. To allow saving multiple images the buffer_max must be set every time an image is added.

Parameters
image:AnyThe image to add. A PIL image is recommended, but cameras can choose to use other formats
metadata:dict | NoneOptional, a dictionary of the image metadata.
buffer_max:intThe maximum number of images that should be in the buffer once this images is added. Default is 1.
Returns
intThe id in the buffer for this image
def clear(self): (source)

Clear all images from memory.

def get_image(self, buffer_id: int | None = None, remove: bool = True) -> tuple[Any, dict | None]: (source)

Return the image with the given id.

If no id is given the most recent image is returned. However, the buffer is also cleared, otherwise it would be possible to accidentally retrieve images out of order.

Parameters
buffer_id:int | NoneThe buffer id of the image to retrieve
remove:boolTrue (default) to remove this image from the buffer, False to leave the image in the buffer.
Returns
tuple[Any, dict | None]Undocumented
def _create_space(self, buffer_max: int): (source)

Create space to add an image.

Parameters
buffer_max:intThe maximum number of images that should be in the buffer once another images is added.
_latest_id: int = (source)

Undocumented

_storage: dict[int, tuple[Any, dict | None]] = (source)

Undocumented