Update app.py
Browse files
app.py
CHANGED
|
@@ -122,16 +122,18 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
|
| 122 |
# Combine depths to create the illusion of an empty space
|
| 123 |
combined_depth = np.maximum(depth_image_normalized * 0.5, background_depth)
|
| 124 |
|
|
|
|
| 125 |
depth_o3d = o3d.geometry.Image(combined_depth)
|
| 126 |
image_o3d = o3d.geometry.Image(foreground)
|
| 127 |
|
| 128 |
-
# Create RGBD image directly
|
| 129 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 130 |
image_o3d, depth_o3d, convert_rgb_to_intensity=False
|
| 131 |
)
|
| 132 |
|
| 133 |
-
#
|
| 134 |
-
|
|
|
|
| 135 |
|
| 136 |
# Check if the depth and foreground sizes are compatible
|
| 137 |
if rgbd_width != foreground.shape[1] or rgbd_height != foreground.shape[0]:
|
|
@@ -182,7 +184,6 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
|
| 182 |
|
| 183 |
return str(gltf_path)
|
| 184 |
|
| 185 |
-
|
| 186 |
# Gradio Interface
|
| 187 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 188 |
description = "Upload an image and optionally a depth map (in .npy or image format) to generate a 3D model. If no depth map is provided, the DPT model will generate it."
|
|
|
|
| 122 |
# Combine depths to create the illusion of an empty space
|
| 123 |
combined_depth = np.maximum(depth_image_normalized * 0.5, background_depth)
|
| 124 |
|
| 125 |
+
# Create Open3D images
|
| 126 |
depth_o3d = o3d.geometry.Image(combined_depth)
|
| 127 |
image_o3d = o3d.geometry.Image(foreground)
|
| 128 |
|
| 129 |
+
# Create RGBD image directly using the Open3D images
|
| 130 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 131 |
image_o3d, depth_o3d, convert_rgb_to_intensity=False
|
| 132 |
)
|
| 133 |
|
| 134 |
+
# Convert the Open3D color image to a NumPy array to get dimensions
|
| 135 |
+
rgbd_color_array = np.asarray(rgbd_image.color)
|
| 136 |
+
rgbd_height, rgbd_width = rgbd_color_array.shape[:2] # Get height and width from the NumPy array
|
| 137 |
|
| 138 |
# Check if the depth and foreground sizes are compatible
|
| 139 |
if rgbd_width != foreground.shape[1] or rgbd_height != foreground.shape[0]:
|
|
|
|
| 184 |
|
| 185 |
return str(gltf_path)
|
| 186 |
|
|
|
|
| 187 |
# Gradio Interface
|
| 188 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 189 |
description = "Upload an image and optionally a depth map (in .npy or image format) to generate a 3D model. If no depth map is provided, the DPT model will generate it."
|