Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -99,44 +99,38 @@ class RobustDepthTo3DConverter:
|
|
99 |
print(f"Depth estimation error: {e}")
|
100 |
return None
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
pcd.colors = o3d.utility.Vector3dVector(colors)
|
134 |
-
|
135 |
-
return pcd
|
136 |
|
137 |
-
except Exception as e:
|
138 |
-
print(f"Point cloud creation error: {e}")
|
139 |
-
return None
|
140 |
|
141 |
def convert_to_mesh(self, point_cloud):
|
142 |
"""
|
|
|
99 |
print(f"Depth estimation error: {e}")
|
100 |
return None
|
101 |
|
102 |
+
def create_point_cloud(self, image, depth_map):
|
103 |
+
"""
|
104 |
+
Create point cloud with error handling and dimension checks
|
105 |
+
"""
|
106 |
+
if depth_map is None:
|
107 |
+
return None
|
108 |
+
|
109 |
+
try:
|
110 |
+
img_array = np.array(image)
|
111 |
+
depth_map_resized = cv2.resize(depth_map, (img_array.shape[1], img_array.shape[0]), interpolation=cv2.INTER_LINEAR)
|
112 |
+
height, width = img_array.shape[:2]
|
113 |
+
|
114 |
+
step = max(1, min(height, width) // 200)
|
115 |
+
points, colors = [], []
|
116 |
+
|
117 |
+
for y in range(0, height, step):
|
118 |
+
for x in range(0, width, step):
|
119 |
+
z = depth_map_resized[y, x] / 255.0 * 5 # Scaled depth
|
120 |
+
points.append([x, y, z])
|
121 |
+
color = img_array[y, x][:3] / 255.0 if len(img_array[y, x]) >= 3 else [0.5, 0.5, 0.5]
|
122 |
+
colors.append(color)
|
123 |
+
|
124 |
+
pcd = o3d.geometry.PointCloud()
|
125 |
+
pcd.points = o3d.utility.Vector3dVector(points)
|
126 |
+
pcd.colors = o3d.utility.Vector3dVector(colors)
|
127 |
+
|
128 |
+
return pcd
|
129 |
+
|
130 |
+
except Exception as e:
|
131 |
+
print(f"Point cloud creation error: {e}")
|
132 |
+
return None
|
|
|
|
|
|
|
133 |
|
|
|
|
|
|
|
134 |
|
135 |
def convert_to_mesh(self, point_cloud):
|
136 |
"""
|