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() ~ NilCount #
The number of images in the batch.
method : public : Count() ~ IntReturn
| Type | Description |
|---|---|
| Int | count |
Get #
The pixels of one image, BGR, size x size x 3 bytes. Call Wait first.
method : public : Get(index:Int) ~ Byte[]Parameters
| Name | Type | Description |
|---|---|---|
| index | Int | image index |
Return
| Type | Description |
|---|---|
| Byte | a 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) ~ ImageBatchParameters
| Name | Type | Description |
|---|---|---|
| paths | String | image files, 1 or more |
| size | Int | every image is resized to size x size |
| threads | Int | worker threads, 1 to 64 (never more than the number of images) |
Return
| Type | Description |
|---|---|
| ImageBatch | the running batch, or Nil if refused (no paths, a Nil path, a size out of range) |