-
-
Save daniellopez0708/46ebcc67de00cf140d92ecf876790a78 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def train_bg_subtractor(inst, cap, num=500): | |
''' | |
BG substractor need process some amount of frames to start giving result | |
''' | |
print ('Training BG Subtractor...') | |
i = 0 | |
for frame in cap: | |
inst.apply(frame, None, 0.001) | |
i += 1 | |
if i >= num: | |
return cap | |
VIDEO_SOURCE = "road.mp4" | |
bg_subtractor = cv2.createBackgroundSubtractorMOG2( | |
history=500, detectShadows=True) | |
# Set up image source | |
cap = skvideo.io.vreader(VIDEO_SOURCE) | |
# skipping 500 frames to train bg subtractor | |
train_bg_subtractor(bg_subtractor, cap, num=500) | |
frame = next(cap) | |
fg_mask = bg_subtractor.apply(frame, None, 0.001) | |
plt.figure(figsize=(12,12)) | |
plt.imshow(fg_mask) | |
plt.show() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment