Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -173,6 +173,15 @@ def load_model():
|
|
173 |
# Convert depth map to 3D mesh
|
174 |
def depth_to_mesh(depth_map, image, resolution=100):
|
175 |
"""Convert depth map to 3D mesh"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
176 |
# Get dimensions
|
177 |
h, w = depth_map.shape
|
178 |
|
@@ -345,6 +354,8 @@ def convert_image_to_3d():
|
|
345 |
depth_map = depth_map.cpu().numpy()
|
346 |
elif hasattr(depth_map, 'numpy'):
|
347 |
depth_map = depth_map.numpy()
|
|
|
|
|
348 |
|
349 |
return depth_map
|
350 |
|
|
|
173 |
# Convert depth map to 3D mesh
|
174 |
def depth_to_mesh(depth_map, image, resolution=100):
|
175 |
"""Convert depth map to 3D mesh"""
|
176 |
+
# Convert depth_map to numpy array if it's a PIL Image
|
177 |
+
if isinstance(depth_map, Image.Image):
|
178 |
+
depth_map = np.array(depth_map)
|
179 |
+
|
180 |
+
# Make sure the depth map is 2D
|
181 |
+
if len(depth_map.shape) > 2:
|
182 |
+
# If it's a 3D array (like RGB), convert to grayscale
|
183 |
+
depth_map = np.mean(depth_map, axis=2) if depth_map.shape[2] > 1 else depth_map[:,:,0]
|
184 |
+
|
185 |
# Get dimensions
|
186 |
h, w = depth_map.shape
|
187 |
|
|
|
354 |
depth_map = depth_map.cpu().numpy()
|
355 |
elif hasattr(depth_map, 'numpy'):
|
356 |
depth_map = depth_map.numpy()
|
357 |
+
elif isinstance(depth_map, Image.Image):
|
358 |
+
depth_map = np.array(depth_map)
|
359 |
|
360 |
return depth_map
|
361 |
|