import numpy as np import cv2 cap = cv2.VideoCapture(\'vtest.avi\') fgbg = cv2.bgsegm.createBackgroundSubtractorMOG() while(1): ret, frame = cap.read() fgmask =
Installing contrib dependencies will fix your problem:
pip install opencv-contrib-python
Alternatively, you can use the newer createBackgroundSubtractorMOG2(), which is directly available in cv2:
createBackgroundSubtractorMOG2()
fgbg = cv2.createBackgroundSubtractorMOG2()