1

I am using cv2 version 4.0.0 and python version 3.7.2.

I am trying to subtract Background using this method cv2.createBackgroundSubtractorMOG2() and its working well.

But when I use cv2.createBackgroundSubtractorMOG() its not working its showing me

AttributeError: module 'cv2.cv2' has no attribute 'createBackgroundSubtractorMOG '.

I also tried cv2.BackgroundSubtractorMOG() but i got same error

AttributeError: module 'cv2.cv2' has no attribute 'BackgroundSubtractorMOG'.

and another subtraction method cv2.createBackgroundSubtractorGMG() also not working.

I also refer other stackoverflow answers but I didn't get solution.

patelnisheet
  • 124
  • 1
  • 3
  • 12

2 Answers2

3

MOG2 containts in main opencv repository. MOG and GMG are from opencv_contrib: https://github.com/opencv/opencv_contrib/tree/master/modules/bgsegm

Nuzhny
  • 1,869
  • 1
  • 7
  • 13
2

there are two subtraction packages in opencv. BackgroundSubtractorMOG() it's at cv2.bgsegm.BackgroundSubtractorMOG(),to use you must install opencv-contrib-python

Steffen Moritz
  • 7,277
  • 11
  • 36
  • 55