freealise commited on
Commit
b33f76e
·
verified ·
1 Parent(s): 8ab7931

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -11
app.py CHANGED
@@ -87,18 +87,10 @@ def get_frames(video_in, step, name, n):
87
 
88
 
89
  def create_video(frames, fps, type):
90
-
91
- backSub = cv2.createBackgroundSubtractorMOG2()
92
- #backSub = cv2.createBackgroundSubtractorKNN()
93
-
94
  print("building video result")
95
  imgs = []
96
  for j, img in enumerate(frames):
97
- frame = cv2.cvtColor(cv2.imread(img).astype(np.uint8), cv2.COLOR_BGR2RGB)
98
- fgMask = backSub.apply(frame)
99
- frame[fgMask==255] = (255,255,255)
100
- frame[fgMask==0] = (0,0,0)
101
- imgs.append(frame)
102
 
103
  mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
104
  return type + "_result.mp4"
@@ -206,9 +198,9 @@ def remove_bg(fl, count, mh, ms, md, lm):
206
  #fr[fr_fg==0] = (255,255,255)
207
 
208
  fr_fg[fr_fg>0] = 3 #probable fg
209
- mask, bgdModel, fgdModel = cv2.grabCut(fr, fr_fg, None,None,None,31, cv2.GC_INIT_WITH_MASK)
210
  mask = np.where((mask==2)|(mask==0),0,1).astype('uint8')
211
- #fr[mask==0] = (255,255,255)
212
 
213
  cv2.imwrite(fl, fr)
214
  return fl
 
87
 
88
 
89
  def create_video(frames, fps, type):
 
 
 
 
90
  print("building video result")
91
  imgs = []
92
  for j, img in enumerate(frames):
93
+ imgs.append(cv2.cvtColor(cv2.imread(img).astype(np.uint8), cv2.COLOR_BGR2RGB))
 
 
 
 
94
 
95
  mediapy.write_video(type + "_result.mp4", imgs, fps=fps)
96
  return type + "_result.mp4"
 
198
  #fr[fr_fg==0] = (255,255,255)
199
 
200
  fr_fg[fr_fg>0] = 3 #probable fg
201
+ mask, bgdModel, fgdModel = cv2.grabCut(fr, fr_fg, None,None,None,15, cv2.GC_INIT_WITH_MASK)
202
  mask = np.where((mask==2)|(mask==0),0,1).astype('uint8')
203
+ fr[mask==0] = (255,255,255)
204
 
205
  cv2.imwrite(fl, fr)
206
  return fl