Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python-opencv AttributeError: 'module' object has no attribute 'createBackgroundSubtractorGMG'

Tags:

python

opencv

I am trying to follow the tutorial given in: https://opencv-python-tutroals.readthedocs.org/en/latest/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.html

While trying the third example (BackgroundSubtractorGMG) I get this error:

AttributeError: 'module' object has no attribute 'createBackgroundSubtractorGMG'

I got the same error for the earlier examples. But I followed the explanation given in this post. some how, the same trick did not work here.

If there is some one who has managed to solve it, please help me out.

Using Python 2.7.3 & opencv 2.4.6.1 on Ubuntu 12.04

like image 995
okkhoy Avatar asked Feb 07 '14 11:02

okkhoy


3 Answers

oh dear, that's another one of those stories ...

with 2.4.6, you only can use BackgroundSubtractorMOG from python. (full stop)

as of 2.4.8, it seems, the BackgroundSubtractorMOG2 problem got fixed, but the BackgroundSubtractorGMG is still missing.

with both versions, you use a plain constructor to create one.

in 3.0 (master), they changed the syntax, you now have to call 'createBackgroundSubtractorGMG', 'createBackgroundSubtractorMOG2' and such (that's what your tutorial might be refering to). but now you can use all 3 versions at least.

so in any way, if you want to use BackgroundSubtractorMOG2 , you'll have to update to 2.4.8, if you need BackgroundSubtractorGMG, you'll need 3.0 (which is 'bleeding edge' in a way, but the new interface has the far better control over the params needed, imho).

like image 137
berak Avatar answered Nov 07 '22 22:11

berak


cv2.bgsegm.createBackgroundSubtractorGMG()
cv2.createBackgroundSubtractorMOG2()
cv2.bgsegm.createBackgroundSubtractorMOG(),

**this worked for me **

like image 35
Sikander SD Avatar answered Nov 07 '22 20:11

Sikander SD


In OpenCV 3.0.0-dev, you have to compile with the contrib repos and then it's in the bgsegm sub-module. I.e. just call cv2.bgsegm.createBackgroundSubtractorGMG()

like image 12
Sven Zwei Avatar answered Nov 07 '22 21:11

Sven Zwei