Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -349,13 +349,13 @@ def draw_mask(v, d, evt: gr.EventData):
|
|
349 |
fgdModel = np.zeros((1,65), np.float64)
|
350 |
rect = (x, y, w, h)
|
351 |
mask = cv2.grabCut(rgb, mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
|
352 |
-
|
353 |
-
newmask = np.where((
|
354 |
-
print(
|
355 |
print(newmask)
|
356 |
img = cv2.cvtColor(rgb, cv2.COLOR_RGB2RGBA)*newmask[:,:,np.newaxis]
|
357 |
|
358 |
-
d["
|
359 |
d["composite"] = img
|
360 |
|
361 |
return gr.ImageEditor(value=d)
|
|
|
349 |
fgdModel = np.zeros((1,65), np.float64)
|
350 |
rect = (x, y, w, h)
|
351 |
mask = cv2.grabCut(rgb, mask, rect, bgdModel, fgdModel, 5, cv2.GC_INIT_WITH_RECT)
|
352 |
+
mask0 = cv2.cvtColor(mask[0], cv2.COLOR_RGB2RGBA)
|
353 |
+
newmask = np.where((mask0==2)|(mask0==0),1,0).astype('uint8')
|
354 |
+
print(mask0)
|
355 |
print(newmask)
|
356 |
img = cv2.cvtColor(rgb, cv2.COLOR_RGB2RGBA)*newmask[:,:,np.newaxis]
|
357 |
|
358 |
+
d["layers"][0]= mask0
|
359 |
d["composite"] = img
|
360 |
|
361 |
return gr.ImageEditor(value=d)
|