freealise commited on
Commit
28b9027
1 Parent(s): 8b195a3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -0
app.py CHANGED
@@ -574,6 +574,24 @@ def draw_mask(l, t, v, d, evt: gr.EventData):
574
  return gr.ImageEditor(value=d)
575
 
576
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
577
  load_model="""
578
  async(c, o, b, p, d, n, m)=>{
579
  var intv = setInterval(function(){
@@ -807,6 +825,10 @@ with gr.Blocks(css=css, js=js) as demo:
807
  apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, output_depth, output_frame])
808
  reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, output_depth])
809
 
 
 
 
 
810
  with gr.Column():
811
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
812
  processed_video = gr.Video(label="Output Video", format="mp4", interactive=False)
 
574
  return gr.ImageEditor(value=d)
575
 
576
 
577
+ def findNormals():
578
+ global depths
579
+ depth = cv2.imread(depths[frame_selected]).astype(np.float32)
580
+ normals = np.zeros((depth.shape[0], depth.shape[1], 3), dtype=np.float32)
581
+
582
+ for x in range(1, depth.shape[1] - 1):
583
+ for y in range(1, depth.shape[0] - 1):
584
+ t = np.array([x, y - 1, depth[y - 1, x]], dtype=np.float32)
585
+ l = np.array([x - 1, y, depth[y, x - 1]], dtype=np.float32)
586
+ c = np.array([x, y, depth[y, x]], dtype=np.float32)
587
+
588
+ d = np.cross(l - c, t - c)
589
+ n = d / np.linalg.norm(d)
590
+ normals[y, x] = n
591
+
592
+ return (normals * 255 + 127).astype(np.uint8)
593
+
594
+
595
  load_model="""
596
  async(c, o, b, p, d, n, m)=>{
597
  var intv = setInterval(function(){
 
825
  apply.click(fn=apply_mask, inputs=[output_mask, bsize], outputs=[output_mask, output_depth, output_frame])
826
  reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, output_depth])
827
 
828
+ normals_out = gr.Image(label="Normal map", interactive=False)
829
+ find_normals = gr.Button("Find normals")
830
+ find_normals.click(fn=findNormals, inputs=None, outputs=[normals_out])
831
+
832
  with gr.Column():
833
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
834
  processed_video = gr.Video(label="Output Video", format="mp4", interactive=False)