v2026.11.2
All Bundles
Bundle

OpenCV computer vision library. Image supports loading, saving, resizing, color conversion, blurring, edge detection, cropping, and drawing. VideoCapture reads from files or camera streams. Compile with -lib opencv.

ImageBatch

Decodes a list of image files on several native threads. Every image is loaded as BGR 8-bit (like Image->Load) and resized to size x size when it is not already (like Image->Resize with the default linear interpolation), so the bytes of an image are the same as Image->Load, Resize and Bytes give for it, at any thread count. The decoding runs on worker threads that never touch VM memory: Start returns at once, so a batch can be decoded while the program does other work, and Wait blocks until it is done.

Example

batch := ImageBatch->Start(["a.jpg", "b.jpg", "c.jpg"], 224, 4);
if(batch <> Nil & batch->Wait() = 0) {
  pixels := batch->Get(0);  # 224 x 224 x 3 bytes
};
batch->Close();

Operations

Close #

Frees the batch (waiting for it first if it is still decoding). Safe to call twice.

method : public : Close() ~ Nil

Count #

The number of images in the batch.

method : public : Count() ~ Int

Return

TypeDescription
Intcount

Get #

The pixels of one image, BGR, size x size x 3 bytes. Call Wait first.

method : public : Get(index:Int) ~ Byte[]

Parameters

NameTypeDescription
indexIntimage index

Return

TypeDescription
Bytea copy of the pixels, or Nil if that image could not be decoded or the batch is not finished

Start # function

Starts decoding image files.

function : Start(paths:String[], size:Int, threads:Int) ~ ImageBatch

Parameters

NameTypeDescription
pathsStringimage files, 1 or more
sizeIntevery image is resized to size x size
threadsIntworker threads, 1 to 64 (never more than the number of images)

Return

TypeDescription
ImageBatchthe running batch, or Nil if refused (no paths, a Nil path, a size out of range)

Wait #

Blocks until every image is decoded.

method : public : Wait() ~ Int

Return

TypeDescription
Inthow many images could not be decoded (0 when all were), -1 if the batch was closed