Update app.py
Browse files
app.py
CHANGED
|
@@ -103,8 +103,8 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 103 |
gradient_magnitude = np.hypot(sobel_x, sobel_y)
|
| 104 |
|
| 105 |
# Multi-scale edge detection to refine boundaries further
|
| 106 |
-
edges_high_res = sobel(gaussian_filter(depth_image_normalized, sigma=
|
| 107 |
-
edges_low_res = sobel(gaussian_filter(depth_image_normalized, sigma=
|
| 108 |
combined_edges = np.maximum(edges_high_res, edges_low_res)
|
| 109 |
|
| 110 |
# Generate an edge mask that captures only strong edges
|
|
@@ -118,6 +118,8 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 118 |
y, x = np.mgrid[:h, :w]
|
| 119 |
z = depth_image_sharpened
|
| 120 |
points_3d = np.vstack((x.flatten(), y.flatten(), z.flatten())).T
|
|
|
|
|
|
|
| 121 |
|
| 122 |
# Create Trimesh object from 3D points and depth-based faces
|
| 123 |
try:
|
|
@@ -125,8 +127,8 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 125 |
mesh = trimesh.Trimesh(vertices=points_3d, process=True)
|
| 126 |
|
| 127 |
# Apply Trimesh filters for further refinement
|
| 128 |
-
mesh.
|
| 129 |
-
mesh.
|
| 130 |
mesh.fill_holes()
|
| 131 |
|
| 132 |
# Simplify with smaller voxel size for more detail
|
|
|
|
| 103 |
gradient_magnitude = np.hypot(sobel_x, sobel_y)
|
| 104 |
|
| 105 |
# Multi-scale edge detection to refine boundaries further
|
| 106 |
+
edges_high_res = sobel(gaussian_filter(depth_image_normalized, sigma=0.3), axis=0) + sobel(gaussian_filter(depth_image_normalized, sigma=0.3), axis=1)
|
| 107 |
+
edges_low_res = sobel(gaussian_filter(depth_image_normalized, sigma=0.5), axis=0) + sobel(gaussian_filter(depth_image_normalized, sigma=0.5), axis=1)
|
| 108 |
combined_edges = np.maximum(edges_high_res, edges_low_res)
|
| 109 |
|
| 110 |
# Generate an edge mask that captures only strong edges
|
|
|
|
| 118 |
y, x = np.mgrid[:h, :w]
|
| 119 |
z = depth_image_sharpened
|
| 120 |
points_3d = np.vstack((x.flatten(), y.flatten(), z.flatten())).T
|
| 121 |
+
if points_3d.shape[0] == 0:
|
| 122 |
+
raise ValueError("No valid points found in depth data for 3D mesh creation.")
|
| 123 |
|
| 124 |
# Create Trimesh object from 3D points and depth-based faces
|
| 125 |
try:
|
|
|
|
| 127 |
mesh = trimesh.Trimesh(vertices=points_3d, process=True)
|
| 128 |
|
| 129 |
# Apply Trimesh filters for further refinement
|
| 130 |
+
mesh.update_faces(mesh.nondegenerate_faces())
|
| 131 |
+
mesh.update_faces(mesh.unique_faces())
|
| 132 |
mesh.fill_holes()
|
| 133 |
|
| 134 |
# Simplify with smaller voxel size for more detail
|