freealise commited on
Commit
1d201cc
1 Parent(s): 5009bf7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -7
app.py CHANGED
@@ -9,7 +9,7 @@ import torch.nn.functional as F
9
  from torchvision import transforms
10
  from torchvision.transforms import Compose
11
  import trimesh
12
- #from geometry import create_triangles
13
  import tempfile
14
  from functools import partial
15
  import spaces
@@ -239,6 +239,7 @@ def pano_depth_to_world_points(depth):
239
 
240
  pts3d = [[0,0,0]]
241
  uv = [[0,0]]
 
242
  for i in range(0, 1): #(0,2)
243
  for j in range(0, 1): #(0,2)
244
  #rnd_lon = (np.random.rand(depth.shape[0]*depth.shape[1]) - 0.5) / 8
@@ -251,16 +252,22 @@ def pano_depth_to_world_points(depth):
251
  y = radius * np.cos(d_lat)
252
  z = radius * np.sin(d_lon) * np.sin(d_lat)
253
 
 
 
 
 
254
  pts = np.stack([x, y, z], axis=1)
255
  uvs = np.stack([lon, lat], axis=1)
 
256
 
257
  pts3d = np.concatenate((pts3d, pts), axis=0)
258
  uv = np.concatenate((uv, uvs), axis=0)
 
259
  #print(f'i: {i}, j: {j}')
260
  j = j+1
261
  i = i+1
262
 
263
- return [pts3d, uv]
264
 
265
  def rgb2gray(rgb):
266
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
@@ -287,6 +294,7 @@ def get_mesh(image, depth, blur_data, loadall):
287
  points = pano_depth_to_world_points(gdepth)
288
  pts3d = points[0]
289
  uv = points[1]
 
290
  print('radius from depth - ok')
291
 
292
  # Create a trimesh mesh from the points
@@ -295,6 +303,7 @@ def get_mesh(image, depth, blur_data, loadall):
295
  uvs = uv.reshape(-1, 2)
296
  print(uvs)
297
  verts = pts3d.reshape(-1, 3)
 
298
  rgba = cv2.cvtColor(blur_img, cv2.COLOR_RGB2RGBA)
299
  colors = rgba.reshape(-1, 4)
300
  clrs = [[128,128,128,0]]
@@ -312,18 +321,18 @@ def get_mesh(image, depth, blur_data, loadall):
312
  #if (clrs[j] == pcolors[i]).all():
313
  #cverts[i].append(verts[j])
314
  #j=j+1
315
- mesh.append(trimesh.PointCloud(verts, colors=None))
316
- mesh[len(mesh)-1].merge_vertices()
317
  #i=i+1
318
  mesh_n.append(str(fnum))
319
 
320
- #triangles = create_triangles(rgba.shape[0], rgba.shape[1])
321
- #mesh.append(trimesh.Trimesh(vertices=verts, faces=triangles))
322
  rgba_pil = Image.fromarray(rgba.astype(np.uint8))
323
  material = trimesh.visual.texture.SimpleMaterial(image=rgba_pil)
324
  visuals = trimesh.visual.TextureVisuals(uv=uvs, image=rgba_pil, material=material)
325
  mesh[len(mesh)-1].visual = visuals
326
- #print('triangles - ok')
327
 
328
  #ln = []
329
  #cr = []
 
9
  from torchvision import transforms
10
  from torchvision.transforms import Compose
11
  import trimesh
12
+ from geometry import create_triangles
13
  import tempfile
14
  from functools import partial
15
  import spaces
 
239
 
240
  pts3d = [[0,0,0]]
241
  uv = [[0,0]]
242
+ nl = [[0,0,0]]
243
  for i in range(0, 1): #(0,2)
244
  for j in range(0, 1): #(0,2)
245
  #rnd_lon = (np.random.rand(depth.shape[0]*depth.shape[1]) - 0.5) / 8
 
252
  y = radius * np.cos(d_lat)
253
  z = radius * np.sin(d_lon) * np.sin(d_lat)
254
 
255
+ nx = -np.cos(d_lon) * np.sin(d_lat)
256
+ ny = -np.cos(d_lat)
257
+ nz = -np.sin(d_lon) * np.sin(d_lat)
258
+
259
  pts = np.stack([x, y, z], axis=1)
260
  uvs = np.stack([lon, lat], axis=1)
261
+ nls = np.stack([nx, ny, nz], axis=1)
262
 
263
  pts3d = np.concatenate((pts3d, pts), axis=0)
264
  uv = np.concatenate((uv, uvs), axis=0)
265
+ nl = np.concatenate((nl, nls), axis=0)
266
  #print(f'i: {i}, j: {j}')
267
  j = j+1
268
  i = i+1
269
 
270
+ return [pts3d, uv, nl]
271
 
272
  def rgb2gray(rgb):
273
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
 
294
  points = pano_depth_to_world_points(gdepth)
295
  pts3d = points[0]
296
  uv = points[1]
297
+ nl = points[2]
298
  print('radius from depth - ok')
299
 
300
  # Create a trimesh mesh from the points
 
303
  uvs = uv.reshape(-1, 2)
304
  print(uvs)
305
  verts = pts3d.reshape(-1, 3)
306
+ normals = nl.reshape(-1, 3)
307
  rgba = cv2.cvtColor(blur_img, cv2.COLOR_RGB2RGBA)
308
  colors = rgba.reshape(-1, 4)
309
  clrs = [[128,128,128,0]]
 
321
  #if (clrs[j] == pcolors[i]).all():
322
  #cverts[i].append(verts[j])
323
  #j=j+1
324
+ #mesh.append(trimesh.PointCloud(verts, colors=None))
325
+ #mesh[len(mesh)-1].merge_vertices()
326
  #i=i+1
327
  mesh_n.append(str(fnum))
328
 
329
+ triangles = create_triangles(rgba.shape[0], rgba.shape[1])
330
+ mesh.append(trimesh.Trimesh(vertices=verts, faces=triangles, vertex_normals=normals))
331
  rgba_pil = Image.fromarray(rgba.astype(np.uint8))
332
  material = trimesh.visual.texture.SimpleMaterial(image=rgba_pil)
333
  visuals = trimesh.visual.TextureVisuals(uv=uvs, image=rgba_pil, material=material)
334
  mesh[len(mesh)-1].visual = visuals
335
+ print('triangles - ok')
336
 
337
  #ln = []
338
  #cr = []