> For the complete documentation index, see [llms.txt](https://modeltrainscript.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://modeltrainscript.gitbook.io/docs/manual/automation/cameras.md).

# Cameras

Cameras enable AI-powered detection of vehicles on your layout using Locovision. You can use them as triggers, conditions, or feedback points in your [scripts](/docs/manual/automation/scripts.md) — for example, starting a platform sequence when a train is detected at a station camera.

Model Train Script supports two camera types.

## Local

Uses the camera of the device you are working on. Great for testing your scripts, but less practical for a permanent layout since you need a fixed camera position for predictable detection.

Enable this in the [profile configuration](/docs/manual/profile.md).

## Web URL

Polls a URL to retrieve images and processes them locally for vehicle detection. Two URL types are supported:

* **JPEG** — Fetches a single image at a configurable interval.
* **MJPEG** — Streams continuous frames.

This works well with affordable hardware like an ESP32-CAM module. Upload the "CameraWebServer" sketch via the Arduino IDE, find the IP address in the Serial Monitor, and enter `http://<ip-address>/capture` as the URL in Model Train Script.

Be aware that this mode places a heavier load on your main device since all processing is done there.

## Detection

Locovision uses a YOLOv8 AI model to detect vehicles in the camera feed. For each camera you define a **detection point** — a specific area in the camera frame to monitor. You can position this point visually by dragging it on the live camera preview.

When a vehicle is detected at the detection point, it stays active for a configurable duration (default 2 seconds) before expiring. This prevents flickering in automation conditions.

## Layout integration

Cameras can be placed on your [layout](/docs/manual/layout.md) as camera items. Assign a camera and detection point to the item, and it becomes a visual feedback point on your track plan. This is especially useful when one camera monitors multiple track areas — each area gets its own layout item with its own detection point.

## Using cameras in scripts

Cameras integrate with the automation engine in two ways:

* **Execution event** — Trigger a script when a vehicle is detected. The detected vehicle can automatically become the selected vehicle for subsequent actions in the script.
* **Condition** — Pause script execution until a vehicle is (or is not) detected at a specific detection point. Useful for waiting until a train arrives before continuing a sequence.

Both support referencing a camera directly or via a layout item.
