# Depth Estimation (DepthAny. V2)

This function block estimates per-pixel depth from a single RGB/BGR image and produces both a colored visualization and a normalized grayscale depth map. It is useful for distance-aware analysis, scene understanding, and augmenting detection pipelines with depth information.

## 📥 Inputs <a href="#inputs" id="inputs"></a>

`Image` Provide an RGB/BGR image to estimate depth from.

## 📤 Outputs <a href="#outputs" id="outputs"></a>

`Depth Vis` Colored visualization of estimated depth (useful for quick inspection).

`Depth Map` Normalized grayscale depth map (0–255) that can be used by other blocks for measurements or masking.

## 🕹️ Controls <a href="#controls" id="controls"></a>

`Model Size` Select model quality/speed trade-off. Typical choices are Small, Base, Large.

`Max Size` Maximum image dimension used during processing (larger gives more detail but increases processing time and memory).

## 🎨 Features <a href="#features" id="features"></a>

* Produces both a human-friendly colored depth visualization and a numeric depth map suitable for further processing.
* Offers selectable model sizes to balance speed vs. accuracy.
* Adjustable processing size to manage memory and frame rate on different machines.
* Works with any image-producing block as input (cameras, files, streams).

## ⚙️ Running <a href="#how-it-works" id="how-it-works"></a>

When the block runs, it processes the latest image provided to the `Image` input and outputs a visual depth map on `Depth Vis` and a normalized grayscale depth map on `Depth Map`. Changing `Model Size` or reducing `Max Size` affects processing speed and memory usage; select a smaller model or lower `Max Size` for faster performance on limited hardware.

## 📝 Usage Instructions <a href="#usage" id="usage"></a>

1. Feed an image source (camera or file) into the `Image` input.
2. Choose a suitable `Model Size` depending on available resources and desired accuracy.
3. Tune `Max Size` to limit the processing resolution; lower values increase speed.
4. Use the `Depth Vis` output to quickly inspect results and `Depth Map` for programmatic tasks.

## 💡 Tips and Tricks <a href="#tips-and-tricks" id="tips-and-tricks"></a>

* Use `Image Resizer` before this block when your input image is very large to reduce memory use and increase throughput.
* Preview results by connecting `Depth Vis` to `Show Image` for quick visual checks.
* Save outputs with `Image Logger` or `Image Write` when you need recordings of depth maps or visualizations for offline analysis.
* Focus processing on a region of interest with `Image ROI` to speed up estimation and reduce unnecessary computation.
* Combine with `Get Pixel` to sample depth values at detected object centers (e.g., read depth at a detected object's coordinates).
* Run object detectors such as `Object Detection (D-FINE)` or `Object Detection - Custom` on the RGB image, then consult the `Depth Map` to filter or sort detections by distance (near vs. far).
* For measurement tasks, pair with `Measure Position Distance` (use positions obtained from detection or ROI tools) and depth sampling from `Depth Map` to estimate relative distances more robustly.

## 🛠️ Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* If processing is too slow or the interface becomes unresponsive, try selecting a smaller `Model Size` or lowering `Max Size`.
* If depth visualization looks noisy, try preprocessing the input with `Denoising` or `Blur`, or use `Image Resizer` to match reasonable processing dimensions.
* If results appear inconsistent across frames, ensure consistent lighting and try increasing image quality (better exposure, higher resolution) or use `Image Logger` to inspect problematic frames.
* If you cannot load the higher quality models on your machine, use `Small` or `Base` sizes for reliable performance.


---

# 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://docs.augelab.com/function-blocks/ai-blocks/depth-estimation-depthany-v2.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.
