freealise commited on
Commit
1464def
1 Parent(s): 0b4b4f5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -1
app.py CHANGED
@@ -567,7 +567,7 @@ def apply_mask(d,b):
567
  frame[:, :, 3] = mask * 255
568
  cv2.imwrite(frames[frame_selected], frame)
569
 
570
- mask = cv2.imread(masks[frame_selected], cv2.IMREAD_GRAYSCALE).astype(np.uint8) + 128
571
  mask[mask==128] = 0
572
  d["layers"][0] = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGBA)
573
 
@@ -613,6 +613,17 @@ def draw_mask(l, t, b, v, d, evt: gr.EventData):
613
  sel = sel[1:sel.shape[0]-1, 1:sel.shape[1]-1]
614
 
615
  d["layers"][0][sel==0] = (0,0,0,0)
 
 
 
 
 
 
 
 
 
 
 
616
 
617
  return gr.ImageEditor(value=d)
618
 
 
567
  frame[:, :, 3] = mask * 255
568
  cv2.imwrite(frames[frame_selected], frame)
569
 
570
+ mask = cv2.imread(masks[frame_selected], cv2.IMREAD_GRAYSCALE).astype(np.uint8)
571
  mask[mask==128] = 0
572
  d["layers"][0] = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGBA)
573
 
 
613
  sel = sel[1:sel.shape[0]-1, 1:sel.shape[1]-1]
614
 
615
  d["layers"][0][sel==0] = (0,0,0,0)
616
+
617
+
618
+ mask = cv2.cvtColor(d["layers"][0], cv2.COLOR_RGBA2GRAY) - 128
619
+ mask[mask<0] = 0
620
+ print(mask[mask>0])
621
+ mask, bgdModel, fgdModel = cv2.grabCut(cv2.cvtColor(d["background"], cv2.COLOR_RGBA2RGB), mask, None,None,None,15, cv2.GC_INIT_WITH_MASK)
622
+ mask = np.where((mask==2)|(mask==0),1,0).astype('uint8')
623
+
624
+ frame = cv2.imread(frames[frame_selected], cv2.IMREAD_UNCHANGED).astype(np.uint8)
625
+ frame[:, :, 3] = mask * 255
626
+ cv2.imwrite(frames[frame_selected], frame)
627
 
628
  return gr.ImageEditor(value=d)
629