Update app.py
Browse files
app.py
CHANGED
|
@@ -98,9 +98,15 @@ def process_image(image_path, depth_map_path=None):
|
|
| 98 |
import cv2 # Make sure OpenCV is installed
|
| 99 |
|
| 100 |
def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
# Step 1: Resize depth_image with PIL using bilinear interpolation for smoother resizing
|
| 102 |
depth_image_resized = np.array(
|
| 103 |
-
Image.fromarray(depth_image
|
| 104 |
foreground.shape[:2][::-1], Image.Resampling.BILINEAR
|
| 105 |
)
|
| 106 |
)
|
|
@@ -164,7 +170,8 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
|
| 164 |
# Save as GLTF
|
| 165 |
gltf_path = f"./{image_path.stem}.gltf"
|
| 166 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 167 |
-
return gltf_path
|
|
|
|
| 168 |
# Gradio Interface
|
| 169 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 170 |
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."
|
|
|
|
| 98 |
import cv2 # Make sure OpenCV is installed
|
| 99 |
|
| 100 |
def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
|
| 101 |
+
# Ensure depth_image is 2D and of type uint16
|
| 102 |
+
if depth_image.ndim != 2:
|
| 103 |
+
raise ValueError("Depth image must be a 2D array.")
|
| 104 |
+
if depth_image.dtype != np.uint16:
|
| 105 |
+
depth_image = depth_image.astype(np.uint16)
|
| 106 |
+
|
| 107 |
# Step 1: Resize depth_image with PIL using bilinear interpolation for smoother resizing
|
| 108 |
depth_image_resized = np.array(
|
| 109 |
+
Image.fromarray(depth_image, mode='I').resize(
|
| 110 |
foreground.shape[:2][::-1], Image.Resampling.BILINEAR
|
| 111 |
)
|
| 112 |
)
|
|
|
|
| 170 |
# Save as GLTF
|
| 171 |
gltf_path = f"./{image_path.stem}.gltf"
|
| 172 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 173 |
+
return gltf_path
|
| 174 |
+
|
| 175 |
# Gradio Interface
|
| 176 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 177 |
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."
|