ImagesSaver
- class lib.image.ImagesSaver(path, queue_size=8, as_bytes=False)
Bases:
ImageIOPerform image saving to a destination folder.
Images are saved in a background ThreadPoolExecutor to allow for concurrent saving. See also
ImageIOfor 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) –
Trueif the image is already encoded to bytes,Falseif the image is anumpy.ndarray. Default:False.
Examples
>>> saver = ImagesSaver('/path/to/save/folder') >>> for filename, image in <image_iterator>: >>> saver.save(filename, image) >>> saver.close()
Attributes Summary
The folder or video that was passed in as the
pathparameter.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
pathparameter.- 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.
Nonefor no subfolder. Default:Nonesub_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.
Nonefor no subfolder. Default:Nonesub_folder (str | None)
- Return type:
None