Spaces:
Starting
Starting
Update app.py
Browse files
app.py
CHANGED
@@ -425,16 +425,15 @@ def draw_mask(l, c, k, v, d, evt: gr.EventData):
|
|
425 |
#bg_ = cv2.copyMakeBorder(bg, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
|
426 |
#bg = np.zeros_like(bg)
|
427 |
|
428 |
-
|
429 |
-
|
430 |
-
) # 255 << 8 tells to fill with the value 255)
|
431 |
grad_x = cv2.convertScaleAbs(cv2.Sobel(mask, ddepth, 1, 0, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT))
|
432 |
grad_y = cv2.convertScaleAbs(cv2.Sobel(mask, ddepth, 0, 1, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT))
|
433 |
|
434 |
grad = cv2.addWeighted(grad_x, 0.5, grad_y, 0.5, 0)
|
435 |
mask[cv2.inRange(grad, 1, 255)>0] = 1
|
436 |
|
437 |
-
d["layers"][1] =
|
438 |
d["background"][mask>0] = (0,0,0,255)
|
439 |
|
440 |
return gr.ImageEditor(value=d)
|
|
|
425 |
#bg_ = cv2.copyMakeBorder(bg, 1, 1, 1, 1, cv2.BORDER_DEFAULT)
|
426 |
#bg = np.zeros_like(bg)
|
427 |
|
428 |
+
mask = cv2.floodFill(bg, None, (x, y), 1, 0, 0)[2] #, (4 | cv2.FLOODFILL_FIXED_RANGE | cv2.FLOODFILL_MASK_ONLY | 255 << 8)
|
429 |
+
# 255 << 8 tells to fill with the value 255)
|
|
|
430 |
grad_x = cv2.convertScaleAbs(cv2.Sobel(mask, ddepth, 1, 0, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT))
|
431 |
grad_y = cv2.convertScaleAbs(cv2.Sobel(mask, ddepth, 0, 1, ksize=3, scale=scale, delta=delta, borderType=cv2.BORDER_DEFAULT))
|
432 |
|
433 |
grad = cv2.addWeighted(grad_x, 0.5, grad_y, 0.5, 0)
|
434 |
mask[cv2.inRange(grad, 1, 255)>0] = 1
|
435 |
|
436 |
+
d["layers"][1][mask>0] = (0,0,0,255)
|
437 |
d["background"][mask>0] = (0,0,0,255)
|
438 |
|
439 |
return gr.ImageEditor(value=d)
|