File size: 659 Bytes
6fdeeb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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