Ask Your Question

Cannot find BackgroundSubtractorMOG() and BackgroundSubtractorGMG() in OpenCV 3.0 with Python 2.7

asked 2015-11-26 08:29:25 -0500

isaacsales gravatar image

I was trying to make some codes following the tutorial, but when I use these functions as suggested in the doc it appears this error: AttributeError: 'module' object has no attribute 'createBackgroundSubtractorMOG'.

What should I do? Thanks!

edit retag flag offensive close merge delete


BackgroundSubtractorMOG() and BackgroundSubtractorGMG() have been moved to the bgsegm module of the contrib repository. As far as I know, no Python wrappers are available for such repository, so you just can't use those classes.

Please, point out what tutorial you've followed, so we can fix it/add a note about this issue

LorenaGdL gravatar imageLorenaGdL ( 2015-11-26 09:23:57 -0500 )edit

Thanks Lorena. It was very helpful. I've followed this tutorial here: https://opencv-python-tutroals.readth...

isaacsales gravatar imageisaacsales ( 2015-11-26 09:33:10 -0500 )edit

I've checked and the official Python tutorial in the OpenCV3.0 docs says nothing about this. I'll add a note if I find some spare time

LorenaGdL gravatar imageLorenaGdL ( 2015-11-26 09:42:18 -0500 )edit

well, once one builds the opencv_contrib repo, they are avaliable from python:

>>> help(cv2.bgsegm)
Help on module cv2.bgsegm in cv2:



        createBackgroundSubtractorGMG([, initializationFrames[, decisionThreshol
d]]) -> retval

        createBackgroundSubtractorMOG([, history[, nmixtures[, backgroundRatio[,
 noiseSigma]]]]) -> retval
berak gravatar imageberak ( 2015-11-26 09:56:15 -0500 )edit

My bad then, though I saw this issue and thought it was unresolved

LorenaGdL gravatar imageLorenaGdL ( 2015-11-26 10:10:03 -0500 )edit

2 answers

Sort by ยป oldest newest most voted

answered 2015-11-27 04:53:55 -0500

Known issue: Still on TODO list to fix :D

edit flag offensive delete link more

answered 2017-08-03 12:32:43 -0500

I had the same problem with the same set-up. If you have compiled with --with-contrib flag, you should be fine once you use the bgsegm namespace.


fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()

this worked for me.

edit flag offensive delete link more


@manielec, if you would have taken the time to click the link, then you would know this was already given as a solution...

StevenPuttemans gravatar imageStevenPuttemans ( 2017-08-04 06:07:52 -0500 )edit

Question Tools

1 follower


Asked: 2015-11-26 08:29:25 -0500

Seen: 6,158 times

Last updated: Aug 03 '17