# Wizualizacja mapy glebi DAv2-Small na realnych ujeciach + statystyki # wglebienia wnetrza skrzyni vs plaszczyzny przednie. import numpy as np import torch from PIL import Image from transformers import AutoImageProcessor, AutoModelForDepthEstimation MODEL_ID = "depth-anything/Depth-Anything-V2-Small-hf" CASES = [ (r"C:\xampp\htdocs\vilmax\vilmal\tmp\recolor-svc-storage-granat-v4.png", "storage"), (r"C:\xampp\htdocs\vilmax\vilmax-cockpit\data\hall-audit\preview\p-6419.jpg", "front"), ] proc = AutoImageProcessor.from_pretrained(MODEL_ID) model = AutoModelForDepthEstimation.from_pretrained(MODEL_ID).to("cuda").eval() for path, tag in CASES: img = Image.open(path).convert("RGB") inputs = proc(images=img, return_tensors="pt").to("cuda") with torch.no_grad(): depth = model(**inputs).predicted_depth[0] # wieksze = BLIZEJ (dysparytancja) d = depth.cpu().numpy() d = (d - d.min()) / max(1e-6, d.max() - d.min()) # 0..1, 1=blisko Image.fromarray((d * 255).astype(np.uint8)).resize(img.size, Image.BILINEAR).save( rf"C:\xampp\htdocs\vilmax\vilmal\tmp\depth-{tag}.png" ) print(tag, "img", img.size, "depth", d.shape, "min/max", round(float(d.min()),3), round(float(d.max()),3))