mtwohey2 commited on
Commit
41a5410
·
verified ·
1 Parent(s): e185ea0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -2
app.py CHANGED
@@ -80,12 +80,29 @@ def stitch_rgbd_videos(
80
  if blur > 0:
81
  kernel_size = int(blur * 20) * 2 + 1 # Ensures an odd kernel size.
82
  depth_vis = cv2.GaussianBlur(depth_vis, (kernel_size, kernel_size), 0)
 
83
  # Resize the depth visualization to match the full-resolution RGB frame.
84
  H_full, W_full = rgb_full.shape[:2]
85
  depth_vis_resized = cv2.resize(depth_vis, (W_full, H_full))
86
- # Concatenate the full-resolution RGB frame (left) and the resized depth visualization (right).
87
- stitched = cv2.hconcat([rgb_full, depth_vis_resized])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  stitched_frames.append(stitched)
 
89
  stitched_frames = np.array(stitched_frames)
90
  # Use only the first 20 characters of the base name for the output filename and append '_RGBD.mp4'
91
  base_name = os.path.splitext(video_name)[0]
 
80
  if blur > 0:
81
  kernel_size = int(blur * 20) * 2 + 1 # Ensures an odd kernel size.
82
  depth_vis = cv2.GaussianBlur(depth_vis, (kernel_size, kernel_size), 0)
83
+
84
  # Resize the depth visualization to match the full-resolution RGB frame.
85
  H_full, W_full = rgb_full.shape[:2]
86
  depth_vis_resized = cv2.resize(depth_vis, (W_full, H_full))
87
+
88
+ # Ensure both images have 3 channels.
89
+ if len(rgb_full.shape) == 2:
90
+ rgb_full = cv2.cvtColor(rgb_full, cv2.COLOR_GRAY2BGR)
91
+ if len(depth_vis_resized.shape) == 2:
92
+ depth_vis_resized = cv2.cvtColor(depth_vis_resized, cv2.COLOR_GRAY2BGR)
93
+
94
+ # Ensure same data type.
95
+ if rgb_full.dtype != depth_vis_resized.dtype:
96
+ depth_vis_resized = depth_vis_resized.astype(rgb_full.dtype)
97
+
98
+ # Ensure images are contiguous in memory.
99
+ rgb_full = np.ascontiguousarray(rgb_full)
100
+ depth_vis_resized = np.ascontiguousarray(depth_vis_resized)
101
+
102
+ # Now safely concatenate.
103
+ stitched = cv2.hconcat([rgb_full, depth_vis_resized])
104
  stitched_frames.append(stitched)
105
+
106
  stitched_frames = np.array(stitched_frames)
107
  # Use only the first 20 characters of the base name for the output filename and append '_RGBD.mp4'
108
  base_name = os.path.splitext(video_name)[0]