freealise commited on
Commit
2240766
1 Parent(s): 9d7a705

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -33
app.py CHANGED
@@ -228,39 +228,48 @@ def pano_depth_to_world_points(depth, scale, offset):
228
  def rgb2gray(rgb):
229
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
230
 
231
- def get_mesh(image, depth, blur_data, scale):
232
- fnum = frame_selected
233
- offset = locations[fnum]
234
- blur_img = blur_image(image[fnum][0], depth[fnum][0], blur_data)
 
 
 
 
 
 
 
 
235
 
236
- gdepth = rgb2gray(depth[fnum][0])
237
- print('depth to gray - ok')
238
- points = pano_depth_to_world_points(gdepth, scale, offset)
239
- pts3d = points[0]
240
- uv = points[1]
241
- print('radius from depth - ok')
242
-
243
- # Create a trimesh mesh from the points
244
- # Each pixel is connected to its 4 neighbors
245
- # colors are the RGB values of the image
246
-
247
- verts = pts3d.reshape(-1, 3)
248
- #triangles = create_triangles(image.shape[0], image.shape[1])
249
- #print('triangles - ok')
250
- rgba = cv2.cvtColor(blur_img, cv2.COLOR_RGB2RGBA)
251
- colors = rgba.reshape(-1, 4)
252
- clrs = [[128, 128, 128, 0]]
253
-
254
- for i in range(0,1): #(0,4)
255
- clrs = np.concatenate((clrs, colors), axis=0)
256
- i = i+1
257
-
258
- #mesh = trimesh.Trimesh(vertices=verts, faces=triangles, vertex_colors=colors)
259
- mesh = trimesh.PointCloud(verts, colors=clrs)
260
- #material = trimesh.visual.texture.SimpleMaterial(image=image)
261
- #texture = trimesh.visual.TextureVisuals(uv=uv, image=image, material=material)
262
- #mesh.visual = texture
263
- scene = trimesh.Scene([mesh])
 
264
  print('mesh - ok')
265
 
266
  # Save as glb
@@ -532,6 +541,7 @@ with gr.Blocks(css=css) as demo:
532
  with gr.Accordion(label="Locations", open=False):
533
  coords = gr.Textbox(value=example_coords, label="Precise coordinates", show_label=False)
534
  scale_in = gr.Slider(value=255, minimum=1, maximum=1023, label="Scale")
 
535
  render = gr.Button("Render")
536
 
537
  def on_submit(uploaded_video,model_type,coordinates):
@@ -564,7 +574,7 @@ with gr.Blocks(css=css) as demo:
564
  return output_video_path
565
 
566
  submit.click(on_submit, inputs=[input_video, model_type, coords], outputs=[processed_video, processed_zip, output_frame, output_depth])
567
- render.click(partial(get_mesh), inputs=[output_frame, output_depth, blur_in, scale_in], outputs=[result])
568
 
569
  example_files = os.listdir('examples')
570
  example_files.sort()
 
228
  def rgb2gray(rgb):
229
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
230
 
231
+ def get_mesh(image, depth, blur_data, scale, loadall):
232
+ b = frame_selected
233
+ d = frame_selected+1
234
+
235
+ if loadall == True:
236
+ b = 0
237
+ d = len(image)-1
238
+
239
+ mesh = []
240
+ for fnum in range(b, d):
241
+ offset = locations[fnum]
242
+ blur_img = blur_image(image[fnum][0], depth[fnum][0], blur_data)
243
 
244
+ gdepth = rgb2gray(depth[fnum][0])
245
+ print('depth to gray - ok')
246
+ points = pano_depth_to_world_points(gdepth, scale, offset)
247
+ pts3d = points[0]
248
+ uv = points[1]
249
+ print('radius from depth - ok')
250
+
251
+ # Create a trimesh mesh from the points
252
+ # Each pixel is connected to its 4 neighbors
253
+ # colors are the RGB values of the image
254
+
255
+ verts = pts3d.reshape(-1, 3)
256
+ #triangles = create_triangles(image.shape[0], image.shape[1])
257
+ #print('triangles - ok')
258
+ rgba = cv2.cvtColor(blur_img, cv2.COLOR_RGB2RGBA)
259
+ colors = rgba.reshape(-1, 4)
260
+ clrs = [[128, 128, 128, 0]]
261
+
262
+ for i in range(0,1): #(0,4)
263
+ clrs = np.concatenate((clrs, colors), axis=0)
264
+ i = i+1
265
+
266
+ #mesh = trimesh.Trimesh(vertices=verts, faces=triangles, vertex_colors=colors)
267
+ mesh.append(trimesh.PointCloud(verts, colors=clrs))
268
+ #material = trimesh.visual.texture.SimpleMaterial(image=image)
269
+ #texture = trimesh.visual.TextureVisuals(uv=uv, image=image, material=material)
270
+ #mesh.visual = texture
271
+
272
+ scene = trimesh.Scene(mesh)
273
  print('mesh - ok')
274
 
275
  # Save as glb
 
541
  with gr.Accordion(label="Locations", open=False):
542
  coords = gr.Textbox(value=example_coords, label="Precise coordinates", show_label=False)
543
  scale_in = gr.Slider(value=255, minimum=1, maximum=1023, label="Scale")
544
+ load_all = gr.Checkbox(label="Load all")
545
  render = gr.Button("Render")
546
 
547
  def on_submit(uploaded_video,model_type,coordinates):
 
574
  return output_video_path
575
 
576
  submit.click(on_submit, inputs=[input_video, model_type, coords], outputs=[processed_video, processed_zip, output_frame, output_depth])
577
+ render.click(partial(get_mesh), inputs=[output_frame, output_depth, blur_in, scale_in, load_all], outputs=[result])
578
 
579
  example_files = os.listdir('examples')
580
  example_files.sort()