# 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://modeltrainscript.gitbook.io/docs/manual/automation/cameras.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
