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

4

9

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

Kunkle answered 7/2, 2014 at 11:30 Comment(2)
That tutorial is meant for OpenCV 3.x. So compile opencv from github master branch..Collect
Thanks for the info I will use Open CV3 now!Kunkle
H
7

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).

Hadst answered 7/2, 2014 at 11:57 Comment(2)
Actually, my 3.0.0-dev version (today's git master) does contain the createBackgroundSubtractorMOG and createBackgroundSubtractorMOG2, but not createBackgroundSubtractorGMG (on Python3). Still looking for that one.Salpingotomy
Just in case someone is looking for this: I dove a bit deeper into why createBackgroundSubtractorGMG is missing, and posted a new question on it: #29430363Salpingotomy
G
12

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()

Goby answered 28/11, 2015 at 20:16 Comment(5)
Pokerfaced Where they mention it? I couldn't see it in the docs, did I miss something? Great, another 20 minutes of recompiling.Petitionary
I have 3.3 AttributeError: 'module' object has no attribute 'bgsegm'Sapper
@Maximilian Are you sure your version is compiled with opencv_contrib?Goby
No! That is why! ThanksSapper
This worked for me. Using 3.3.1 dev python-opencvHorse
F
9
cv2.bgsegm.createBackgroundSubtractorGMG()
cv2.createBackgroundSubtractorMOG2()
cv2.bgsegm.createBackgroundSubtractorMOG(),

**this worked for me **

Five answered 10/9, 2018 at 7:48 Comment(0)
H
7

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).

Hadst answered 7/2, 2014 at 11:57 Comment(2)
Actually, my 3.0.0-dev version (today's git master) does contain the createBackgroundSubtractorMOG and createBackgroundSubtractorMOG2, but not createBackgroundSubtractorGMG (on Python3). Still looking for that one.Salpingotomy
Just in case someone is looking for this: I dove a bit deeper into why createBackgroundSubtractorGMG is missing, and posted a new question on it: #29430363Salpingotomy
W
2

bgsegm was in contrib module of opencv, but after the update I am not sure.

But still, if you have not built contrib module:

pip install opencv-contrib-python

Make sure no console is running that has imported cv2 while you execute your installing process. Run the cmd as Administration

It worked for me.

Week answered 13/2, 2019 at 4:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.