Update app.py
Browse files
app.py
CHANGED
|
@@ -66,13 +66,9 @@ def process_image(image_path, depth_map_path=None):
|
|
| 66 |
img = Image.fromarray(subject_depth_map)
|
| 67 |
return [img, gltf_path, gltf_path]
|
| 68 |
except Exception as e:
|
| 69 |
-
print(f"
|
| 70 |
-
raise Exception("Error reconstructing 3D model")
|
| 71 |
-
|
| 72 |
-
if depth_map_path:
|
| 73 |
-
print(f"Depth map path: {depth_map_path}")
|
| 74 |
-
print(f"Depth map shape: {depth_image.shape}")
|
| 75 |
-
|
| 76 |
def create_main_subject_mask(image):
|
| 77 |
"""Generates a binary mask for the main subject using rembg."""
|
| 78 |
# Remove background and create mask
|
|
@@ -101,13 +97,18 @@ def extract_subject_depth(depth_image, image):
|
|
| 101 |
def create_3d_obj(image, depth_image, image_path, inpainted_bg, main_subject_offset=0.2):
|
| 102 |
# Ensure depth_image has only main subject depth and no background depth
|
| 103 |
depth_image = np.array(depth_image)
|
| 104 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 105 |
# Convert image and depth_image to Open3D format
|
| 106 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 107 |
-
o3d.geometry.Image(image),
|
| 108 |
-
o3d.geometry.Image(depth_image),
|
| 109 |
convert_rgb_to_intensity=False
|
| 110 |
)
|
|
|
|
| 111 |
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, o3d.camera.PinholeCameraIntrinsic(
|
| 112 |
width=image.shape[1], height=image.shape[0], fx=1.0, fy=1.0, cx=image.shape[1] / 2, cy=image.shape[0] / 2))
|
| 113 |
|
|
@@ -123,7 +124,7 @@ def create_3d_obj(image, depth_image, image_path, inpainted_bg, main_subject_off
|
|
| 123 |
|
| 124 |
# Avoid cropping: retain original size and save the entire model
|
| 125 |
gltf_path = f"./{image_path.stem}.gltf"
|
| 126 |
-
o3d.io.
|
| 127 |
return gltf_path
|
| 128 |
|
| 129 |
title = "Enhanced Depth Estimation & 3D Reconstruction with Panorama Background"
|
|
|
|
| 66 |
img = Image.fromarray(subject_depth_map)
|
| 67 |
return [img, gltf_path, gltf_path]
|
| 68 |
except Exception as e:
|
| 69 |
+
print(f"Detailed error: {e}")
|
| 70 |
+
raise Exception("Error reconstructing 3D model") from e
|
| 71 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def create_main_subject_mask(image):
|
| 73 |
"""Generates a binary mask for the main subject using rembg."""
|
| 74 |
# Remove background and create mask
|
|
|
|
| 97 |
def create_3d_obj(image, depth_image, image_path, inpainted_bg, main_subject_offset=0.2):
|
| 98 |
# Ensure depth_image has only main subject depth and no background depth
|
| 99 |
depth_image = np.array(depth_image)
|
| 100 |
+
|
| 101 |
+
# Print shapes and depth range for debugging
|
| 102 |
+
print(f"Image shape: {image.shape}, Depth map shape: {depth_image.shape}")
|
| 103 |
+
print(f"Depth map min/max: {depth_image.min()}/{depth_image.max()}")
|
| 104 |
+
|
| 105 |
# Convert image and depth_image to Open3D format
|
| 106 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
| 107 |
+
o3d.geometry.Image(image.astype(np.uint8)),
|
| 108 |
+
o3d.geometry.Image(depth_image.astype(np.float32)),
|
| 109 |
convert_rgb_to_intensity=False
|
| 110 |
)
|
| 111 |
+
|
| 112 |
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, o3d.camera.PinholeCameraIntrinsic(
|
| 113 |
width=image.shape[1], height=image.shape[0], fx=1.0, fy=1.0, cx=image.shape[1] / 2, cy=image.shape[0] / 2))
|
| 114 |
|
|
|
|
| 124 |
|
| 125 |
# Avoid cropping: retain original size and save the entire model
|
| 126 |
gltf_path = f"./{image_path.stem}.gltf"
|
| 127 |
+
o3d.io.write_point_cloud(gltf_path, pcd) # Save as point cloud instead of mesh
|
| 128 |
return gltf_path
|
| 129 |
|
| 130 |
title = "Enhanced Depth Estimation & 3D Reconstruction with Panorama Background"
|