Update app.py
Browse files
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 |
-
|
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,
|
210 |
mask = np.where((mask==2)|(mask==0),0,1).astype('uint8')
|
211 |
-
|
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
|