Spaces:
Sleeping
Sleeping
| 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 | |