Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -48,58 +48,28 @@ def stitch_rgbd_videos(
|
|
48 |
rgb_full = full_frames[i] # Full-resolution RGB frame.
|
49 |
depth_frame = depths[i] # Already in uint8 format
|
50 |
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
# Convert to grayscale if it's a color image
|
57 |
-
depth_gray = cv2.cvtColor(depth_frame, cv2.COLOR_RGB2GRAY)
|
58 |
-
depth_vis = np.stack([depth_gray] * 3, axis=-1)
|
59 |
-
else:
|
60 |
-
# Assume it's already the right format
|
61 |
-
depth_vis = depth_frame
|
62 |
else:
|
63 |
-
|
64 |
-
|
65 |
-
cmap = matplotlib.colormaps.get_cmap("inferno")
|
66 |
-
# Convert to single channel first
|
67 |
-
depth_gray = cv2.cvtColor(depth_frame, cv2.COLOR_RGB2GRAY)
|
68 |
-
# Normalize to 0-1 range for colormap
|
69 |
-
depth_norm = depth_gray / 255.0
|
70 |
-
# Apply colormap
|
71 |
-
depth_vis = (cmap(depth_norm)[..., :3] * 255).astype(np.uint8)
|
72 |
-
else:
|
73 |
-
# If zero depth, just use the original
|
74 |
-
depth_vis = depth_frame
|
75 |
else:
|
76 |
-
|
77 |
-
|
78 |
-
d_max = d_min + 1
|
79 |
-
|
80 |
-
# Normalize the depth frame to the range [0, 255]
|
81 |
-
depth_norm = np.clip((depth_frame - d_min) / (d_max - d_min) * 255, 0, 255).astype(np.uint8)
|
82 |
-
|
83 |
-
# Ensure depth_norm is 2D (remove singleton dimensions if present)
|
84 |
-
if depth_norm.ndim == 3:
|
85 |
-
depth_norm = np.squeeze(depth_norm)
|
86 |
-
|
87 |
-
# Generate depth visualization:
|
88 |
-
if grayscale:
|
89 |
-
if convert_from_color:
|
90 |
-
# First, generate a color depth image using the inferno colormap,
|
91 |
-
# then convert that color image to grayscale.
|
92 |
-
cmap = matplotlib.colormaps.get_cmap("inferno")
|
93 |
-
depth_color = (cmap(depth_norm / 255.0)[..., :3] * 255).astype(np.uint8)
|
94 |
-
depth_gray = cv2.cvtColor(depth_color, cv2.COLOR_RGB2GRAY)
|
95 |
-
depth_vis = np.stack([depth_gray] * 3, axis=-1)
|
96 |
-
else:
|
97 |
-
# Directly generate a grayscale image from the normalized depth values.
|
98 |
-
depth_vis = np.stack([depth_norm] * 3, axis=-1)
|
99 |
-
else:
|
100 |
-
# Generate a color depth image using the inferno colormap.
|
101 |
cmap = matplotlib.colormaps.get_cmap("inferno")
|
102 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
# Apply Gaussian blur if requested
|
105 |
if blur > 0:
|
|
|
48 |
rgb_full = full_frames[i] # Full-resolution RGB frame.
|
49 |
depth_frame = depths[i] # Already in uint8 format
|
50 |
|
51 |
+
if grayscale:
|
52 |
+
if convert_from_color:
|
53 |
+
# Convert to grayscale if it's a color image
|
54 |
+
depth_gray = cv2.cvtColor(depth_frame, cv2.COLOR_RGB2GRAY)
|
55 |
+
depth_vis = np.stack([depth_gray] * 3, axis=-1)
|
|
|
|
|
|
|
|
|
|
|
|
|
56 |
else:
|
57 |
+
# Assume it's already the right format
|
58 |
+
depth_vis = depth_frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
else:
|
60 |
+
if depth_frame.max() > 0: # Ensure we have valid depth data
|
61 |
+
# Use the inferno colormap if requested
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
62 |
cmap = matplotlib.colormaps.get_cmap("inferno")
|
63 |
+
# Convert to single channel first
|
64 |
+
depth_gray = cv2.cvtColor(depth_frame, cv2.COLOR_RGB2GRAY)
|
65 |
+
# Normalize to 0-1 range for colormap
|
66 |
+
depth_norm = depth_gray / 255.0
|
67 |
+
# Apply colormap
|
68 |
+
depth_vis = (cmap(depth_norm)[..., :3] * 255).astype(np.uint8)
|
69 |
+
else:
|
70 |
+
# If zero depth, just use the original
|
71 |
+
depth_vis = depth_frame
|
72 |
+
|
73 |
|
74 |
# Apply Gaussian blur if requested
|
75 |
if blur > 0:
|