freealise commited on
Commit
5a94562
1 Parent(s): abb6f5d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -161,8 +161,11 @@ def make_video(video_path, outdir='./vis_video_depth', encoder='vits'):
161
  raw_video.release()
162
  # out.release()
163
  cv2.destroyAllWindows()
 
 
 
164
 
165
- return final_vid, final_zip, orig_frames[0], depth_frames[0] #output_path
166
 
167
  def depth_edges_mask(depth):
168
  """Returns a mask of edges in the depth map.
@@ -225,10 +228,10 @@ def pano_depth_to_world_points(depth, scale):
225
  def rgb2gray(rgb):
226
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
227
 
228
- def get_mesh(image, depth, scale):
229
- gdepth = rgb2gray(depth)
230
  print('depth to gray - ok')
231
- points = pano_depth_to_world_points(gdepth, scale)
232
  pts3d = points[0]
233
  uv = points[1]
234
  print('radius from depth - ok')
@@ -240,7 +243,7 @@ def get_mesh(image, depth, scale):
240
  verts = pts3d.reshape(-1, 3)
241
  #triangles = create_triangles(image.shape[0], image.shape[1])
242
  #print('triangles - ok')
243
- rgba = cv2.cvtColor(image, cv2.COLOR_RGB2RGBA)
244
  colors = rgba.reshape(-1, 4)
245
  clrs = [[128, 128, 128, 0]]
246
 
@@ -314,9 +317,9 @@ with gr.Blocks(css=css) as demo:
314
  input_video = gr.Video(label="Input Video", format="mp4")
315
  input_url.change(fn=loadurl, inputs=[input_url], outputs=[input_video])
316
  submit = gr.Button("Submit")
317
- output_frame = gr.Image(label="Frame", type='numpy')
318
- output_depth = gr.Image(label="Depth", type='numpy')
319
- scale = gr.Slider(label="Scale", minimum=0.03125, maximum=2, step=0.03125, value=0.5)
320
  render = gr.Button("Render")
321
  with gr.Column():
322
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
@@ -332,7 +335,7 @@ with gr.Blocks(css=css) as demo:
332
  return output_video_path
333
 
334
  submit.click(on_submit, inputs=[input_video, model_type], outputs=[processed_video, processed_zip, output_frame, output_depth])
335
- render.click(partial(get_mesh), inputs=[output_frame, output_depth, scale], outputs=[result])
336
 
337
  example_files = os.listdir('examples')
338
  example_files.sort()
 
161
  raw_video.release()
162
  # out.release()
163
  cv2.destroyAllWindows()
164
+
165
+ frame_n.value = 0
166
+ frame_n.maximum = len(orig_frames)
167
 
168
+ return final_vid, final_zip, orig_frames, depth_frames #output_path
169
 
170
  def depth_edges_mask(depth):
171
  """Returns a mask of edges in the depth map.
 
228
  def rgb2gray(rgb):
229
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
230
 
231
+ def get_mesh(image, depth, fnum):
232
+ gdepth = rgb2gray(depth[fnum])
233
  print('depth to gray - ok')
234
+ points = pano_depth_to_world_points(gdepth, 1)
235
  pts3d = points[0]
236
  uv = points[1]
237
  print('radius from depth - ok')
 
243
  verts = pts3d.reshape(-1, 3)
244
  #triangles = create_triangles(image.shape[0], image.shape[1])
245
  #print('triangles - ok')
246
+ rgba = cv2.cvtColor(image[fnum], cv2.COLOR_RGB2RGBA)
247
  colors = rgba.reshape(-1, 4)
248
  clrs = [[128, 128, 128, 0]]
249
 
 
317
  input_video = gr.Video(label="Input Video", format="mp4")
318
  input_url.change(fn=loadurl, inputs=[input_url], outputs=[input_video])
319
  submit = gr.Button("Submit")
320
+ output_frame = gr.Gallery(label="Frame", type='numpy', rows=1)
321
+ output_depth = gr.Gallery(label="Depth", type='numpy', rows=1)
322
+ frame_n = gr.Slider(label="Frame #", minimum=0, maximum=0, step=1, value=0)
323
  render = gr.Button("Render")
324
  with gr.Column():
325
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
 
335
  return output_video_path
336
 
337
  submit.click(on_submit, inputs=[input_video, model_type], outputs=[processed_video, processed_zip, output_frame, output_depth])
338
+ render.click(partial(get_mesh), inputs=[output_frame, output_depth, frame_n], outputs=[result])
339
 
340
  example_files = os.listdir('examples')
341
  example_files.sort()