Search code examples
pythonopencvcondabackground-subtraction

Python does not find bgsegm from cv2


I am trying to test some background subtraction methods (following the tutorial) but Python fails to find them.

Using Windows and Anaconda. I made sure to upgrade opencv through conda and ran the

pip install opencv-contrib-python

command as recommended in another related question.

Still, I get this:

(tracx) C:\Users\USER>python
Python 3.5.4 |Anaconda, Inc.| (default, Nov  8 2017, 14:34:30) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> fgbg = cv2.createBackgroundSubtractorMOG()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'cv2.cv2' has no attribute 'createBackgroundSubtractorMOG'
>>> quit()

Solution

  • You must be looking for f = cv2.bgsegm.createBackgroundSubtractorMOG().

    The function currently resides within the bgseg (background segmentation) module.