v2026.5.3
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.

Image

OpenCV image

Operations

AdaptiveThreshold #

Applies an adaptive threshold to an array

method : public : AdaptiveThreshold(maxval:Float, adaptive_method:Int, threshold_type:Int, block_size:Int, C:Float) ~ Image

Parameters

NameTypeDescription
maxvalFloatnon-zero value assigned to pixels that satisfy the condition
adaptive_methodIntadaptive thresholding algorithm (0=MEAN_C, 1=GAUSSIAN_C)
threshold_typeIntthreshold type (must be BINARY or BINARY_INV)
block_sizeIntsize of the pixel neighborhood (must be odd and greater than 1)
CFloatconstant subtracted from the mean or weighted mean

Return

TypeDescription
Imagethresholded image

BilateralFilter #

Applies bilateral filter to the image

method : public : BilateralFilter(d:Int, sigmaColor:Float, sigmaSpace:Float) ~ Image

Parameters

NameTypeDescription
dIntdiameter of each pixel neighborhood
sigmaColorFloatfilter sigma in the color space
sigmaSpaceFloatfilter sigma in the coordinate space

Return

TypeDescription
Imagefiltered image

BoundingRect # function

Computes the bounding rectangle for a single contour.

function : BoundingRect(contours:Int[], index:Int) ~ Rect

Parameters

NameTypeDescription
contoursIntpacked contour data from FindContours()
indexIntindex of the contour

Return

TypeDescription
Rectbounding rectangle

Bytes #

Gets image bytes

method : public : Bytes() ~ Byte[]

Return

TypeDescription
Byteimage bytes

Canny #

Applies Canny edge detection

method : public : Canny(threshold1:Float, threshold2:Float) ~ Image

Parameters

NameTypeDescription
threshold1Floatfirst threshold for hysteresis procedure
threshold2Floatsecond threshold for hysteresis procedure

Return

TypeDescription
Imageedge-detected image

Example

image := Image->Load("photo.jpg");
gray := image->CvtColor(6);
edges := gray->Canny(50.0, 150.0);
edges->Save("edges.png");

Clone #

Creates a deep copy of the image

method : public : Clone() ~ Image

Return

TypeDescription
Imagecloned image

Columns #

Gets image columns

method : public : Columns() ~ Int

Return

TypeDescription
Intimage columns

ContourArea # function

Computes the area of a single contour.

function : ContourArea(contours:Int[], index:Int) ~ Float

Parameters

NameTypeDescription
contoursIntpacked contour data from FindContours()
indexIntindex of the contour

Return

TypeDescription
Floatarea of the contour

Convert #

Convert an image to a given byte format

method : public : Convert(format:Image->Format) ~ Byte[]

Parameters

NameTypeDescription
formatImage->Formatoutput format

Return

TypeDescription
Byteconverted image bytes

Example

image := Image->Load("photo.jpg");
png_bytes := image->Convert(Image->Format->PNG);
"PNG bytes: {$png_bytes->Size()}"->PrintLine();

Crop #

Crops an image using a rectangle region of interest

method : public : Crop(rect:Rect) ~ Image

Parameters

NameTypeDescription
rectRectbounding rectangle for the crop region

Return

TypeDescription
Imagecropped image

Example

image := Image->Load("photo.jpg");
region := Rect->New(10, 10, 200, 150);
cropped := image->Crop(region);
cropped->Save("cropped.jpg");

CvtColor #

Converts image color space

method : public : CvtColor(code:Int) ~ Image

Parameters

NameTypeDescription
codeIntcolor conversion code from ColorConversionCodes

Return

TypeDescription
Imageconverted image

Example

image := Image->Load("photo.jpg");
gray := image->CvtColor(6);
gray->Save("gray.png");

Dilate #

Dilates an image using a structuring element

method : public : Dilate(shape:Int, ksize_w:Int, ksize_h:Int) ~ Image

Parameters

NameTypeDescription
shapeIntstructuring element shape from MorphShapes
ksize_wIntkernel width
ksize_hIntkernel height

Return

TypeDescription
Imagedilated image

DrawCircle #

Draws a bounding circle

method : public : DrawCircle(pt:Point, radius:Int, color:Scalar, thickness:Int, type:LineType) ~ API.OpenCV.Image

Parameters

NameTypeDescription
ptPointcircle center
radiusIntcircle radius
colorScalarbounding circle color
thicknessIntbounding circle thickness
typeLineTypebounding circle type

Return

TypeDescription
Imageupdated image

DrawContours #

Draws contours on the image.

method : public : DrawContours(contours:Int[], contourIdx:Int, color:Scalar, thickness:Int) ~ Image

Parameters

NameTypeDescription
contoursIntpacked contour data from FindContours()
contourIdxIntindex of contour to draw, or -1 to draw all contours
colorScalardrawing color
thicknessIntline thickness (default 1)

Return

TypeDescription
Imageimage with contours drawn

DrawRectangle #

Draws a bounding rectangle

method : public : DrawRectangle(rect:Rect, color:Scalar, thickness:Int, type:LineType) ~ API.OpenCV.Image

Parameters

NameTypeDescription
rectRectbounding rectangle
colorScalarbounding rectangle color
thicknessIntbounding rectangle thickness
typeLineTypebounding rectangle type

Return

TypeDescription
Imageupdated image

Example

image := Image->Load("photo.jpg");
box := Rect->New(50, 50, 100, 80);
red := Scalar->New(0.0, 0.0, 255.0);
annotated := image->DrawRectangle(box, red, 2);
annotated->Save("annotated.jpg");

DrawText #

Draws text on an image

method : public : DrawText(text:String, font:Font, color:Scalar, thickness:Int, type:LineType) ~ API.OpenCV.Image

Parameters

NameTypeDescription
textStringtext to draw
fontFonttext font
colorScalarbounding circle color
thicknessIntbounding circle thickness
typeLineTypebounding circle type

Return

TypeDescription
Imageupdated image

Example

image := Image->Load("photo.jpg");
white := Scalar->New(255.0, 255.0, 255.0);
labeled := image->DrawText("Hello!", Point->New(10, 30), Font->FONT_HERSHEY_SIMPLEX, 1.0, white);
labeled->Save("labeled.jpg");

Erode #

Erodes an image using a structuring element

method : public : Erode(shape:Int, ksize_w:Int, ksize_h:Int) ~ Image

Parameters

NameTypeDescription
shapeIntstructuring element shape from MorphShapes
ksize_wIntkernel width
ksize_hIntkernel height

Return

TypeDescription
Imageeroded image

FindContours #

Finds contours in a binary image. The image should be single-channel (e.g., after CvtColor to grayscale and Threshold). Returns a packed Int[] with format: [count, size0..sizeN-1, x0,y0,x1,y1,...]. Use ContourArea() and BoundingRect() to analyze individual contours.

method : public : FindContours(mode:Int, approx:Int) ~ Int[]

Parameters

NameTypeDescription
modeIntcontour retrieval mode from RetrievalModes
approxIntcontour approximation method from ContourApproximationModes

Return

TypeDescription
Intpacked Int[] representing the detected contours

Flip #

Flips an image

method : public : Flip(flipCode:Int) ~ Image

Parameters

NameTypeDescription
flipCodeInt0 for vertical, 1 for horizontal, -1 for both

Return

TypeDescription
Imageflipped image

Example

image := Image->Load("photo.jpg");
mirrored := image->Flip(1);
mirrored->Save("mirrored.jpg");

GaussianBlur #

Applies Gaussian blur to the image

method : public : GaussianBlur(ksize_w:Int, ksize_h:Int, sigmaX:Float) ~ Image

Parameters

NameTypeDescription
ksize_wIntkernel width (must be odd)
ksize_hIntkernel height (must be odd)
sigmaXFloatGaussian kernel standard deviation in X direction

Return

TypeDescription
Imageblurred image

Example

image := Image->Load("photo.jpg");
blurred := image->GaussianBlur(5, 5, 1.5);
blurred->Save("blurred.jpg");

GetRotationMatrix2D # function

Computes a 2D rotation matrix for an affine transformation.

function : GetRotationMatrix2D(center_x:Float, center_y:Float, angle:Float, scale:Float) ~ Float[]

Parameters

NameTypeDescription
center_xFloatx-coordinate of the rotation center
center_yFloaty-coordinate of the rotation center
angleFloatrotation angle in degrees (positive counter-clockwise)
scaleFloatisotropic scale factor

Return

TypeDescription
Float6-element Float[] representing the 2x3 rotation matrix

IsEmpty #

Determines if an image is empty

method : public : IsEmpty() ~ Bool

Return

TypeDescription
Booltrue if empty, false otherwise

Load # function

Load image from file

function : Load(image_path:String) ~ API.OpenCV.Image

Parameters

NameTypeDescription
image_pathStringimage file path

Return

TypeDescription
Imageloaded image

Example

image := Image->Load("photo.jpg");
if(<>image->IsEmpty()) {
  "Loaded: {$image->Columns()}x{$image->Rows()}"->PrintLine();
};

Load # function

Load image from bytes

function : Load(image_bytes:Byte[]) ~ API.OpenCV.Image

Parameters

NameTypeDescription
image_bytesByteraw image bytes

Return

TypeDescription
Imageloaded image

Example

raw := System.IO.Filesystem.FileReader->ReadBinaryFile("photo.jpg");
image := Image->Load(raw);
"Rows: {$image->Rows()}, Cols: {$image->Columns()}"->PrintLine();

MedianBlur #

Applies median blur to the image

method : public : MedianBlur(ksize:Int) ~ Image

Parameters

NameTypeDescription
ksizeIntaperture size (must be odd and greater than 1)

Return

TypeDescription
Imageblurred image

Example

image := Image->Load("noisy.jpg");
denoised := image->MedianBlur(3);
denoised->Save("denoised.jpg");

MorphologyEx #

Applies a morphological operation to an image

method : public : MorphologyEx(op:Int, shape:Int, ksize_w:Int, ksize_h:Int) ~ Image

Parameters

NameTypeDescription
opIntmorphological operation type from MorphTypes
shapeIntstructuring element shape from MorphShapes
ksize_wIntkernel width
ksize_hIntkernel height

Return

TypeDescription
Imageprocessed image

Normalize #

Normalizes the image for neural network preprocessing. Converts the image to float, normalizes to [0,1], converts BGR to RGB, subtracts the given mean values, and divides by the given std values per channel. Returns the result as a flattened CHW tensor (Float[]).

method : public : Normalize(mean_r:Float, mean_g:Float, mean_b:Float, std_r:Float, std_g:Float, std_b:Float) ~ Float[]

Parameters

NameTypeDescription
mean_rFloatmean value for the red channel
mean_gFloatmean value for the green channel
mean_bFloatmean value for the blue channel
std_rFloatstandard deviation for the red channel
std_gFloatstandard deviation for the green channel
std_bFloatstandard deviation for the blue channel

Return

TypeDescription
Floatflattened CHW Float[] tensor suitable for ONNX inference

Resize #

Resizes an image

method : public : Resize(sz:Size, fx:Float, fy:Float, interpolation:InterpolationFlags) ~ API.OpenCV.Image

Parameters

NameTypeDescription
szSizeimage size
fxFloatx-scale factor
fyFloaty-scale factor
interpolationInterpolationFlagsfilling missing pixels method

Return

TypeDescription
Imageupdated image

Example

image := Image->Load("photo.jpg");
resized := image->Resize(Size->New(320, 240));
resized->Save("thumb.jpg");

Resize #

Resizes an image

method : public : Resize(fx:Float, fy:Float, interpolation:InterpolationFlags) ~ API.OpenCV.Image

Parameters

NameTypeDescription
fxFloatx-scale factor
fyFloaty-scale factor
interpolationInterpolationFlagsfilling missing pixels method

Return

TypeDescription
Imageupdated image

Resize #

Resizes an image

method : public : Resize(f:Float, ) ~ API.OpenCV.Image

Parameters

NameTypeDescription
fFloatscale factor

Return

TypeDescription
Imageupdated image

Rows #

Gets image rows

method : public : Rows() ~ Int

Return

TypeDescription
Intimage rows

Save #

Saves an image to file

method : public : Save(path:String) ~ Bool

Parameters

NameTypeDescription
pathStringoutput file path

Return

TypeDescription
Booltrue if saved successfully, false otherwise

Example

image := Image->Load("input.jpg");
blurred := image->GaussianBlur(5, 5, 1.5);
if(blurred->Save("output.jpg")) {
  "Saved."->PrintLine();
};

Show #

Shows an image

method : public : Show(title:String) ~ Nil

Parameters

NameTypeDescription
titleStringdialog title

Example

image := Image->Load("photo.jpg");
image->Show("Preview");

Show #

Shows an image

method : public : Show(title:String, scale:Float) ~ Nil

Parameters

NameTypeDescription
titleStringdialog title
scaleFloatscaling percentage

Show #

Shows an image

method : public : Show(title:String, scale:Float, ) ~ Nil

Parameters

NameTypeDescription
titleStringdialog title
scaleFloatscaling percentage

Size #

Gets image size

method : public : Size() ~ Int

Return

TypeDescription
Intimage size

Sobel #

Applies Sobel edge detection

method : public : Sobel(ddepth:Int, dx:Int, dy:Int) ~ Image

Parameters

NameTypeDescription
ddepthIntdesired depth of the destination image (use -1 for same as source)
dxIntorder of the derivative x
dyIntorder of the derivative y

Return

TypeDescription
Imageedge-detected image

Threshold #

Applies a fixed-level threshold to each array element

method : public : Threshold(thresh:Float, maxval:Float, type:Int) ~ Image

Parameters

NameTypeDescription
threshFloatthreshold value
maxvalFloatmaximum value to use with BINARY and BINARY_INV threshold types
typeIntthreshold type from ThresholdTypes

Return

TypeDescription
Imagethresholded image

Type #

Gets image type

method : public : Type() ~ Int

Return

TypeDescription
Intimage type

WarpAffine #

Applies an affine transformation to the image using a 2x3 matrix.

method : public : WarpAffine(matrix:Float[], width:Int, height:Int) ~ Image

Parameters

NameTypeDescription
matrixFloat6-element Float[] representing the 2x3 affine matrix (row-major)
widthIntoutput image width
heightIntoutput image height

Return

TypeDescription
Imagetransformed image

WarpPerspective #

Applies a perspective transformation to the image using a 3x3 matrix.

method : public : WarpPerspective(matrix:Float[], width:Int, height:Int) ~ Image

Parameters

NameTypeDescription
matrixFloat9-element Float[] representing the 3x3 perspective matrix (row-major)
widthIntoutput image width
heightIntoutput image height

Return

TypeDescription
Imagetransformed image