codic commited on
Commit
4a47309
·
verified ·
1 Parent(s): e42e284

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -4
app.py CHANGED
@@ -80,7 +80,7 @@ def process_image(image_path, depth_map_path=None):
80
  # Step 6: Create an edge-aware mask (if needed for further processing)
81
  mask = np.all(np.array(foreground) != [0, 0, 0], axis=-1) # Create a mask where the foreground is not black
82
  # Improved edge detection for the main subject
83
- edges = cv2.Canny(img_as_ubyte(mask), threshold1=30, threshold2=150) # Adjust thresholds for edges
84
  edges_dilated = cv2.dilate(edges, np.ones((9, 9), np.uint8), iterations=4) # Larger kernel, fewer gaps
85
  edges_eroded = cv2.erode(edges_dilated, np.ones((9, 9), np.uint8), iterations=2)
86
 
@@ -156,7 +156,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
156
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
157
 
158
  # Estimate normals with refined parameters
159
- pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=100))
160
  pcd.orient_normals_consistent_tangent_plane(k=10)
161
 
162
 
@@ -165,7 +165,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
165
 
166
  # Create Poisson mesh using main subject's isolated depth
167
  mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
168
- pcd, depth=depth, width=0, scale=4, linear_fit=True
169
  )
170
  # Remove low-density artifacts
171
  density_threshold = np.quantile(np.asarray(densities), 0.06) # Adjust quantile as needed
@@ -181,7 +181,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
181
  )
182
 
183
  # Apply Laplacian smoothing
184
- mesh = mesh.filter_smooth_laplacian(number_of_iterations=4)
185
 
186
  # Crop mesh to bounding box around main subject only
187
  bbox = pcd.get_axis_aligned_bounding_box()
 
80
  # Step 6: Create an edge-aware mask (if needed for further processing)
81
  mask = np.all(np.array(foreground) != [0, 0, 0], axis=-1) # Create a mask where the foreground is not black
82
  # Improved edge detection for the main subject
83
+ edges = cv2.Canny(img_as_ubyte(mask), threshold1=15, threshold2=100) # Adjust thresholds for edges
84
  edges_dilated = cv2.dilate(edges, np.ones((9, 9), np.uint8), iterations=4) # Larger kernel, fewer gaps
85
  edges_eroded = cv2.erode(edges_dilated, np.ones((9, 9), np.uint8), iterations=2)
86
 
 
156
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
157
 
158
  # Estimate normals with refined parameters
159
+ pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.05, max_nn=150))
160
  pcd.orient_normals_consistent_tangent_plane(k=10)
161
 
162
 
 
165
 
166
  # Create Poisson mesh using main subject's isolated depth
167
  mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
168
+ pcd, depth=depth, width=0, scale=2, linear_fit=True
169
  )
170
  # Remove low-density artifacts
171
  density_threshold = np.quantile(np.asarray(densities), 0.06) # Adjust quantile as needed
 
181
  )
182
 
183
  # Apply Laplacian smoothing
184
+ mesh = mesh.filter_smooth_laplacian(number_of_iterations=2)
185
 
186
  # Crop mesh to bounding box around main subject only
187
  bbox = pcd.get_axis_aligned_bounding_box()