Depth Anything V2
Use Depth Anything V2 for monocular depth estimation on a Dedicated Deployment or self-hosted Inference
Code sample
pip install inference-sdk opencv-pythonimport 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]))
Last updated
Was this helpful?