Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -190,31 +190,24 @@ def pano_depth_to_world_points(depth, scale):
|
|
190 |
|
191 |
# Convert depth to radius
|
192 |
radius = (255 - depth.flatten()) * scale
|
|
|
|
|
193 |
|
194 |
lon = np.linspace(0, np.pi*2, depth.shape[1])
|
195 |
lat = np.linspace(0, np.pi, depth.shape[0])
|
196 |
lon, lat = np.meshgrid(lon, lat)
|
197 |
-
lon = lon.flatten()
|
198 |
-
lat = lat.flatten()
|
199 |
|
200 |
# Convert to cartesian coordinates
|
201 |
-
x = np.cos(lon) * np.sin(lat)
|
202 |
-
y = np.cos(lat)
|
203 |
-
z = np.sin(lon) * np.sin(lat)
|
204 |
|
205 |
-
|
206 |
-
y_ = radius * y
|
207 |
-
z_ = radius * z
|
208 |
-
|
209 |
-
_x = 255 * x
|
210 |
-
_y = 255 * y
|
211 |
-
_z = 255 * z
|
212 |
-
|
213 |
-
pts3d = np.stack([x_, y_, z_, _x, _y, _z], axis=1)
|
214 |
uv = np.stack([lon, lat], axis=1)
|
215 |
-
lines = np.arange(0, depth.shape[0]*depth.shape[1], 1)
|
216 |
|
217 |
-
return [pts3d, uv
|
218 |
|
219 |
def rgb2gray(rgb):
|
220 |
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
|
@@ -225,7 +218,6 @@ def get_mesh(image, depth, scale):
|
|
225 |
points = pano_depth_to_world_points(gdepth, scale)
|
226 |
pts3d = points[0]
|
227 |
uv = points[1]
|
228 |
-
lines = points[2]
|
229 |
print('radius from depth - ok')
|
230 |
|
231 |
# Create a trimesh mesh from the points
|
@@ -235,14 +227,10 @@ def get_mesh(image, depth, scale):
|
|
235 |
verts = pts3d.reshape(-1, 3)
|
236 |
#triangles = create_triangles(image.shape[0], image.shape[1])
|
237 |
#print('triangles - ok')
|
238 |
-
segments = trimesh.path.entities.Line(lines).explode()
|
239 |
rgba = cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
|
240 |
colors = rgba.reshape(-1, 4)
|
241 |
-
print(segments[0])
|
242 |
-
print(colors[0])
|
243 |
#mesh = trimesh.Trimesh(vertices=verts, faces=triangles, vertex_colors=colors)
|
244 |
-
mesh = trimesh.
|
245 |
-
#mesh = trimesh.PointCloud(verts, colors=colors)
|
246 |
#material = trimesh.visual.texture.SimpleMaterial(image=image)
|
247 |
#texture = trimesh.visual.TextureVisuals(uv=uv, image=image, material=material)
|
248 |
#mesh.visual = texture
|
|
|
190 |
|
191 |
# Convert depth to radius
|
192 |
radius = (255 - depth.flatten()) * scale
|
193 |
+
d_lon = (np.random.rand(depth.shape[0]*depth.shape[1]) - 0.5) * np.pi*2 / depth.shape[1]
|
194 |
+
d_lat = (np.random.rand(depth.shape[0]*depth.shape[1]) - 0.5) * np.pi / depth.shape[0]
|
195 |
|
196 |
lon = np.linspace(0, np.pi*2, depth.shape[1])
|
197 |
lat = np.linspace(0, np.pi, depth.shape[0])
|
198 |
lon, lat = np.meshgrid(lon, lat)
|
199 |
+
lon = lon.flatten() + d_lon
|
200 |
+
lat = lat.flatten() + d_lat
|
201 |
|
202 |
# Convert to cartesian coordinates
|
203 |
+
x = radius * np.cos(lon) * np.sin(lat)
|
204 |
+
y = radius * np.cos(lat)
|
205 |
+
z = radius * np.sin(lon) * np.sin(lat)
|
206 |
|
207 |
+
pts3d = np.stack([x, y, z], axis=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
208 |
uv = np.stack([lon, lat], axis=1)
|
|
|
209 |
|
210 |
+
return [pts3d, uv]
|
211 |
|
212 |
def rgb2gray(rgb):
|
213 |
return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
|
|
|
218 |
points = pano_depth_to_world_points(gdepth, scale)
|
219 |
pts3d = points[0]
|
220 |
uv = points[1]
|
|
|
221 |
print('radius from depth - ok')
|
222 |
|
223 |
# Create a trimesh mesh from the points
|
|
|
227 |
verts = pts3d.reshape(-1, 3)
|
228 |
#triangles = create_triangles(image.shape[0], image.shape[1])
|
229 |
#print('triangles - ok')
|
|
|
230 |
rgba = cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
|
231 |
colors = rgba.reshape(-1, 4)
|
|
|
|
|
232 |
#mesh = trimesh.Trimesh(vertices=verts, faces=triangles, vertex_colors=colors)
|
233 |
+
mesh = trimesh.PointCloud(verts, colors=colors)
|
|
|
234 |
#material = trimesh.visual.texture.SimpleMaterial(image=image)
|
235 |
#texture = trimesh.visual.TextureVisuals(uv=uv, image=image, material=material)
|
236 |
#mesh.visual = texture
|