Spaces:
Build error
Build error
handle error, update require
Browse files- README.md +1 -1
- app.py +18 -9
- examples/4-thomas-le-pRJhn4MbsMM-unsplash.jpg +0 -0
- requirements.txt +1 -1
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: ⚡
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 2.9.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: red
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 2.9.3
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
CHANGED
|
@@ -35,13 +35,21 @@ def process_image(image_path):
|
|
| 35 |
).squeeze()
|
| 36 |
output = prediction.cpu().numpy()
|
| 37 |
depth_image = (output * 255 / np.max(output)).astype('uint8')
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
depth_o3d = o3d.geometry.Image(depth_image)
|
| 46 |
image_o3d = o3d.geometry.Image(rgb_image)
|
| 47 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
|
@@ -60,6 +68,8 @@ def create_3d_obj(rgb_image, depth_image, image_path):
|
|
| 60 |
np.zeros((1, 3))) # invalidate existing normals
|
| 61 |
pcd.estimate_normals(
|
| 62 |
search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=30))
|
|
|
|
|
|
|
| 63 |
pcd.transform([[1, 0, 0, 0],
|
| 64 |
[0, -1, 0, 0],
|
| 65 |
[0, 0, -1, 0],
|
|
@@ -72,7 +82,7 @@ def create_3d_obj(rgb_image, depth_image, image_path):
|
|
| 72 |
print('run Poisson surface reconstruction')
|
| 73 |
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
|
| 74 |
mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
|
| 75 |
-
pcd, depth=
|
| 76 |
|
| 77 |
voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 256
|
| 78 |
print(f'voxel_size = {voxel_size:e}')
|
|
@@ -84,7 +94,6 @@ def create_3d_obj(rgb_image, depth_image, image_path):
|
|
| 84 |
# mesh.remove_vertices_by_mask(vertices_to_remove)
|
| 85 |
bbox = pcd.get_axis_aligned_bounding_box()
|
| 86 |
mesh_crop = mesh.crop(bbox)
|
| 87 |
-
print(mesh)
|
| 88 |
gltf_path = f'./{image_path.stem}.gltf'
|
| 89 |
o3d.io.write_triangle_mesh(
|
| 90 |
gltf_path, mesh_crop, write_triangle_uvs=True)
|
|
|
|
| 35 |
).squeeze()
|
| 36 |
output = prediction.cpu().numpy()
|
| 37 |
depth_image = (output * 255 / np.max(output)).astype('uint8')
|
| 38 |
+
try:
|
| 39 |
+
gltf_path = create_3d_obj(np.array(image), depth_image, image_path)
|
| 40 |
+
img = Image.fromarray(depth_image)
|
| 41 |
+
return [img, gltf_path, gltf_path]
|
| 42 |
+
except Exception as e:
|
| 43 |
+
gltf_path = create_3d_obj(
|
| 44 |
+
np.array(image), depth_image, image_path, depth=8)
|
| 45 |
+
img = Image.fromarray(depth_image)
|
| 46 |
+
return [img, gltf_path, gltf_path]
|
| 47 |
+
except:
|
| 48 |
+
print("Error reconstructing 3D model")
|
| 49 |
+
raise Exception("Error reconstructing 3D model")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def create_3d_obj(rgb_image, depth_image, image_path, depth=10):
|
| 53 |
depth_o3d = o3d.geometry.Image(depth_image)
|
| 54 |
image_o3d = o3d.geometry.Image(rgb_image)
|
| 55 |
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
|
|
|
|
| 68 |
np.zeros((1, 3))) # invalidate existing normals
|
| 69 |
pcd.estimate_normals(
|
| 70 |
search_param=o3d.geometry.KDTreeSearchParamHybrid(radius=0.01, max_nn=30))
|
| 71 |
+
pcd.orient_normals_towards_camera_location(
|
| 72 |
+
camera_location=np.array([0., 0., 1000.]))
|
| 73 |
pcd.transform([[1, 0, 0, 0],
|
| 74 |
[0, -1, 0, 0],
|
| 75 |
[0, 0, -1, 0],
|
|
|
|
| 82 |
print('run Poisson surface reconstruction')
|
| 83 |
with o3d.utility.VerbosityContextManager(o3d.utility.VerbosityLevel.Debug) as cm:
|
| 84 |
mesh_raw, densities = o3d.geometry.TriangleMesh.create_from_point_cloud_poisson(
|
| 85 |
+
pcd, depth=depth, width=0, scale=1.1, linear_fit=True)
|
| 86 |
|
| 87 |
voxel_size = max(mesh_raw.get_max_bound() - mesh_raw.get_min_bound()) / 256
|
| 88 |
print(f'voxel_size = {voxel_size:e}')
|
|
|
|
| 94 |
# mesh.remove_vertices_by_mask(vertices_to_remove)
|
| 95 |
bbox = pcd.get_axis_aligned_bounding_box()
|
| 96 |
mesh_crop = mesh.crop(bbox)
|
|
|
|
| 97 |
gltf_path = f'./{image_path.stem}.gltf'
|
| 98 |
o3d.io.write_triangle_mesh(
|
| 99 |
gltf_path, mesh_crop, write_triangle_uvs=True)
|
examples/4-thomas-le-pRJhn4MbsMM-unsplash.jpg
DELETED
|
Binary file (218 kB)
|
|
|
requirements.txt
CHANGED
|
@@ -2,6 +2,6 @@ torch
|
|
| 2 |
git+https://github.com/nielsrogge/transformers.git@add_dpt_redesign#egg=transformers
|
| 3 |
numpy
|
| 4 |
Pillow
|
| 5 |
-
gradio>=2.9.
|
| 6 |
jinja2
|
| 7 |
open3d
|
|
|
|
| 2 |
git+https://github.com/nielsrogge/transformers.git@add_dpt_redesign#egg=transformers
|
| 3 |
numpy
|
| 4 |
Pillow
|
| 5 |
+
gradio>=2.9.3
|
| 6 |
jinja2
|
| 7 |
open3d
|