Spaces:
Running
on
Zero
Running
on
Zero
File size: 861 Bytes
a51c6d2 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
from PIL import Image
from models.monoD import depth_pro
# Load model and preprocessing transform
model, transform = depth_pro.create_model_and_transforms()
model.eval()
# Load and preprocess an image.
image_path = "assets/dance/00000.jpg"
image, _, f_px = depth_pro.load_rgb(image_path)
image = transform(image)
# Run inference.
import time
t0 = time.time()
prediction = model.infer(image, f_px=f_px)
depth = prediction["depth"] # Depth in [m].
focallength_px = prediction["focallength_px"] # Focal length in pixels.
import cv2
import numpy as np
depth = depth.clamp(0,30).squeeze().detach().cpu().numpy()
depth = (depth - depth.min())/(depth.max()-depth.min()) * 255.0
depth = depth.astype(np.uint8)
depth = cv2.applyColorMap(depth, cv2.COLORMAP_INFERNO)
cv2.imwrite("depth.png", depth)
print(f"Time: {time.time() - t0:.2f}s")
import pdb; pdb.set_trace() |