Spaces:
Sleeping
Sleeping
Update utils/depth_utils.py
Browse files- utils/depth_utils.py +23 -25
utils/depth_utils.py
CHANGED
|
@@ -1,25 +1,23 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import cv2
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
model
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
image = cv2.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
return depth_maps
|
|
|
|
| 1 |
+
import torch
|
| 2 |
+
import cv2
|
| 3 |
+
from transformers import DPTFeatureExtractor, DPTForDepthEstimation
|
| 4 |
+
|
| 5 |
+
extractor = DPTFeatureExtractor.from_pretrained("Intel/dpt-large")
|
| 6 |
+
model = DPTForDepthEstimation.from_pretrained("Intel/dpt-large")
|
| 7 |
+
model.eval()
|
| 8 |
+
|
| 9 |
+
def estimate_depth(frame_paths):
|
| 10 |
+
depth_maps = []
|
| 11 |
+
|
| 12 |
+
for path in frame_paths:
|
| 13 |
+
image = cv2.imread(path)
|
| 14 |
+
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 15 |
+
|
| 16 |
+
inputs = extractor(images=image, return_tensors="pt")
|
| 17 |
+
with torch.no_grad():
|
| 18 |
+
outputs = model(**inputs)
|
| 19 |
+
depth = outputs.predicted_depth[0].cpu().numpy()
|
| 20 |
+
|
| 21 |
+
depth_maps.append(depth)
|
| 22 |
+
|
| 23 |
+
return depth_maps
|
|
|
|
|
|