freealise commited on
Commit
da39b9f
1 Parent(s): 8ae6715

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -574,7 +574,7 @@ def draw_mask(l, t, v, d, evt: gr.EventData):
574
  return gr.ImageEditor(value=d)
575
 
576
 
577
- def findNormals():
578
  global depths
579
  d_im = cv2.cvtColor(cv2.imread(depths[frame_selected]).astype(np.uint8), cv2.COLOR_BGR2GRAY)
580
  zy, zx = np.gradient(d_im)
@@ -583,7 +583,10 @@ def findNormals():
583
  #zx = cv2.Sobel(d_im, cv2.CV_64F, 1, 0, ksize=5)
584
  #zy = cv2.Sobel(d_im, cv2.CV_64F, 0, 1, ksize=5)
585
 
586
- normal = np.dstack((np.ones_like(d_im), zy, -zx))
 
 
 
587
  n = np.linalg.norm(normal, axis=2)
588
  normal[:, :, 0] /= n
589
  normal[:, :, 1] /= n
@@ -831,8 +834,9 @@ with gr.Blocks(css=css, js=js) as demo:
831
  reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, output_depth])
832
 
833
  normals_out = gr.Image(label="Normal map", interactive=False)
 
834
  find_normals = gr.Button("Find normals")
835
- find_normals.click(fn=findNormals, inputs=None, outputs=[normals_out])
836
 
837
  with gr.Column():
838
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')
 
574
  return gr.ImageEditor(value=d)
575
 
576
 
577
+ def findNormals(format):
578
  global depths
579
  d_im = cv2.cvtColor(cv2.imread(depths[frame_selected]).astype(np.uint8), cv2.COLOR_BGR2GRAY)
580
  zy, zx = np.gradient(d_im)
 
583
  #zx = cv2.Sobel(d_im, cv2.CV_64F, 1, 0, ksize=5)
584
  #zy = cv2.Sobel(d_im, cv2.CV_64F, 0, 1, ksize=5)
585
 
586
+ if format == "opengl":
587
+ zy = -zy
588
+
589
+ normal = np.dstack((np.ones_like(d_im), -zy, -zx))
590
  n = np.linalg.norm(normal, axis=2)
591
  normal[:, :, 0] /= n
592
  normal[:, :, 1] /= n
 
834
  reset.click(fn=reset_mask, inputs=None, outputs=[output_mask, output_depth])
835
 
836
  normals_out = gr.Image(label="Normal map", interactive=False)
837
+ format_normals = gr.Radio(choices=["directx", "opengl"])
838
  find_normals = gr.Button("Find normals")
839
+ find_normals.click(fn=findNormals, inputs=[format_normals], outputs=[normals_out])
840
 
841
  with gr.Column():
842
  model_type = gr.Dropdown([("small", "vits"), ("base", "vitb"), ("large", "vitl")], type="value", value="vits", label='Model Type')