codic commited on
Commit
2cbda3c
·
verified ·
1 Parent(s): 25f93b7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -2
app.py CHANGED
@@ -104,7 +104,11 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
104
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
105
 
106
  if len(pcd.points) < 100:
107
- raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
 
 
 
 
108
 
109
  if not pcd.has_normals():
110
  pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.25, max_nn=50))
@@ -130,7 +134,7 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
130
  gltf_path = f"./{image_path.stem}.gltf"
131
  o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
132
  return gltf_path
133
-
134
  # Gradio Interface
135
  title = "Depth Estimation & 3D Reconstruction Demo"
136
  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."
 
104
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
105
 
106
  if len(pcd.points) < 100:
107
+ # Attempt fallback depth level
108
+ depth -= 1
109
+ if depth < 6: # Prevent infinite fallback
110
+ raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
111
+ return create_3d_obj(foreground, depth_image, background, image_path, depth=depth)
112
 
113
  if not pcd.has_normals():
114
  pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.25, max_nn=50))
 
134
  gltf_path = f"./{image_path.stem}.gltf"
135
  o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
136
  return gltf_path
137
+
138
  # Gradio Interface
139
  title = "Depth Estimation & 3D Reconstruction Demo"
140
  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."