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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -67,7 +67,7 @@ def process_image(image_path, depth_map_path=None):
67
  mask_blurred_resized = cv2.resize(mask_blurred, (depth_image.shape[1], depth_image.shape[0]), interpolation=cv2.INTER_LINEAR)
68
 
69
  # Blend depth_image with mask_blurred_resized
70
- blended_depth_image = cv2.addWeighted(depth_image, 0.8, mask_blurred_resized, 0.2, 0)
71
 
72
  try:
73
  gltf_path = create_3d_obj(np.array(image), blended_depth_image, image_path)
@@ -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=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,7 +111,7 @@ def create_3d_obj(rgb_image, depth_image, image_path, depth=12):
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,12 +124,12 @@ def create_3d_obj(rgb_image, depth_image, image_path, depth=12):
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
 
 
67
  mask_blurred_resized = cv2.resize(mask_blurred, (depth_image.shape[1], depth_image.shape[0]), interpolation=cv2.INTER_LINEAR)
68
 
69
  # Blend depth_image with mask_blurred_resized
70
+ blended_depth_image = cv2.addWeighted(depth_image, 0.9, mask_blurred_resized, 0.1, 0)
71
 
72
  try:
73
  gltf_path = create_3d_obj(np.array(image), blended_depth_image, image_path)
 
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=14)
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=14):
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=60))
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()) / 812 # 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=4) # Reduced smoothing iterations for sharpness
133
  bbox = pcd.get_axis_aligned_bounding_box()
134
  mesh_crop = mesh.crop(bbox)
135