import cv2
import numpy as np
cap = cv2.VideoCapture(0)
bgs = cv2.bgsegm.createBackgroundSubtractorMOG()
while True:
ret, frame = cap.read()
if ret:
fgmask = bgs.apply(frame)
cv2.imshow('video', fgmask)
key = cv2.waitKey(1)
# ESC键
if key == 27:
break
cap.release()
cv2.destroyAllWindows()