> ## Documentation Index
> Fetch the complete documentation index at: https://docs.altnautica.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Vision engine

> The on-board vision engine: frame rings, the model registry, NPU inference sidecars, detection demand, click-to-follow, the detection stream and custom model upload.

`ados-vision` is the agent's vision engine. It owns the camera-frame fast path that extensions are too small and too sandboxed to own. For every camera it handles, it captures or taps frames, downscales them, and publishes them into a per-camera shared-memory ring that consumers map and read. It keeps the registry of inference models, serialises inference on the shared accelerator, and fans detections back out.

It runs on the `drone` and `visor` profiles. The supervisor starts it when `vision.enabled` is `true` and a camera source exists, or when the top-level `cameras` list declares a captured camera, since the engine is the only owner of those.

## Inference backends

`vision.backend` picks where models run:

| Backend | Runs on |
| - | - |
| `auto` (default) | The best backend the board has. |
| `rknn` | A Rockchip NPU, through the `ados-vision-rknn` sidecar. |
| `hailo` | A Hailo accelerator, through the `ados-vision-hailo` sidecar. |
| `onnx` | ONNX Runtime on the CPU. |
| `mock` | A mock backend for testing. A mock model is never reported as inference-capable. |

The NPU sidecars are separate units because the vendor runtimes are separate. The engine talks to them over IPC and holds a lease so one model runs on the accelerator at a time.

Extensions never talk to the engine directly. They call the plugin host, which checks the extension's vision capability and forwards the call to the engine over `/run/ados/vision.sock`.

## Detection on demand

With `vision.detection_demand: on_demand` (the default), the detector runs on a camera only while some consumer holds a lease on it. An operator surface takes, renews or releases a lease with:

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -s -X POST -H "X-ADOS-Key: $ADOS_KEY" -H "Content-Type: application/json" \
  -d '{"camera_id": "cam0", "kind": "detection", "hold_s": 10}' \
  http://192.168.1.50:8080/api/vision/demand
# {"kind": "detection", "camera_id": "cam0", "detecting": true, "until_ms": 1793960013000}
```

| Field | Meaning |
| - | - |
| `camera_id` | The camera. Required. |
| `kind` | `detection` (default), `depth` (the depth grid) or `surfaces` (landing zones). |
| `hold_s` | Seconds to hold it on, 0 to 60. `0` releases this owner's lease. |
| `owner` | Who holds the lease, default `operator`. One owner's renew or release never touches another's. |

`vision.detection_demand: always` runs the detector on every camera all the time.

## Click-to-follow

`POST /api/vision/designate` locks a camera's tracker onto the box an operator clicked, overriding the auto-lock.

```bash theme={"theme":{"light":"github-light","dark":"github-dark"}}
curl -s -X POST -H "X-ADOS-Key: $ADOS_KEY" -H "Content-Type: application/json" \
  -d '{"camera_id": "cam0", "bbox": {"x": 412, "y": 188, "width": 96, "height": 210}, "class_label": "person"}' \
  http://192.168.1.50:8080/api/vision/designate
# {"designated": true, "track_id": 17, "camera_id": "cam0"}
```

`bbox` is in pixels of the frame's own resolution, origin top-left. `class_label` and `confidence` are optional. A request the engine rejects is `400`; an engine that is off or not running is `503`, so a designate is never dropped silently.

## Live detections

`WS /api/vision/detections/ws` streams each detection batch as JSON:

```json theme={"theme":{"light":"github-light","dark":"github-dark"}}
{"model_id": "...", "camera_id": "cam0", "frame_id": 1042, "ts_ms": 1793960003000,
 "detections": [{"bbox": {"x": 412, "y": 188, "width": 96, "height": 210},
   "class_label": "person", "confidence": 0.91, "track_id": 17}]}
```

A browser authenticates with a ticket for scope `vision.detections` from `POST /api/_ws/ticket`; a native client passes `X-ADOS-Key`. A client that connects after a detection receives the last batch at once if it is under a second old. `GET /api/vision/detections/latest` returns the last batch over HTTP.

## Engine state

| Route | Returns |
| - | - |
| `GET /api/vision/status` | Every registered model (task, execution, whether the backend loaded it), the backend and its state (`ready`, `mock` or `unavailable` with `backend_reason`), the detector's demand state per camera, the depth layer's state, and NPU utilisation (`null` when the board has no sampler). |
| `GET /api/vision/capabilities` | The registered models grouped by task, with the union of their classes and whether any is inference-capable. `?kind=detection&class=person` resolves one capability to the matching model, or `{"available": false}`. |

Both answer `503` when the engine is not running, never an empty result.

## Models

Models live in `vision.models_dir` (default `/opt/ados/models/vision`), with the cache capped at `vision.models_cache_max_mb`.

| Route | Effect |
| - | - |
| `GET /api/vision/models` | The registry, the installed files, uploaded models, the active detector and cache use. |
| `POST /api/vision/models/{model_id}/download` | Download the variant of a registry model that fits this board. |
| `GET /api/vision/models/{model_id}/status` | Download progress and installed state. |
| `POST /api/vision/plugin-models/{plugin_id}/deliver` | Resolve and cache the models an installed extension declares. |
| `PUT /api/vision/detector` | Select the detector: `{"model_id", "model_path"?}`. |
| `DELETE /api/vision/detector` | Clear the detector; the engine runs no inference of its own. |
| `POST /api/vision/models/upload` | Upload a custom model. |

### Select the detector

`PUT /api/vision/detector` writes the `vision.detector` block (`model_id`, `model_path`, `enabled: true`) into `/etc/ados/config.yaml`, keeping every other key, then restarts `ados-vision`. Without `model_path` the agent resolves the id against the installed files: `<id>.<ext>` for an upload, `<id>-<board>.<ext>` for a registry download. An id with no installed file is refused with `409`.

### Upload a custom model

`POST /api/vision/models/upload` is a multipart request with two parts:

* a file part: the model (`.rknn`, `.onnx` or `.tflite`);
* a metadata part: JSON `{id, name, classes, head, input_w, input_h, runtime, board_match}`.

The file is stored as `<id>` plus the suffix for `runtime` (`rknn` → `.rknn`, `tflite` → `.tflite`, otherwise `.onnx`); the uploaded file name is not used. The id must match `[A-Za-z0-9._-]` with no `..`. Re-using an id replaces the earlier upload. A missing id, an empty file or a `*.engine` file is `400`.

## Configuration

| Key | Type | Default | Allowed | Description |
| - | - | - | - | - |
| `vision.backend` | string | `"auto"` | `"auto"`, `"rknn"`, `"hailo"`, `"onnx"`, `"onnx-cuda"`, `"mock"` | Backend |
| `vision.confidence_threshold` | number | `0.25` | 0.05 to 1 | Confidence Threshold |
| `vision.decode_threads` | integer | `1` | 1 to 4294967295 | Decode Threads |
| `vision.depth.enabled` | boolean | `true` | n/a | Enabled |
| `vision.depth.input_height` | integer | `196` | 0 to 4294967295 | Input Height |
| `vision.depth.input_width` | integer | `252` | 0 to 4294967295 | Input Width |
| `vision.depth.model_id` | string | `"depth_anything_v2_small"` | n/a | Model Id |
| `vision.depth.model_path` | string\|null | n/a | n/a | Model Path |
| `vision.depth.rate_hz` | number\|null | n/a | >= 0 | Rate Hz |
| `vision.depth.threads` | integer | `2` | 1 to 4294967295 | Threads |
| `vision.designate_camera` | string\|null | n/a | n/a | Designate Camera |
| `vision.designate_hold_s` | number | `30` | >= 0 | Designate Hold S |
| `vision.detection_demand` | string | `"on_demand"` | `"on_demand"`, `"always"` | Detection Demand |
| `vision.detector.class_labels` | array | n/a | n/a | Class Labels |
| `vision.detector.crop_input_size` | integer\|null | n/a | 0 to 4294967295 | Crop Input Size |
| `vision.detector.crop_model_path` | string\|null | n/a | n/a | Crop Model Path |
| `vision.detector.full_frame_hz` | number | `2` | >= 0 | Full Frame Hz |
| `vision.detector.head` | string | `""` | n/a | Head |
| `vision.detector.input_height` | integer | `640` | 0 to 4294967295 | Input Height |
| `vision.detector.input_width` | integer | `640` | 0 to 4294967295 | Input Width |
| `vision.detector.model_id` | string | `""` | n/a | Model Id |
| `vision.detector.model_path` | string | `""` | n/a | Model Path |
| `vision.detector.priority` | integer\|null | n/a | 0 to 255 | Priority |
| `vision.detector.rate_hz` | number | `10` | >= 0 | Rate Hz |
| `vision.detector.threads` | integer | `2` | 1 to 4294967295 | Threads |
| `vision.downscale_height` | integer | `480` | 0 to 4294967295 | Downscale Height |
| `vision.downscale_width` | integer | `640` | 0 to 4294967295 | Downscale Width |
| `vision.enabled` | boolean | `false` | n/a | Enabled |
| `vision.max_box_area_frac` | number | `0.5` | 0 to 1 | Max Box Area Frac |
| `vision.mock_target` | boolean | `false` | n/a | Mock Target |
| `vision.models_cache_max_mb` | integer | `500` | 0 to 4294967295 | Models Cache Max Mb |
| `vision.models_dir` | string | `"/opt/ados/models/vision"` | n/a | Models Dir |
| `vision.profile` | string\|null | n/a | n/a | Profile |
| `vision.registry_url` | string | `"https://raw.githubusercontent.com/altnautica/ADOSMissionControlGCS/main/public/models/registry.json"` | n/a | Registry Url |
| `vision.reid.input_height` | integer | `256` | 0 to 4294967295 | Input Height |
| `vision.reid.input_width` | integer | `128` | 0 to 4294967295 | Input Width |
| `vision.reid.model_id` | string | `""` | n/a | Model Id |
| `vision.reid.model_path` | string | `""` | n/a | Model Path |
| `vision.reid_enabled` | boolean | `false` | n/a | Reid Enabled |
| `vision.reid_model_id` | string\|null | n/a | n/a | Reid Model Id |
| `vision.shm_budget_mb` | integer | `64` | 0 to 4294967295 | Shm Budget Mb |
| `vision.sim_latency_ms` | integer\|null | n/a | 0 to 4294967295 | Sim Latency Ms |
| `vision.slot_count` | integer | `4` | 0 to 4294967295 | Slot Count |
| `vision.socket_dir` | string | `"/run/ados"` | n/a | Socket Dir |
| `vision.subject.beacon_only_max_s` | number | `60` | 0 to 3600 | Beacon Only Max S |
| `vision.tracker_enabled` | boolean | `false` | n/a | Tracker Enabled |
| `vision.whole_frame_conf` | number | `0.45` | 0.05 to 1 | Whole Frame Conf |

## Related

> [card] [Multi-camera](https://docs.altnautica.com/drone-agent/multi-camera.md)
>
> The cameras the engine reads.

> [card] [Follow Me](https://docs.altnautica.com/drone-agent/extensions/follow-me.md)
>
> An extension that flies from the engine's tracks.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.