map size error correction
Browse files
app.py
CHANGED
|
@@ -228,7 +228,23 @@ def process_image(image, model_choice="GLPN (Recommended)", visualization_type="
|
|
| 228 |
pad = 16
|
| 229 |
output = predicted_depth.squeeze().cpu().numpy() * 1000.0
|
| 230 |
output = output[pad:-pad, pad:-pad]
|
| 231 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
|
| 233 |
# STEP 3: Create depth visualization
|
| 234 |
print("Step 3: Creating depth visualization...")
|
|
@@ -252,9 +268,19 @@ def process_image(image, model_choice="GLPN (Recommended)", visualization_type="
|
|
| 252 |
# STEP 4: Create point cloud
|
| 253 |
print("Step 4: Generating point cloud...")
|
| 254 |
width, height = image.size
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 255 |
depth_image = (output * 255 / np.max(output)).astype(np.uint8)
|
| 256 |
image_array = np.array(image)
|
| 257 |
|
|
|
|
|
|
|
| 258 |
depth_o3d = o3d.geometry.Image(depth_image)
|
| 259 |
image_o3d = o3d.geometry.Image(image_array)
|
| 260 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
|
|
|
| 228 |
pad = 16
|
| 229 |
output = predicted_depth.squeeze().cpu().numpy() * 1000.0
|
| 230 |
output = output[pad:-pad, pad:-pad]
|
| 231 |
+
image_cropped = image.crop((pad, pad, image.width - pad, image.height - pad))
|
| 232 |
+
|
| 233 |
+
# Ensure depth and image have same dimensions
|
| 234 |
+
depth_height, depth_width = output.shape
|
| 235 |
+
img_width, img_height = image_cropped.size
|
| 236 |
+
|
| 237 |
+
print(f"After crop - Depth shape: {output.shape}, Image size: {image_cropped.size}")
|
| 238 |
+
|
| 239 |
+
# Resize depth to match image if needed
|
| 240 |
+
if depth_height != img_height or depth_width != img_width:
|
| 241 |
+
print(f"Resizing depth from ({depth_height}, {depth_width}) to ({img_height}, {img_width})")
|
| 242 |
+
from scipy import ndimage
|
| 243 |
+
zoom_factors = (img_height / depth_height, img_width / depth_width)
|
| 244 |
+
output = ndimage.zoom(output, zoom_factors, order=1)
|
| 245 |
+
print(f"Depth resized to: {output.shape}")
|
| 246 |
+
|
| 247 |
+
image = image_cropped
|
| 248 |
|
| 249 |
# STEP 3: Create depth visualization
|
| 250 |
print("Step 3: Creating depth visualization...")
|
|
|
|
| 268 |
# STEP 4: Create point cloud
|
| 269 |
print("Step 4: Generating point cloud...")
|
| 270 |
width, height = image.size
|
| 271 |
+
|
| 272 |
+
# Ensure depth map matches image size exactly
|
| 273 |
+
if output.shape != (height, width):
|
| 274 |
+
print(f"Final check - resizing depth from {output.shape} to ({height}, {width})")
|
| 275 |
+
from scipy import ndimage
|
| 276 |
+
zoom_factors = (height / output.shape[0], width / output.shape[1])
|
| 277 |
+
output = ndimage.zoom(output, zoom_factors, order=1)
|
| 278 |
+
|
| 279 |
depth_image = (output * 255 / np.max(output)).astype(np.uint8)
|
| 280 |
image_array = np.array(image)
|
| 281 |
|
| 282 |
+
print(f"Creating RGBD - Image: {image_array.shape}, Depth: {depth_image.shape}")
|
| 283 |
+
|
| 284 |
depth_o3d = o3d.geometry.Image(depth_image)
|
| 285 |
image_o3d = o3d.geometry.Image(image_array)
|
| 286 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|