freealise commited on
Commit
9f110ad
1 Parent(s): 89b318d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -21
app.py CHANGED
@@ -252,10 +252,10 @@ def pano_depth_to_world_points(depth):
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
@@ -286,7 +286,7 @@ def get_mesh(image, depth, blur_data, loadall):
286
  print('depth to gray - ok')
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
@@ -302,26 +302,26 @@ def get_mesh(image, depth, blur_data, loadall):
302
  clrs = np.concatenate((clrs, colors), axis=0)
303
  #i = i+1
304
 
305
- cverts = []
306
- i=0
307
- j=0
308
- while i<len(pcolors):
309
- cverts.append([])
310
- while j<len(clrs):
311
- if (clrs[j] == pcolors[i]).all():
312
- cverts[i].append(verts[j])
313
- j=j+1
314
- mesh.append(trimesh.PointCloud(cverts[i], color=pcolors[i]))
315
- mesh[len(mesh)-1].merge_vertices()
316
- i=i+1
317
  mesh_n.append(str(fnum))
318
 
319
  #triangles = create_triangles(rgba.shape[0], rgba.shape[1])
320
  #mesh.append(trimesh.Trimesh(vertices=verts, faces=triangles))
321
- #rgba_pil = Image.fromarray(rgba.astype(np.uint8))
322
- #material = trimesh.visual.texture.SimpleMaterial(image=rgba_pil)
323
- #visuals = trimesh.visual.TextureVisuals(uv=uvs, image=rgba_pil, material=material)
324
- #mesh[len(mesh)-1].visual = visuals
325
  #print('triangles - ok')
326
 
327
  #ln = []
@@ -449,7 +449,7 @@ def optimize(v, d):
449
 
450
  dcolor = []
451
  for k, f in enumerate(frames):
452
- frame = cv2.cvtColor(cv2.imread(frames[k]).astype(np.uint8), cv2.COLOR_BGR2RGB)
453
 
454
  # convert to np.float32
455
  f = np.float32(frame.reshape((-1,3)))
@@ -495,7 +495,7 @@ def bincount(a):
495
  a2D = a.reshape(-1,a.shape[-1])
496
  col_range = (256, 256, 256) # generically : a2D.max(0)+1
497
  a1D = np.ravel_multi_index(a2D.T, col_range)
498
- return np.unravel_index(np.bincount(a1D).argmax(), col_range)
499
 
500
  def reset_mask():
501
  global frame_selected
 
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
 
286
  print('depth to gray - ok')
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
 
302
  clrs = np.concatenate((clrs, colors), axis=0)
303
  #i = i+1
304
 
305
+ #cverts = []
306
+ #i=0
307
+ #j=0
308
+ #while i<len(pcolors):
309
+ #cverts.append([])
310
+ #while j<len(clrs):
311
+ #if (clrs[j] == pcolors[i]).all():
312
+ #cverts[i].append(verts[j])
313
+ #j=j+1
314
+ mesh.append(trimesh.PointCloud(verts, colors=None))
315
+ mesh[len(mesh)-1].merge_vertices()
316
+ #i=i+1
317
  mesh_n.append(str(fnum))
318
 
319
  #triangles = create_triangles(rgba.shape[0], rgba.shape[1])
320
  #mesh.append(trimesh.Trimesh(vertices=verts, faces=triangles))
321
+ rgba_pil = Image.fromarray(rgba.astype(np.uint8))
322
+ material = trimesh.visual.texture.SimpleMaterial(image=rgba_pil)
323
+ visuals = trimesh.visual.TextureVisuals(uv=uvs, image=rgba_pil, material=material)
324
+ mesh[len(mesh)-1].visual = visuals
325
  #print('triangles - ok')
326
 
327
  #ln = []
 
449
 
450
  dcolor = []
451
  for k, f in enumerate(frames):
452
+ frame = cv2.imread(frames[k]).astype(np.uint8)
453
 
454
  # convert to np.float32
455
  f = np.float32(frame.reshape((-1,3)))
 
495
  a2D = a.reshape(-1,a.shape[-1])
496
  col_range = (256, 256, 256) # generically : a2D.max(0)+1
497
  a1D = np.ravel_multi_index(a2D.T, col_range)
498
+ return list(reversed(np.unravel_index(np.bincount(a1D).argmax(), col_range)))
499
 
500
  def reset_mask():
501
  global frame_selected