Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -27,9 +27,6 @@ def stitch_rgbd_videos(
|
|
27 |
output_dir: str = './outputs',
|
28 |
input_size: int = 518,
|
29 |
):
|
30 |
-
# 1. Read input video frames for inference (downscaled to max_res).
|
31 |
-
frames, target_fps = read_video_frames(processed_video, max_len, target_fps, max_res)
|
32 |
-
|
33 |
video_name = os.path.basename(processed_video)
|
34 |
if not os.path.exists(output_dir):
|
35 |
os.makedirs(output_dir)
|
@@ -37,7 +34,7 @@ def stitch_rgbd_videos(
|
|
37 |
stitched_video_path = None
|
38 |
if stitch:
|
39 |
# For stitching: read the original video in full resolution (without downscaling).
|
40 |
-
full_frames,
|
41 |
depths, _ = read_video_frames(depth_vis_video, max_len, target_fps, max_res=-1)
|
42 |
|
43 |
# For each frame, create a visual depth image from the inferenced depths.
|
@@ -48,9 +45,9 @@ def stitch_rgbd_videos(
|
|
48 |
depth_frame = depths[i]
|
49 |
|
50 |
# Normalize the depth frame to the range [0, 255].
|
51 |
-
|
52 |
-
depth_norm = cv2.normalize(depth_frame, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)
|
53 |
-
depth_norm = depth_norm.astype(np.uint8)
|
54 |
|
55 |
# Generate depth visualization:
|
56 |
if grayscale:
|
@@ -60,11 +57,13 @@ def stitch_rgbd_videos(
|
|
60 |
cmap = matplotlib.colormaps.get_cmap("inferno")
|
61 |
depth_color = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
|
62 |
|
63 |
-
if len(depth_color.shape) == 3 and depth_color.shape[2] in [3, 4]:
|
64 |
-
|
65 |
-
else:
|
66 |
-
|
67 |
-
|
|
|
|
|
68 |
depth_vis = np.stack([depth_gray] * 3, axis=-1)
|
69 |
else:
|
70 |
# Directly generate a grayscale image from the normalized depth values.
|
@@ -75,33 +74,33 @@ def stitch_rgbd_videos(
|
|
75 |
depth_vis = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
|
76 |
|
77 |
# Ensure depth_vis is valid and contiguous
|
78 |
-
if depth_vis is None or depth_vis.size == 0:
|
79 |
-
|
80 |
-
else:
|
81 |
-
|
82 |
|
83 |
-
# Apply Gaussian blur if requested.
|
84 |
-
if blur > 0:
|
85 |
-
|
86 |
-
|
87 |
|
88 |
# Resize the depth visualization to match the full-resolution RGB frame.
|
89 |
H_full, W_full = rgb_full.shape[:2]
|
90 |
depth_vis_resized = cv2.resize(depth_vis, (W_full, H_full))
|
91 |
|
92 |
# Ensure both images have 3 channels.
|
93 |
-
if len(rgb_full.shape) == 2:
|
94 |
-
|
95 |
-
if len(depth_vis_resized.shape) == 2:
|
96 |
-
|
97 |
|
98 |
# Ensure same data type.
|
99 |
-
if rgb_full.dtype != depth_vis_resized.dtype:
|
100 |
-
|
101 |
|
102 |
# Ensure images are contiguous in memory.
|
103 |
-
rgb_full = np.ascontiguousarray(rgb_full)
|
104 |
-
depth_vis_resized = np.ascontiguousarray(depth_vis_resized)
|
105 |
|
106 |
# Now safely concatenate.
|
107 |
stitched = cv2.hconcat([rgb_full, depth_vis_resized])
|
|
|
27 |
output_dir: str = './outputs',
|
28 |
input_size: int = 518,
|
29 |
):
|
|
|
|
|
|
|
30 |
video_name = os.path.basename(processed_video)
|
31 |
if not os.path.exists(output_dir):
|
32 |
os.makedirs(output_dir)
|
|
|
34 |
stitched_video_path = None
|
35 |
if stitch:
|
36 |
# For stitching: read the original video in full resolution (without downscaling).
|
37 |
+
full_frames, target_fps = read_video_frames(processed_video, max_len, target_fps, max_res=-1)
|
38 |
depths, _ = read_video_frames(depth_vis_video, max_len, target_fps, max_res=-1)
|
39 |
|
40 |
# For each frame, create a visual depth image from the inferenced depths.
|
|
|
45 |
depth_frame = depths[i]
|
46 |
|
47 |
# Normalize the depth frame to the range [0, 255].
|
48 |
+
depth_norm = ((depth_frame - d_min) / (d_max - d_min) * 255).astype(np.uint8)
|
49 |
+
#depth_norm = cv2.normalize(depth_frame, None, alpha=0, beta=255, norm_type=cv2.NORM_MINMAX)
|
50 |
+
#depth_norm = depth_norm.astype(np.uint8)
|
51 |
|
52 |
# Generate depth visualization:
|
53 |
if grayscale:
|
|
|
57 |
cmap = matplotlib.colormaps.get_cmap("inferno")
|
58 |
depth_color = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
|
59 |
|
60 |
+
#if len(depth_color.shape) == 3 and depth_color.shape[2] in [3, 4]:
|
61 |
+
# depth_gray = cv2.cvtColor(depth_color, cv2.COLOR_RGB2GRAY)
|
62 |
+
#else:
|
63 |
+
# depth_gray = depth_color
|
64 |
+
#depth_vis = np.stack([depth_gray] * 3, axis=-1)
|
65 |
+
|
66 |
+
depth_gray = cv2.cvtColor(depth_color, cv2.COLOR_RGB2GRAY)
|
67 |
depth_vis = np.stack([depth_gray] * 3, axis=-1)
|
68 |
else:
|
69 |
# Directly generate a grayscale image from the normalized depth values.
|
|
|
74 |
depth_vis = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
|
75 |
|
76 |
# Ensure depth_vis is valid and contiguous
|
77 |
+
#if depth_vis is None or depth_vis.size == 0:
|
78 |
+
# raise ValueError("depth_vis is empty or not properly computed.")
|
79 |
+
#else:
|
80 |
+
# depth_vis = np.ascontiguousarray(depth_vis)
|
81 |
|
82 |
+
# TODO FIX: Apply Gaussian blur if requested.
|
83 |
+
#if blur > 0:
|
84 |
+
# kernel_size = int(blur * 20) * 2 + 1 # Ensures an odd kernel size.
|
85 |
+
# depth_vis = cv2.GaussianBlur(depth_vis, (kernel_size, kernel_size), 0)
|
86 |
|
87 |
# Resize the depth visualization to match the full-resolution RGB frame.
|
88 |
H_full, W_full = rgb_full.shape[:2]
|
89 |
depth_vis_resized = cv2.resize(depth_vis, (W_full, H_full))
|
90 |
|
91 |
# Ensure both images have 3 channels.
|
92 |
+
#if len(rgb_full.shape) == 2:
|
93 |
+
# rgb_full = cv2.cvtColor(rgb_full, cv2.COLOR_GRAY2BGR)
|
94 |
+
#if len(depth_vis_resized.shape) == 2:
|
95 |
+
# depth_vis_resized = cv2.cvtColor(depth_vis_resized, cv2.COLOR_GRAY2BGR)
|
96 |
|
97 |
# Ensure same data type.
|
98 |
+
#if rgb_full.dtype != depth_vis_resized.dtype:
|
99 |
+
# depth_vis_resized = depth_vis_resized.astype(rgb_full.dtype)
|
100 |
|
101 |
# Ensure images are contiguous in memory.
|
102 |
+
#rgb_full = np.ascontiguousarray(rgb_full)
|
103 |
+
#depth_vis_resized = np.ascontiguousarray(depth_vis_resized)
|
104 |
|
105 |
# Now safely concatenate.
|
106 |
stitched = cv2.hconcat([rgb_full, depth_vis_resized])
|