codic commited on
Commit
7c75389
·
verified ·
1 Parent(s): fba8e3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -0
app.py CHANGED
@@ -7,6 +7,7 @@ import torch
7
  import numpy as np
8
  from PIL import Image
9
  import open3d as o3d
 
10
  from pathlib import Path
11
  import os
12
  import cv2
@@ -120,6 +121,28 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
120
  # Keep depth values only within the edge mask area (isolating the main subject)
121
  depth_image_sharpened = np.where(edge_mask, depth_image_normalized, 0)
122
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
123
  # Create Open3D RGBD image
124
  depth_o3d = o3d.geometry.Image(depth_image_sharpened)
125
  image_o3d = o3d.geometry.Image(foreground)
 
7
  import numpy as np
8
  from PIL import Image
9
  import open3d as o3d
10
+ import pymesh # Importing PyMesh for advanced mesh handling
11
  from pathlib import Path
12
  import os
13
  import cv2
 
121
  # Keep depth values only within the edge mask area (isolating the main subject)
122
  depth_image_sharpened = np.where(edge_mask, depth_image_normalized, 0)
123
 
124
+ # PyMesh usage for detail refinement
125
+ mesh_data = pymesh.form_mesh(depth_image_sharpened, None) # Create PyMesh mesh structure
126
+ pymesh.remove_degenerated_triangles(mesh_data) # Remove degenerate triangles
127
+ pymesh.collapse_short_edges(mesh_data, 1e-4) # Simplify edges while retaining details
128
+ pymesh.remove_duplicated_faces(mesh_data) # Remove any duplicate face elements
129
+ pymesh.resolve_self_intersection(mesh_data) # Fix intersecting faces for better 3D cohesion
130
+
131
+ # Convert the PyMesh data to an Open3D point cloud for further refinement
132
+ vertices = mesh_data.vertices
133
+ faces = mesh_data.faces
134
+
135
+ # Create an Open3D triangle mesh from vertices and faces
136
+ mesh = o3d.geometry.TriangleMesh()
137
+ mesh.vertices = o3d.utility.Vector3dVector(vertices)
138
+ mesh.triangles = o3d.utility.Vector3iVector(faces)
139
+
140
+ # Compute vertex normals for better visualization
141
+ mesh.compute_vertex_normals()
142
+
143
+ # Optionally, apply smoothing or other processing here
144
+ mesh = mesh.filter_smooth_simple(number_of_iterations=3)
145
+
146
  # Create Open3D RGBD image
147
  depth_o3d = o3d.geometry.Image(depth_image_sharpened)
148
  image_o3d = o3d.geometry.Image(foreground)