codic commited on
Commit
823b761
·
verified ·
1 Parent(s): 9348575

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -75,11 +75,11 @@ def process_image(image_path, depth_map_path=None):
75
  return [img, gltf_path, gltf_path]
76
  except Exception:
77
  print("Error with default depth. Retrying with a shallower depth.")
78
- gltf_path = create_3d_obj(np.array(image), blended_depth_image, image_path, depth=9)
79
  img = Image.fromarray(blended_depth_image)
80
  return [img, gltf_path, gltf_path]
81
 
82
- def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
83
  # Resize and normalize the depth image
84
  depth_image_resized = np.array(
85
  Image.fromarray(depth_image).resize(rgb_image.shape[:2][::-1], Image.LANCZOS)
@@ -111,7 +111,7 @@ def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
111
  # Estimate and orient normals
112
  if not pcd.has_normals():
113
  print("Estimating normals with increased search radius for sparse data...")
114
- pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.25, max_nn=50))
115
 
116
  if pcd.has_normals():
117
  pcd.orient_normals_towards_camera_location(camera_location=np.array([0.0, 0.0, 1500.0]))
@@ -124,12 +124,12 @@ def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
124
  )
125
 
126
  # Mesh simplification and reduced smoothing for better detail
127
- voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 400 # Decreased voxel size for finer detail
128
  mesh = mesh_raw.simplify_vertex_clustering(
129
  voxel_size=voxel_size,
130
  contraction=o3d.geometry.SimplificationContraction.Average,
131
  )
132
- mesh = mesh.filter_smooth_simple(number_of_iterations=3) # Reduced smoothing iterations for sharpness
133
  bbox = pcd.get_axis_aligned_bounding_box()
134
  mesh_crop = mesh.crop(bbox)
135
 
 
75
  return [img, gltf_path, gltf_path]
76
  except Exception:
77
  print("Error with default depth. Retrying with a shallower depth.")
78
+ gltf_path = create_3d_obj(np.array(image), blended_depth_image, image_path, depth=12)
79
  img = Image.fromarray(blended_depth_image)
80
  return [img, gltf_path, gltf_path]
81
 
82
+ def create_3d_obj(rgb_image, depth_image, image_path, depth=12):
83
  # Resize and normalize the depth image
84
  depth_image_resized = np.array(
85
  Image.fromarray(depth_image).resize(rgb_image.shape[:2][::-1], Image.LANCZOS)
 
111
  # Estimate and orient normals
112
  if not pcd.has_normals():
113
  print("Estimating normals with increased search radius for sparse data...")
114
+ pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.15, max_nn=40))
115
 
116
  if pcd.has_normals():
117
  pcd.orient_normals_towards_camera_location(camera_location=np.array([0.0, 0.0, 1500.0]))
 
124
  )
125
 
126
  # Mesh simplification and reduced smoothing for better detail
127
+ voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 612 # Decreased voxel size for finer detail
128
  mesh = mesh_raw.simplify_vertex_clustering(
129
  voxel_size=voxel_size,
130
  contraction=o3d.geometry.SimplificationContraction.Average,
131
  )
132
+ mesh = mesh.filter_smooth_simple(number_of_iterations=2) # Reduced smoothing iterations for sharpness
133
  bbox = pcd.get_axis_aligned_bounding_box()
134
  mesh_crop = mesh.crop(bbox)
135