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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -7
app.py CHANGED
@@ -182,7 +182,7 @@ def depth_edges_mask(depth):
182
  mask = depth_grad > 0.05
183
  return mask
184
 
185
- def pano_depth_to_world_points(depth, scale):
186
  """
187
  360 depth to world points
188
  given 2D depth is an equirectangular projection of a spherical image
@@ -192,7 +192,7 @@ def pano_depth_to_world_points(depth, scale):
192
  """
193
 
194
  # Convert depth to radius
195
- radius = (255 - depth.flatten()) * scale
196
 
197
  lon = np.linspace(0, np.pi*2, depth.shape[1])
198
  lat = np.linspace(0, np.pi, depth.shape[0])
@@ -210,9 +210,9 @@ def pano_depth_to_world_points(depth, scale):
210
  d_lat = lat + j/2 * np.pi / depth.shape[0]
211
 
212
  # Convert to cartesian coordinates
213
- x = radius * np.cos(d_lon) * np.sin(d_lat)
214
  y = radius * np.cos(d_lat)
215
- z = radius * np.sin(d_lon) * np.sin(d_lat)
216
 
217
  pts = np.stack([x, y, z], axis=1)
218
  uvs = np.stack([lon, lat], axis=1)
@@ -228,13 +228,14 @@ def pano_depth_to_world_points(depth, scale):
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):
232
  fnum = frame_selected
 
233
  blur_img = blur_image(image[fnum][0], depth[fnum][0], blur_data)
234
 
235
  gdepth = rgb2gray(depth[fnum][0])
236
  print('depth to gray - ok')
237
- points = pano_depth_to_world_points(gdepth, 1)
238
  pts3d = points[0]
239
  uv = points[1]
240
  print('radius from depth - ok')
@@ -530,6 +531,7 @@ with gr.Blocks(css=css) as demo:
530
  example_coords = '50.07379596793083,14.437146122950555 50.073799567020004,14.437146774240507 50.07377647505558,14.437161000659017 50.07379496839027,14.437148958238538 50.073823157821664,14.437124189538856'
531
  with gr.Accordion(label="Locations", open=False):
532
  coords = gr.Textbox(value=example_coords, label="Precise coordinates", show_label=False)
 
533
  render = gr.Button("Render")
534
 
535
  def on_submit(uploaded_video,model_type,coordinates):
@@ -562,7 +564,7 @@ with gr.Blocks(css=css) as demo:
562
  return output_video_path
563
 
564
  submit.click(on_submit, inputs=[input_video, model_type, coords], outputs=[processed_video, processed_zip, output_frame, output_depth])
565
- render.click(partial(get_mesh), inputs=[output_frame, output_depth, blur_in], outputs=[result])
566
 
567
  example_files = os.listdir('examples')
568
  example_files.sort()
 
182
  mask = depth_grad > 0.05
183
  return mask
184
 
185
+ def pano_depth_to_world_points(depth, scale, offset):
186
  """
187
  360 depth to world points
188
  given 2D depth is an equirectangular projection of a spherical image
 
192
  """
193
 
194
  # Convert depth to radius
195
+ radius = (255 - depth.flatten())
196
 
197
  lon = np.linspace(0, np.pi*2, depth.shape[1])
198
  lat = np.linspace(0, np.pi, depth.shape[0])
 
210
  d_lat = lat + j/2 * np.pi / depth.shape[0]
211
 
212
  # Convert to cartesian coordinates
213
+ x = radius * np.cos(d_lon) * np.sin(d_lat) + offset[1] * scale
214
  y = radius * np.cos(d_lat)
215
+ z = radius * np.sin(d_lon) * np.sin(d_lat) + offset[0] * scale
216
 
217
  pts = np.stack([x, y, z], axis=1)
218
  uvs = np.stack([lon, lat], axis=1)
 
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')
 
531
  example_coords = '50.07379596793083,14.437146122950555 50.073799567020004,14.437146774240507 50.07377647505558,14.437161000659017 50.07379496839027,14.437148958238538 50.073823157821664,14.437124189538856'
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
  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()