ZipArchive#
- class ZipArchive(filename: str, filter: str | None = None, loop: bool = False, **kwargs: Any)[source]#
Iterate images from a zip archive
- Parameters:
filename (str) – path to zipfile
filter (str) – a Unix shell-style wildcard that specified which files to include when iterating over the archive
kwargs – options applied to image frames, see
convert
The resulting object is an iterator over the files within the zip archive. The iterator returns the file as a
Imageinstance if it is an image (and the name of the file, within the archive, is given by itsnameattribute), else a bytes object containing the file contents.If the path is not absolute, the zip file is first searched for relative to the current directory, and if not found, it is searched for in the
imagesfolder of themvtb-datapackage, installed as a Toolbox dependency.To read just the image files within the archive, use a
filtersuch as"*.png"or"*.pgm". Note thatfilteris a Unix shell style wildcard expression, not a Python regexp.Example:
from machinevisiontoolbox import ZipArchive images = ZipArchive('bridge-l.zip') len(images) for image in images: # iterate over files # process image
alternatively:
image = images[i] # load i'th file from the archive
or using a context manager to ensure the archive is closed:
with ZipArchive('bridge-l.zip') as images: for image in images: # process image
- References:
P. Corke, Robotics, Vision & Control for Python, Springer, 2023, Section 11.1.2.
- Seealso:
Methods
Display images from the source interactively.
List all files within the archive to stdout.
Open a file from the archive
Convert all images from this source into a single 4D PyTorch tensor.
Attributes