try isolating the main subject --before was working
Browse files
app.py
CHANGED
|
@@ -144,9 +144,14 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 144 |
# Orient normals towards a distant camera position
|
| 145 |
pcd.orient_normals_towards_camera_location(camera_location=np.array([0.0, 0.0, 2000.0]))
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
# Create Poisson mesh using main subject's isolated depth
|
| 148 |
mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
|
| 149 |
-
|
| 150 |
)
|
| 151 |
|
| 152 |
# Simplify with smaller voxel size for more detail
|
|
@@ -160,7 +165,6 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 160 |
mesh = mesh.filter_smooth_laplacian(number_of_iterations=4)
|
| 161 |
|
| 162 |
# Crop mesh to bounding box around main subject only
|
| 163 |
-
bbox = pcd.get_axis_aligned_bounding_box()
|
| 164 |
mesh_crop = mesh.crop(bbox)
|
| 165 |
|
| 166 |
# Compute UV mapping for texturing
|
|
@@ -180,6 +184,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 180 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 181 |
|
| 182 |
return gltf_path
|
|
|
|
| 183 |
# Gradio Interface
|
| 184 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 185 |
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."
|
|
|
|
| 144 |
# Orient normals towards a distant camera position
|
| 145 |
pcd.orient_normals_towards_camera_location(camera_location=np.array([0.0, 0.0, 2000.0]))
|
| 146 |
|
| 147 |
+
# Crop point cloud to main subject bounds
|
| 148 |
+
bbox = pcd.get_axis_aligned_bounding_box()
|
| 149 |
+
bbox.scale(0.5, bbox.get_center()) # Adjust scale to fit the main subject tightly
|
| 150 |
+
pcd_cropped = pcd.crop(bbox)
|
| 151 |
+
|
| 152 |
# Create Poisson mesh using main subject's isolated depth
|
| 153 |
mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
|
| 154 |
+
pcd_cropped, depth=depth, width=0, scale=2, linear_fit=True
|
| 155 |
)
|
| 156 |
|
| 157 |
# Simplify with smaller voxel size for more detail
|
|
|
|
| 165 |
mesh = mesh.filter_smooth_laplacian(number_of_iterations=4)
|
| 166 |
|
| 167 |
# Crop mesh to bounding box around main subject only
|
|
|
|
| 168 |
mesh_crop = mesh.crop(bbox)
|
| 169 |
|
| 170 |
# Compute UV mapping for texturing
|
|
|
|
| 184 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 185 |
|
| 186 |
return gltf_path
|
| 187 |
+
|
| 188 |
# Gradio Interface
|
| 189 |
title = "Depth Estimation & 3D Reconstruction Demo"
|
| 190 |
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."
|