Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -576,20 +576,25 @@ def draw_mask(l, t, v, d, evt: gr.EventData):
|
|
576 |
|
577 |
def findNormals():
|
578 |
global depths
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
|
|
|
|
|
|
|
|
|
|
593 |
|
594 |
|
595 |
load_model="""
|
|
|
576 |
|
577 |
def findNormals():
|
578 |
global depths
|
579 |
+
d_im = cv2.imread(depths[frame_selected]).astype(np.uint8)
|
580 |
+
zy, zx = np.gradient(d_im)
|
581 |
+
# You may also consider using Sobel to get a joint Gaussian smoothing and differentation
|
582 |
+
# to reduce noise
|
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((-zx, -zy, np.ones_like(d_im)))
|
587 |
+
n = np.linalg.norm(normal, axis=2)
|
588 |
+
normal[:, :, 0] /= n
|
589 |
+
normal[:, :, 1] /= n
|
590 |
+
normal[:, :, 2] /= n
|
591 |
+
|
592 |
+
# offset and rescale values to be in 0-255
|
593 |
+
normal += 1
|
594 |
+
normal /= 2
|
595 |
+
normal *= 255
|
596 |
+
|
597 |
+
return normal[:, :, ::-1]
|
598 |
|
599 |
|
600 |
load_model="""
|