Update app.py
Browse files
app.py
CHANGED
|
@@ -95,19 +95,19 @@ def process_image(image_path, depth_map_path=None):
|
|
| 95 |
|
| 96 |
|
| 97 |
def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
| 98 |
-
# Resize depth image
|
| 99 |
depth_image_resized = np.array(
|
| 100 |
-
Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)
|
| 101 |
)
|
| 102 |
|
| 103 |
-
# Normalize
|
| 104 |
depth_image_normalized = (depth_image_resized - depth_image_resized.min()) / (
|
| 105 |
depth_image_resized.max() - depth_image_resized.min()
|
| 106 |
) * 65535
|
| 107 |
-
depth_image_normalized = depth_image_normalized.astype(np.uint16)
|
| 108 |
|
| 109 |
-
# Convert
|
| 110 |
-
depth_image_uint8 = img_as_ubyte(depth_image_normalized / 65535.0) # Scale to [0, 1]
|
| 111 |
|
| 112 |
depth_o3d = o3d.geometry.Image(depth_image_uint8)
|
| 113 |
image_o3d = o3d.geometry.Image(foreground)
|
|
@@ -148,6 +148,7 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
|
| 148 |
gltf_path = f"./{image_path.stem}.gltf"
|
| 149 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 150 |
return gltf_path
|
|
|
|
| 151 |
# Gradio Interface
|
| 152 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 153 |
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."
|
|
|
|
| 95 |
|
| 96 |
|
| 97 |
def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
| 98 |
+
# Resize depth image, specifying 'I;16' mode for uint16 compatibility
|
| 99 |
depth_image_resized = np.array(
|
| 100 |
+
Image.fromarray(depth_image, mode='I;16').resize(foreground.shape[:2][::-1], Image.LANCZOS)
|
| 101 |
)
|
| 102 |
|
| 103 |
+
# Normalize and convert to uint16 if it needs to stay uint16
|
| 104 |
depth_image_normalized = (depth_image_resized - depth_image_resized.min()) / (
|
| 105 |
depth_image_resized.max() - depth_image_resized.min()
|
| 106 |
) * 65535
|
| 107 |
+
depth_image_normalized = depth_image_normalized.astype(np.uint16)
|
| 108 |
|
| 109 |
+
# Convert to uint8 for compatibility with Open3D if necessary
|
| 110 |
+
depth_image_uint8 = img_as_ubyte(depth_image_normalized / 65535.0) # Scale to [0, 1] for uint8 conversion
|
| 111 |
|
| 112 |
depth_o3d = o3d.geometry.Image(depth_image_uint8)
|
| 113 |
image_o3d = o3d.geometry.Image(foreground)
|
|
|
|
| 148 |
gltf_path = f"./{image_path.stem}.gltf"
|
| 149 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 150 |
return gltf_path
|
| 151 |
+
|
| 152 |
# Gradio Interface
|
| 153 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 154 |
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."
|