Vision
Vision functions let scripts read on-screen information beyond what the YOLO model exposes — text, image templates, and colour regions. All vision calls are async-friendly named-slot operations: results are cached and updated in the background, so calling them every frame is cheap.
ocr()
Read text from a screen region.
ocr(name, x1, y1, x2, y2, confidence, mode?)
| Parameter | Type | Description |
|---|---|---|
name |
string | Slot ID. Use a stable name per region. |
x1, y1, x2, y2 |
int | Region rectangle (pixels). |
confidence |
float | Minimum confidence threshold (0–1). |
mode |
string | Optional. "NonParagraph" (default) or "Paragraph". |
Returns: Object {text, confidence, wordCount, words[]} or null if no result yet.
result = ocr("killfeed", 100, 50, 800, 200, 0.7);
if (result != null && result.text == "ENEMY DOWN") {
// do something
}
templateMatch()
Find an image template inside a screen region.
templateMatch(name, x1, y1, x2, y2, confidence, path)
| Parameter | Type | Description |
|---|---|---|
name |
string | Slot ID. |
x1, y1, x2, y2 |
int | Region rectangle. |
confidence |
float | Match threshold (0–1). |
path |
string | Path to template .png. |
Returns: Array of {x, y, w, h, score} matches.
matches = templateMatch("xhair", 0, 0, 1920, 1080, 0.8, "crosshair.png");
if (len(matches) > 0) {
drawRectangle(matches[0].x, matches[0].y,
matches[0].x + matches[0].w,
matches[0].y + matches[0].h, "red");
}
colorMatch()
Find a colour patch in a region.
colorMatch(name, x1, y1, x2, y2, hex, tolerance)
| Parameter | Type | Description |
|---|---|---|
name |
string | Slot ID. |
x1, y1, x2, y2 |
int | Region rectangle. |
hex |
string | Colour to match ("#RRGGBB"). |
tolerance |
int | Allowed deviation (0–441). |
Returns: Object {percent, matched, total} or null.
hp = colorMatch("hp", 50, 950, 250, 980, "#FF0000", 30);
if (hp != null && hp.percent < 20) {
// low health detected
}
colorContour()
Detect contiguous colour regions (contours) in a region.
colorContour(name, x1, y1, x2, y2, hex, tolerance, minArea, maxCount?)
| Parameter | Type | Description |
|---|---|---|
name |
string | Slot ID. |
x1, y1, x2, y2 |
int | Region rectangle. |
hex |
string | Colour to match. |
tolerance |
int | Allowed deviation. |
minArea |
int | Minimum contour area to include. |
maxCount |
int | Optional. Cap on number of contours returned. |
Returns: Array of contour objects with bounds, area, and centroid.
Tips
- The
nameparameter is a slot identifier — using the same name across frames means the background worker reuses its result. Different names create separate slots. - Vision functions never block. The first call may return
nullwhile the slot warms up. - Call them every frame even if you don't always need the result — the cost is negligible.