codic commited on
Commit
5636e69
·
verified ·
1 Parent(s): 2cbda3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -82,7 +82,8 @@ def process_image(image_path, depth_map_path=None):
82
  img = Image.fromarray(sharp_depth_image)
83
  return [img, gltf_path, gltf_path]
84
 
85
- def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
 
86
  depth_image_resized = np.array(
87
  Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)
88
  )
@@ -103,12 +104,16 @@ def create_3d_obj(foreground, depth_image, background, image_path, depth=10):
103
 
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))
 
82
  img = Image.fromarray(sharp_depth_image)
83
  return [img, gltf_path, gltf_path]
84
 
85
+ def create_3d_obj(foreground, depth_image, background, image_path, depth=10, min_depth=6):
86
+ # Resize and normalize the depth image
87
  depth_image_resized = np.array(
88
  Image.fromarray(depth_image).resize(foreground.shape[:2][::-1], Image.LANCZOS)
89
  )
 
104
 
105
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
106
 
107
+ # Check the point count
108
+ num_points = len(pcd.points)
109
+ logging.debug(f"Depth level: {depth}, Point count: {num_points}")
110
+
111
+ if num_points < 100:
112
+ # If we have reduced depth below the threshold, raise an error
113
+ if depth <= min_depth:
114
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
115
+ # Otherwise, reduce depth and try again
116
+ return create_3d_obj(foreground, depth_image, background, image_path, depth=depth - 1, min_depth=min_depth)
117
 
118
  if not pcd.has_normals():
119
  pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.25, max_nn=50))