Update app.py
Browse files
app.py
CHANGED
|
@@ -576,10 +576,11 @@ def draw_mask(l, t, b, v, d, evt: gr.EventData):
|
|
| 576 |
else:
|
| 577 |
gradient = cv2.imread('./gradient_small.png').astype(np.uint8)
|
| 578 |
|
| 579 |
-
bg = cv2.cvtColor(d["background"], cv2.
|
| 580 |
-
bg = cv2.cvtColor(bg, cv2.COLOR_RGB2HSV)
|
| 581 |
-
bg[:,:,0] = clrs[:,:,0]
|
| 582 |
-
bg = cv2.cvtColor(bg, cv2.COLOR_HSV2RGB)
|
|
|
|
| 583 |
|
| 584 |
diff = np.abs(cv2.cvtColor(d["background"], cv2.COLOR_RGBA2GRAY).astype(np.int16)-cv2.cvtColor(gradient, cv2.COLOR_RGBA2GRAY).astype(np.int16)).astype(np.uint8)
|
| 585 |
mask = cv2.inRange(diff, 0, t)
|
|
@@ -598,20 +599,21 @@ def draw_mask(l, t, b, v, d, evt: gr.EventData):
|
|
| 598 |
# bg[(bg >= i*255/l) & (bg < (i+1)*255/l)] = i*255/(l-1)
|
| 599 |
#bg = cv2.convertScaleAbs(palette[bg]).astype(np.uint8) # Converting image back to uint
|
| 600 |
|
| 601 |
-
res = np.float32(bg.reshape((-1,
|
| 602 |
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 4, 1.0)
|
| 603 |
ret,label,center=cv2.kmeans(res,l,None,criteria,4,cv2.KMEANS_PP_CENTERS)
|
| 604 |
center = np.uint8(center)
|
| 605 |
res = center[label.flatten()]
|
| 606 |
bg = res.reshape((bg.shape))
|
| 607 |
|
| 608 |
-
bg[
|
| 609 |
-
bg[
|
|
|
|
| 610 |
|
| 611 |
params["fnum"] = frame_selected
|
| 612 |
params["l"] = l
|
| 613 |
|
| 614 |
-
d["layers"][0] = cv2.cvtColor(bg, cv2.
|
| 615 |
edge = bg.copy()
|
| 616 |
else:
|
| 617 |
bg = edge.copy()
|
|
|
|
| 576 |
else:
|
| 577 |
gradient = cv2.imread('./gradient_small.png').astype(np.uint8)
|
| 578 |
|
| 579 |
+
bg = cv2.cvtColor(d["background"], cv2.COLOR_RGBA2GRAY)
|
| 580 |
+
#bg = cv2.cvtColor(bg, cv2.COLOR_RGB2HSV)
|
| 581 |
+
#bg[:,:,0] = clrs[:,:,0]
|
| 582 |
+
#bg = cv2.cvtColor(bg, cv2.COLOR_HSV2RGB)
|
| 583 |
+
bd = cv2.convertScaleAbs(cv2.Laplacian(bg, cv2.CV_64F, 5)).astype(np.uint8)
|
| 584 |
|
| 585 |
diff = np.abs(cv2.cvtColor(d["background"], cv2.COLOR_RGBA2GRAY).astype(np.int16)-cv2.cvtColor(gradient, cv2.COLOR_RGBA2GRAY).astype(np.int16)).astype(np.uint8)
|
| 586 |
mask = cv2.inRange(diff, 0, t)
|
|
|
|
| 599 |
# bg[(bg >= i*255/l) & (bg < (i+1)*255/l)] = i*255/(l-1)
|
| 600 |
#bg = cv2.convertScaleAbs(palette[bg]).astype(np.uint8) # Converting image back to uint
|
| 601 |
|
| 602 |
+
res = np.float32(bg.reshape((-1,1)))
|
| 603 |
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 4, 1.0)
|
| 604 |
ret,label,center=cv2.kmeans(res,l,None,criteria,4,cv2.KMEANS_PP_CENTERS)
|
| 605 |
center = np.uint8(center)
|
| 606 |
res = center[label.flatten()]
|
| 607 |
bg = res.reshape((bg.shape))
|
| 608 |
|
| 609 |
+
bg[bd>b] = 0
|
| 610 |
+
bg[mask>0] = 0
|
| 611 |
+
bg[bg==255] = 0
|
| 612 |
|
| 613 |
params["fnum"] = frame_selected
|
| 614 |
params["l"] = l
|
| 615 |
|
| 616 |
+
d["layers"][0] = cv2.cvtColor(bg, cv2.COLOR_GRAY2RGBA)
|
| 617 |
edge = bg.copy()
|
| 618 |
else:
|
| 619 |
bg = edge.copy()
|