# Depth Anything V2

Depth Anything V2 is a monocular depth estimation model. It returns a normalized depth map (values between 0 and 1) for any input image.

{% hint style="info" %}
Depth Anything V2 is not available on the Serverless Hosted API. Run it on a [Dedicated Deployment](/deploy/dedicated-deployments.md) or [self-hosted Inference](https://inference.roboflow.com/).
{% endhint %}

## Code sample

Install the [Inference SDK](https://inference.roboflow.com/):

```bash
pip install inference-sdk opencv-python
```

Set `api_url` to your Dedicated Deployment URL or a local Inference server. Pass your [Roboflow API Key](https://app.roboflow.com/settings/api) via the `API_KEY` environment variable. The script colorizes the depth map and writes a side-by-side comparison with the input.

```python
import os
import urllib.request

import cv2
import numpy as np
from inference_sdk import InferenceHTTPClient

IMAGE_URL = "https://storage.googleapis.com/com-roboflow-marketing/notebooks/examples/bicycle.png"
IMAGE_PATH = "bicycle.png"
OUTPUT_PATH = "depth_annotated.png"

urllib.request.urlretrieve(IMAGE_URL, IMAGE_PATH)
image = cv2.imread(IMAGE_PATH)

client = InferenceHTTPClient(
    api_url="https://your-deployment.roboflow.cloud",
    api_key=os.getenv("API_KEY"),
)
result = client.depth_estimation(IMAGE_PATH)

depth = np.array(result["normalized_depth"], dtype=np.float32)
depth = cv2.resize(depth, (image.shape[1], image.shape[0]))
depth_vis = (depth * 255).astype(np.uint8)
depth_color = cv2.applyColorMap(depth_vis, cv2.COLORMAP_INFERNO)

cv2.imwrite(OUTPUT_PATH, np.hstack([image, depth_color]))
```

<figure><img src="/files/e9MgW9BFNDzenPtS5wyH" alt=""><figcaption></figcaption></figure>

{% hint style="info" %}
Set `api_url` to match your deployment target:

* `http://localhost:9001` for a local [Inference](https://inference.roboflow.com/) server.
* Your [Dedicated Deployment](/deploy/dedicated-deployments.md) URL for a private endpoint.
  {% endhint %}


---

# 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.roboflow.com/deploy/supported-models/depth-anything-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.
