Reputation: 23
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'
Upvotes: 2
Views: 1231
Reputation: 579
fgbg = cv.createBackgroundSubtractorMOG() didn't work for me too but there is another improved version of background subtraction which works similar fgbg = cv2.createBackgroundSubtractorMOG2()
Upvotes: 0
Reputation: 11420
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
fgbg = cv2.createBackgroundSubtractorMOG()
instead of
fgbg = cv2.BackgroundSubtractorMOG()
Then the rest is the same.
Upvotes: 0