codic commited on
Commit
315ac2a
·
verified ·
1 Parent(s): 6011871
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -20,7 +20,7 @@ def process_image(image_path, depth_map_path=None):
20
  image_path = Path(image_path)
21
  image_raw = Image.open(image_path).convert("RGB")
22
  image = image_raw.resize(
23
- (4072, int(4072 * image_raw.size[1] / image_raw.size[0])),
24
  Image.Resampling.LANCZOS,
25
  )
26
 
@@ -147,7 +147,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
147
 
148
  # Define camera intrinsics based on image dimensions
149
  w, h = foreground.shape[1], foreground.shape[0]
150
- camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(w, h, 3000, 3000, w / 2, h / 2)
151
 
152
  # Generate point cloud and apply depth-focused filtering
153
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
@@ -157,7 +157,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
157
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
158
 
159
  # Estimate normals with refined parameters
160
- pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.05, max_nn=100))
161
  pcd.orient_normals_consistent_tangent_plane(k=10)
162
 
163
 
@@ -175,7 +175,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
175
 
176
 
177
  # Simplify with smaller voxel size for more detail
178
- voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 6200
179
  mesh = mesh_raw.simplify_vertex_clustering(
180
  voxel_size=voxel_size,
181
  contraction=o3d.geometry.SimplificationContraction.Average,
@@ -195,7 +195,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
195
  # Save high-resolution texture image
196
  texture_path = f"./{image_path.stem}_texture_highres.png"
197
  foreground_pil = Image.fromarray(foreground)
198
- high_res_texture = foreground_pil.resize((5096, 5096), Image.LANCZOS) # Increased resolution for finer details
199
  high_res_texture.save(texture_path)
200
 
201
  # Apply the high-resolution texture and export the mesh as a GLTF file
 
20
  image_path = Path(image_path)
21
  image_raw = Image.open(image_path).convert("RGB")
22
  image = image_raw.resize(
23
+ (3072, int(3072 * image_raw.size[1] / image_raw.size[0])),
24
  Image.Resampling.LANCZOS,
25
  )
26
 
 
147
 
148
  # Define camera intrinsics based on image dimensions
149
  w, h = foreground.shape[1], foreground.shape[0]
150
+ camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(w, h, 2000, 2000, w / 2, h / 2)
151
 
152
  # Generate point cloud and apply depth-focused filtering
153
  pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
 
157
  raise RuntimeError("Insufficient points in the point cloud for normals estimation.")
158
 
159
  # Estimate normals with refined parameters
160
+ pcd.estimate_normals(search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=150))
161
  pcd.orient_normals_consistent_tangent_plane(k=10)
162
 
163
 
 
175
 
176
 
177
  # Simplify with smaller voxel size for more detail
178
+ voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 5200
179
  mesh = mesh_raw.simplify_vertex_clustering(
180
  voxel_size=voxel_size,
181
  contraction=o3d.geometry.SimplificationContraction.Average,
 
195
  # Save high-resolution texture image
196
  texture_path = f"./{image_path.stem}_texture_highres.png"
197
  foreground_pil = Image.fromarray(foreground)
198
+ high_res_texture = foreground_pil.resize((3096, 3096), Image.LANCZOS) # Increased resolution for finer details
199
  high_res_texture.save(texture_path)
200
 
201
  # Apply the high-resolution texture and export the mesh as a GLTF file