i have been going through opencv mog and gmg background subtraction, i have installed opencv 3.3.0 from
https://github.com/Itseez/opencv_contrib
and also opencv from the same version, but still i couldn't find MOG not working, where as mog 2 is working,
import numpy as np
import cv2
cap = cv2.VideoCapture(0)
fgbg = cv2.BackgroundSubtractorMOG()
while(1):
ret, frame = cap.read()
fgmask = fgbg.apply(frame)
cv2.imshow('frame',fgmask)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()
i get the following error message
Traceback (most recent call last):
File "back.py", line 6, in <module>
fgbg = cv2.BackgroundSubtractorMOG()
AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG'
The problem is that you are not calling the correct function to create the background substractor...
You can follow the tutorial (it is for version 3.0, but I couldn't find it for 3.3, however it is the same) to have a more in depth explanation of how to use it.
As you can see in the link I provided, you have to call
instead of
Then the rest is the same.