class ImageIO – ImageIO object
The ImageIO class allows you to read/write OpenMV Image objects in their native form to
disk or to memory, providing fast random-access read/write of frames.
- class image.ImageIO(path: str | Tuple[int, int, int], mode: str | int)
Creates an ImageIO object.
If
pathis a string, it is treated as a file path on disk.modemust be'r'to open for reading or'w'to open for writing.If
pathis a 3-value tuple(w, h, pixformat), it is treated as in-memory storage.modeis then the integer number of image buffers (frames) to pre-allocate. The in-memory storage buffer is not allowed to grow after allocation.pixformatis a pixformat constant such asimage.GRAYSCALE,image.RGB565,image.BAYER, orimage.JPEG.- type() int
Returns whether the ImageIO object is a
FILE_STREAMorMEMORY_STREAM.
- version() int | None
Returns the stream version if the object is a
FILE_STREAM. ReturnsNoneforMEMORY_STREAMobjects.
- buffer_size() int | None
Returns the per-frame buffer size in bytes for
MEMORY_STREAMobjects. ReturnsNoneforFILE_STREAMobjects.For memory streams,
buffer_size() * count() == size().
- write(img: Image) ImageIO
Writes
imgto the stream. For file streams, the file grows as new images are appended. For memory streams, the image is written to the current pre-allocated slot before the offset advances.Returns the ImageIO object.
- read(copy_to_fb: bool = True, *, loop: bool = True, pause: bool = True) Image | None
Returns the next image from the stream and advances the offset.
copy_to_fbifTrue, the image is loaded into the frame buffer (likesensor.snapshot()). IfFalse, the image is allocated on the MicroPython heap.loopifTrue, automatically seeks to the beginning of the stream when the end is reached. IfFalse, returnsNoneat end-of-stream (file streams only).pauseifTrue, pauses for the originally recorded inter-frame interval to match the source frame rate.
- seek(offset: int) ImageIO
Seeks to the image slot number
offset. Works for both file and memory streams.Returns the ImageIO object.
- sync() ImageIO
Flushes pending data to disk for file streams. No-op for memory streams.
Returns the ImageIO object.