ImagesSaver

class lib.image.ImagesSaver(path, queue_size=8, as_bytes=False)

Bases: ImageIO

Perform image saving to a destination folder.

Images are saved in a background ThreadPoolExecutor to allow for concurrent saving. See also ImageIO for additional attributes.

Parameters:
  • path (str) – The folder to save images to. This must be an existing folder.

  • queue_size (int, optional) – The amount of images to hold in the internal buffer. Default: 8.

  • as_bytes (bool, optional) – True if the image is already encoded to bytes, False if the image is a numpy.ndarray. Default: False.

Examples

>>> saver = ImagesSaver('/path/to/save/folder')
>>> for filename, image in <image_iterator>:
>>>     saver.save(filename, image)
>>> saver.close()

Attributes Summary

location

The folder or video that was passed in as the path parameter.

Methods Summary

close()

Signal to the Save Threads that they should be closed and cleanly shutdown the saver

save(filename, image[, sub_folder])

Save the given image in the background thread

Attributes Documentation

location

The folder or video that was passed in as the path parameter.

Type:

str

Methods Documentation

close()

Signal to the Save Threads that they should be closed and cleanly shutdown the saver

save(filename: str, image: bytes | ndarray, sub_folder: str | None = None) None

Save the given image in the background thread

Ensure that close() is called once all save operations are complete.

Parameters:
  • filename (str) – The filename of the image to be saved. NB: Any folders passed in with the filename will be stripped and replaced with location.

  • image (bytes) – The encoded image to be saved

  • subfolder (str, optional) – If the file should be saved in a subfolder in the output location, the subfolder should be provided here. None for no subfolder. Default: None

  • sub_folder (str | None)

Return type:

None

close()

Signal to the Save Threads that they should be closed and cleanly shutdown the saver

save(filename: str, image: bytes | ndarray, sub_folder: str | None = None) None

Save the given image in the background thread

Ensure that close() is called once all save operations are complete.

Parameters:
  • filename (str) – The filename of the image to be saved. NB: Any folders passed in with the filename will be stripped and replaced with location.

  • image (bytes) – The encoded image to be saved

  • subfolder (str, optional) – If the file should be saved in a subfolder in the output location, the subfolder should be provided here. None for no subfolder. Default: None

  • sub_folder (str | None)

Return type:

None