Spaces:
Running
on
Zero
Running
on
Zero
X-GAO
commited on
[Update] Add dataset evaluation
Browse files- depthcrafter/utils.py +16 -4
depthcrafter/utils.py
CHANGED
|
@@ -3,17 +3,29 @@ import cv2
|
|
| 3 |
import matplotlib.cm as cm
|
| 4 |
import torch
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# a simple function to read video frames
|
| 9 |
cap = cv2.VideoCapture(video_path)
|
| 10 |
original_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 11 |
original_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 12 |
original_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 13 |
# round the height and width to the nearest multiple of 64
|
| 14 |
-
height = round(original_height / 64) * 64
|
| 15 |
-
width = round(original_width / 64) * 64
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
# resize the video if the height or width is larger than max_res
|
| 18 |
if max(height, width) > max_res:
|
| 19 |
scale = max_res / max(original_height, original_width)
|
|
|
|
| 3 |
import matplotlib.cm as cm
|
| 4 |
import torch
|
| 5 |
|
| 6 |
+
dataset_res_dict = {
|
| 7 |
+
"sintel":[448, 1024],
|
| 8 |
+
"scannet":[640, 832],
|
| 9 |
+
"kitti":[384, 1280],
|
| 10 |
+
"bonn":[512, 640],
|
| 11 |
+
"nyu":[448, 640],
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
def read_video_frames(video_path, process_length, target_fps, max_res, dataset):
|
| 15 |
# a simple function to read video frames
|
| 16 |
cap = cv2.VideoCapture(video_path)
|
| 17 |
original_fps = cap.get(cv2.CAP_PROP_FPS)
|
| 18 |
original_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 19 |
original_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 20 |
# round the height and width to the nearest multiple of 64
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
if dataset=="open":
|
| 23 |
+
height = round(original_height / 64) * 64
|
| 24 |
+
width = round(original_width / 64) * 64
|
| 25 |
+
else:
|
| 26 |
+
height = dataset_res_dict[dataset][0]
|
| 27 |
+
width = dataset_res_dict[dataset][1]
|
| 28 |
+
|
| 29 |
# resize the video if the height or width is larger than max_res
|
| 30 |
if max(height, width) > max_res:
|
| 31 |
scale = max_res / max(original_height, original_width)
|