Update app.py
Browse files
app.py
CHANGED
|
@@ -131,7 +131,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 131 |
|
| 132 |
# Define camera intrinsics based on image dimensions
|
| 133 |
w, h = foreground.shape[1], foreground.shape[0]
|
| 134 |
-
camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(w, h,
|
| 135 |
|
| 136 |
# Generate point cloud and apply depth-focused filtering
|
| 137 |
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
|
|
@@ -152,7 +152,7 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 152 |
)
|
| 153 |
|
| 154 |
# Simplify with smaller voxel size for more detail
|
| 155 |
-
voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) /
|
| 156 |
mesh = mesh_raw.simplify_vertex_clustering(
|
| 157 |
voxel_size=voxel_size,
|
| 158 |
contraction=o3d.geometry.SimplificationContraction.Average,
|
|
@@ -170,13 +170,14 @@ def create_3d_obj(foreground, depth_image, image_path, depth=12, edge_strength=0
|
|
| 170 |
uvs = np.array([[v[0] / w, 1 - v[1] / h] for v in mesh_crop.vertices])
|
| 171 |
mesh_crop.triangle_uvs = o3d.utility.Vector2dVector(np.repeat(uvs, 3, axis=0))
|
| 172 |
|
| 173 |
-
# Save texture image
|
| 174 |
-
texture_path = f"./{image_path.stem}
|
| 175 |
-
|
| 176 |
-
|
|
|
|
| 177 |
|
| 178 |
# Export to glTF format
|
| 179 |
-
gltf_path = f"./{image_path.stem}.gltf"
|
| 180 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 181 |
|
| 182 |
return gltf_path
|
|
|
|
| 131 |
|
| 132 |
# Define camera intrinsics based on image dimensions
|
| 133 |
w, h = foreground.shape[1], foreground.shape[0]
|
| 134 |
+
camera_intrinsic = o3d.camera.PinholeCameraIntrinsic(w, h, 3000, 3000, w / 2, h / 2)
|
| 135 |
|
| 136 |
# Generate point cloud and apply depth-focused filtering
|
| 137 |
pcd = o3d.geometry.PointCloud.create_from_rgbd_image(rgbd_image, camera_intrinsic)
|
|
|
|
| 152 |
)
|
| 153 |
|
| 154 |
# Simplify with smaller voxel size for more detail
|
| 155 |
+
voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 3200
|
| 156 |
mesh = mesh_raw.simplify_vertex_clustering(
|
| 157 |
voxel_size=voxel_size,
|
| 158 |
contraction=o3d.geometry.SimplificationContraction.Average,
|
|
|
|
| 170 |
uvs = np.array([[v[0] / w, 1 - v[1] / h] for v in mesh_crop.vertices])
|
| 171 |
mesh_crop.triangle_uvs = o3d.utility.Vector2dVector(np.repeat(uvs, 3, axis=0))
|
| 172 |
|
| 173 |
+
# Save high-resolution texture image
|
| 174 |
+
texture_path = f"./{image_path.stem}_texture_highres.png"
|
| 175 |
+
high_res_texture = foreground.resize((4096, 4096), Image.LANCZOS) # Increased resolution for finer details
|
| 176 |
+
high_res_texture.save(texture_path)
|
| 177 |
+
mesh_crop.textures = [o3d.geometry.Image(np.array(high_res_texture))]
|
| 178 |
|
| 179 |
# Export to glTF format
|
| 180 |
+
gltf_path = f"./{image_path.stem}_high_quality.gltf"
|
| 181 |
o3d.io.write_triangle_mesh(gltf_path, mesh_crop, write_triangle_uvs=True)
|
| 182 |
|
| 183 |
return gltf_path
|