freealise commited on
Commit
7399e9a
1 Parent(s): 54a41e3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py CHANGED
@@ -383,6 +383,29 @@ def switch_rows(v):
383
  print(frames[0])
384
  return frames
385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
386
  def reset_mask():
387
  global frame_selected
388
  global masks
@@ -590,7 +613,9 @@ with gr.Blocks(css=css, js=js) as demo:
590
  submit = gr.Button("Submit")
591
  output_frame = gr.Gallery(label="Frames", preview=True, columns=8192, type="numpy")
592
  output_switch = gr.Checkbox(label="Show depths")
 
593
  output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
 
594
  output_mask = gr.ImageEditor(layers=False, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
595
  with gr.Row():
596
  selector = gr.HTML(value="""
 
383
  print(frames[0])
384
  return frames
385
 
386
+ def optimize(v, d):
387
+ global frames
388
+ global depths
389
+
390
+ if d == False:
391
+ if v == True:
392
+ scale = 1
393
+ delta = 0
394
+ ddepth = cv2.CV_16S
395
+
396
+ indices = np.arange(0,256) # List of all colors
397
+ divider = np.linspace(0,255,48+1)[1] # we get a divider
398
+ quantiz = np.int0(np.linspace(0,255,48)) # we get quantization colors
399
+ color_levels = np.clip(np.int0(indices/divider),0,48-1) # color levels 0,1,2..
400
+ palette = quantiz[color_levels]
401
+ for k, f in enumerate(frames):
402
+ frames[k] = cv2.convertScaleAbs(palette[frames[k]]).astype(np.uint8) # Converting image back to uint
403
+ frames[k] = cv2.convertScaleAbs(cv2.Sobel(frames[k], ddepth, 1, 1, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT))
404
+
405
+ return frames
406
+ else:
407
+ return depths
408
+
409
  def reset_mask():
410
  global frame_selected
411
  global masks
 
613
  submit = gr.Button("Submit")
614
  output_frame = gr.Gallery(label="Frames", preview=True, columns=8192, type="numpy")
615
  output_switch = gr.Checkbox(label="Show depths")
616
+ optimize_switch = gr.Checkbox(label="Optimize")
617
  output_switch.input(fn=switch_rows, inputs=[output_switch], outputs=[output_frame])
618
+ optimize_switch.input(fn=optimize, inputs=[optimize_switch, output_switch], outputs=[output_frame])
619
  output_mask = gr.ImageEditor(layers=False, sources=('upload', 'clipboard'), show_download_button=True, type="numpy", interactive=True, transforms=(None,), eraser=gr.Eraser(), brush=gr.Brush(default_size=0, colors=['black', '#505050', '#a0a0a0', 'white']), elem_id="image_edit")
620
  with gr.Row():
621
  selector = gr.HTML(value="""