Utilities¶
Video reading and writing, and the image helpers the drawing, crop and collage paths use.
Video
¶
Iterate the frames of a file, a camera index, or an RTSP url.
Iteration stops on the first failed read, so a wrong frame count in the container header cannot cut the stream short or hand you empty frames.
Source code in vizor/utils/video.py
Writer
¶
Write frames to a video file. The size is taken from the first frame.
Source code in vizor/utils/video.py
write
¶
Write one BGR frame, opening the file on the first call to read its size.
Source code in vizor/utils/video.py
crop
¶
Cut box out of img with a margin of border x the shorter side.
Returns a BGR view. It can be empty if the box falls outside the frame,
so check .size before feeding it to a model.
Source code in vizor/utils/image.py
label
¶
Class id to string. Works with a list, a dict, or nothing at all.
Source code in vizor/utils/image.py
fit
¶
Resize img to fill a w x h cell without changing its shape.
The spare space is filled with color, so a tall crop of a person comes
back with bars at the sides rather than squashed into a square. Returns a
new array, never a view.
Source code in vizor/utils/image.py
montage
¶
Tile images into one BGR grid, reading left to right, top to bottom.
This is how several crops of one object become a single image a VLM can be
asked about once. The gutters are drawn in color and the letterboxing
inside each cell in fill, two different shades so the model can see
where one crop ends and the next starts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
imgs
|
list[ndarray]
|
BGR arrays. Empty ones are dropped. |
required |
cols
|
int | None
|
columns. Defaults to a square-ish grid. |
None
|
cell
|
int | tuple[int, int]
|
cell size, one number for a square or a |
128
|
pad
|
int
|
gutter in pixels, drawn around the outside as well as between cells. |
4
|
color
|
tuple[int, int, int]
|
gutter colour. |
(0, 0, 0)
|
fill
|
tuple[int, int, int]
|
letterbox colour inside a cell. |
(114, 114, 114)
|