How to subtract the background in a still image? IF the issue is with videos then we can use cv2.createBackgroundSubtractorMOG(). I tried to manipulate the function, but I got AttributeError This is what i have tried: img = cv2.imread('lena.png') fgbg = cv2.createBackgroundSubtractorMOG2() fgmask = fgbg.apply(img) cv2.imwrite('{0:d}.jpg'.format(i),fgmask) But I got this error: AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG2' Any suggestion are welcome! Continue reading...