Vid2ShapeAI / utils /depth_utils.py
umaradnaan's picture
Update utils/depth_utils.py
6fdeeb9 verified
raw
history blame contribute delete
659 Bytes
import torch
import cv2
from transformers import DPTFeatureExtractor, DPTForDepthEstimation
extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
model.eval()
def estimate_depth(frame_paths):
depth_maps = []
for path in frame_paths:
image = cv2.imread(path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
inputs = extractor(images=image, return_tensors="pt")
with torch.no_grad():
outputs = model(**inputs)
depth = outputs.predicted_depth[0].cpu().numpy()
depth_maps.append(depth)
return depth_maps