Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -341,18 +341,15 @@ def draw_mask(v, d, evt: gr.EventData):
|
|
341 |
w = int(vv[2])
|
342 |
h = int(vv[3])
|
343 |
|
344 |
-
|
345 |
-
rgb = cv2.cvtColor(d["background"], cv2.COLOR_RGBA2RGB)
|
346 |
-
d["background"] = cv2.applyColorMap(cv2.cvtColor(d["background"], cv2.COLOR_RGBA2GRAY), cv2.COLORMAP_HSV)
|
347 |
-
mask = np.zeros(rgb.shape[:2], np.uint8)
|
348 |
bgdModel = np.zeros((1,65), np.float64)
|
349 |
fgdModel = np.zeros((1,65), np.float64)
|
350 |
rect = (x, y, w, h)
|
351 |
-
mask = cv2.grabCut(
|
352 |
print(mask)
|
353 |
mask0 = mask[0]
|
354 |
newmask = np.where((mask0==2)|(mask0==0),1,0).astype('uint8')
|
355 |
-
d["composite"] =
|
356 |
|
357 |
return gr.ImageEditor(value=d)
|
358 |
|
|
|
341 |
w = int(vv[2])
|
342 |
h = int(vv[3])
|
343 |
|
344 |
+
mask = np.zeros(d["background"].shape[:2], np.uint8)
|
|
|
|
|
|
|
345 |
bgdModel = np.zeros((1,65), np.float64)
|
346 |
fgdModel = np.zeros((1,65), np.float64)
|
347 |
rect = (x, y, w, h)
|
348 |
+
mask = cv2.grabCut(d["background"], mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
|
349 |
print(mask)
|
350 |
mask0 = mask[0]
|
351 |
newmask = np.where((mask0==2)|(mask0==0),1,0).astype('uint8')
|
352 |
+
d["composite"] = rgb*newmask[:,:,np.newaxis]
|
353 |
|
354 |
return gr.ImageEditor(value=d)
|
355 |
|