Ask Your Question
0

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

asked Nov 26 '15

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!

Preview: (hide)

Comments

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 (Nov 26 '15)edit

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

isaacsales gravatar imageisaacsales (Nov 26 '15)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 (Nov 26 '15)edit

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

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

NAME
    cv2.bgsegm

FILE
    (built-in)

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

    createBackgroundSubtractorMOG(...)
        createBackgroundSubtractorMOG([, history[, nmixtures[, backgroundRatio[,
 noiseSigma]]]]) -> retval
berak gravatar imageberak (Nov 26 '15)edit

My bad then, though I saw this issue and thought it was unresolved https://github.com/Itseez/opencv/issu...

LorenaGdL gravatar imageLorenaGdL (Nov 26 '15)edit

2 answers

Sort by » oldest newest most voted
0

answered Nov 27 '15

Known issue: https://github.com/Itseez/opencv/issu.... Still on TODO list to fix :D

Preview: (hide)
-1

answered Aug 3 '17

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.

e.g.

fgbg = cv2.bgsegm.createBackgroundSubtractorMOG()

this worked for me.

Preview: (hide)

Comments

@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 (Aug 4 '17)edit

Question Tools

1 follower

Stats

Asked: Nov 26 '15

Seen: 6,669 times

Last updated: Aug 03 '17