freealise commited on
Commit
ea2584d
1 Parent(s): 568fe67

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -10
app.py CHANGED
@@ -227,8 +227,10 @@ def pano_depth_to_world_points(depth, scale):
227
  def rgb2gray(rgb):
228
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
229
 
230
- def get_mesh(image, depth):
231
  fnum = frame_selected
 
 
232
  gdepth = rgb2gray(depth[fnum][0])
233
  print('depth to gray - ok')
234
  points = pano_depth_to_world_points(gdepth, 1)
@@ -243,7 +245,7 @@ def get_mesh(image, depth):
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][0], cv2.COLOR_RGB2RGBA)
247
  colors = rgba.reshape(-1, 4)
248
  clrs = [[128, 128, 128, 0]]
249
 
@@ -265,23 +267,21 @@ def get_mesh(image, depth):
265
  scene.export(glb_path)
266
  print('file - ok')
267
  return glb_path
268
-
269
 
270
  def blur_image(image, depth, blur_data):
271
- fnum = frame_selected
272
  blur_a = blur_data.split()
273
  print(f'blur data {blur_data}')
274
 
275
- blur_frame = image[fnum][0].copy()
276
  j = 0
277
  while j < 256:
278
  i = 255 - j
279
  blur_lo = np.array([i,i,i])
280
  blur_hi = np.array([i+1,i+1,i+1])
281
- blur_mask = cv2.inRange(depth[fnum][0], blur_lo, blur_hi)
282
 
283
  print(f'kernel size {int(blur_a[j])}')
284
- blur = cv2.GaussianBlur(image[fnum][0], (int(blur_a[j]), int(blur_a[j])), 0)
285
 
286
  blur_frame[blur_mask>0] = blur[blur_mask>0]
287
  j = j + 1
@@ -347,7 +347,6 @@ with gr.Blocks(css=css) as demo:
347
  output_depth = gr.Gallery(label="Depth", type='numpy', preview=True, columns=8192, interactive=False)
348
  output_frame.select(fn=select_frame, inputs=None, outputs=[output_depth], show_progress='hidden')
349
  output_depth.select(fn=select_frame, inputs=None, outputs=[output_frame], show_progress='hidden')
350
- output_blur = gr.ImageEditor(label="Blurred", type='numpy', interactive=True)
351
  submit = gr.Button("Submit")
352
  with gr.Column():
353
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
@@ -398,7 +397,6 @@ with gr.Blocks(css=css) as demo:
398
  <polyline id='pl' points='-3,0 0,127 255,127 258,0' stroke='url(#lg)' fill='none' stroke-width='3'/>
399
  </svg>""")
400
  txt_in = gr.Textbox(value="", label="Blur kernel size")
401
- blur_btn = gr.Button("Blur")
402
  html = gr.HTML(value="""<label for='zoom'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' min='0.157' max='1.57' step='0.001' oninput='
403
  BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize = Math.ceil(Math.log2(Math.PI/this.value));
404
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = 2.0;
@@ -492,7 +490,6 @@ with gr.Blocks(css=css) as demo:
492
 
493
  submit.click(on_submit, inputs=[input_video, model_type], outputs=[processed_video, processed_zip, output_frame, output_depth])
494
  render.click(partial(get_mesh), inputs=[output_frame, output_depth], outputs=[result])
495
- blur_btn.click(blur_image, inputs=[output_frame, output_depth, txt_in], outputs=[output_blur])
496
 
497
  example_files = os.listdir('examples')
498
  example_files.sort()
 
227
  def rgb2gray(rgb):
228
  return np.dot(rgb[...,:3], [0.333, 0.333, 0.333])
229
 
230
+ def get_mesh(image, depth, blur_data):
231
  fnum = frame_selected
232
+ blur_img = blur_image(image[fnum][0], depth[fnum][0], blur_data)
233
+
234
  gdepth = rgb2gray(depth[fnum][0])
235
  print('depth to gray - ok')
236
  points = pano_depth_to_world_points(gdepth, 1)
 
245
  verts = pts3d.reshape(-1, 3)
246
  #triangles = create_triangles(image.shape[0], image.shape[1])
247
  #print('triangles - ok')
248
+ rgba = cv2.cvtColor(blur_img, cv2.COLOR_RGB2RGBA)
249
  colors = rgba.reshape(-1, 4)
250
  clrs = [[128, 128, 128, 0]]
251
 
 
267
  scene.export(glb_path)
268
  print('file - ok')
269
  return glb_path
 
270
 
271
  def blur_image(image, depth, blur_data):
 
272
  blur_a = blur_data.split()
273
  print(f'blur data {blur_data}')
274
 
275
+ blur_frame = image.copy()
276
  j = 0
277
  while j < 256:
278
  i = 255 - j
279
  blur_lo = np.array([i,i,i])
280
  blur_hi = np.array([i+1,i+1,i+1])
281
+ blur_mask = cv2.inRange(depth, blur_lo, blur_hi)
282
 
283
  print(f'kernel size {int(blur_a[j])}')
284
+ blur = cv2.GaussianBlur(image, (int(blur_a[j]), int(blur_a[j])), 0)
285
 
286
  blur_frame[blur_mask>0] = blur[blur_mask>0]
287
  j = j + 1
 
347
  output_depth = gr.Gallery(label="Depth", type='numpy', preview=True, columns=8192, interactive=False)
348
  output_frame.select(fn=select_frame, inputs=None, outputs=[output_depth], show_progress='hidden')
349
  output_depth.select(fn=select_frame, inputs=None, outputs=[output_frame], show_progress='hidden')
 
350
  submit = gr.Button("Submit")
351
  with gr.Column():
352
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
 
397
  <polyline id='pl' points='-3,0 0,127 255,127 258,0' stroke='url(#lg)' fill='none' stroke-width='3'/>
398
  </svg>""")
399
  txt_in = gr.Textbox(value="", label="Blur kernel size")
 
400
  html = gr.HTML(value="""<label for='zoom'>Zoom</label><input id='zoom' type='range' style='width:256px;height:1em;' min='0.157' max='1.57' step='0.001' oninput='
401
  BABYLON.Engine.LastCreatedScene.getNodes()[1].material.pointSize = Math.ceil(Math.log2(Math.PI/this.value));
402
  BABYLON.Engine.LastCreatedScene.activeCamera.metadata.pipeline.imageProcessing.contrast = 2.0;
 
490
 
491
  submit.click(on_submit, inputs=[input_video, model_type], outputs=[processed_video, processed_zip, output_frame, output_depth])
492
  render.click(partial(get_mesh), inputs=[output_frame, output_depth], outputs=[result])
 
493
 
494
  example_files = os.listdir('examples')
495
  example_files.sort()