Ask Your Question
1

module 'cv2' has no attribute 'createBackgroundSubtractorMOG'

asked 2016-05-18 05:33:25 -0600

kunal017 gravatar image

I am using Python 3.5.1 and opencv 3.1.0. I am trying to use cv2.createBackgroundSubtractorMOG() method in Python.

I get the following error when running the code : fgbg = cv2.createBackgroundSubtractorMOG() AttributeError: module 'cv2' has no attribute 'createBackgroundSubtractorMOG2'

Code I am using is from http://docs.opencv.org/3.0-beta/doc/p...

I tried searching online but not able to solve problem. Please help me out, Thanks in advance.

edit retag flag offensive close merge delete

3 answers

Sort by ยป oldest newest most voted
2

answered 2016-05-18 05:51:09 -0600

berak gravatar image

BackgroundSubtractorMOG was moved to https://github.com/Itseez/opencv_cont... (see README there for instructions on adding it)

then, it is in the bgsegm submodule, so call it like this:

cv2.bgsegm.createBackgroundSubtractorMOG()

also, rather use http://docs.opencv.org/master/ , the 3.0-beta docs are outdated.

edit flag offensive delete link more

Comments

Thanks, It worked well.

kunal017 gravatar imagekunal017 ( 2016-05-18 06:00:19 -0600 )edit

Thanks, worked for me.

Blane gravatar imageBlane ( 2017-10-18 12:18:44 -0600 )edit

open and correct help me. Thanks!

https://drive.google.com/drive/folder...

hung gravatar imagehung ( 2019-01-28 07:38:32 -0600 )edit

Now i am using open CV version 4.0.0 and unfortunately none of these commands are working can anybody help me?

hari51 gravatar imagehari51 ( 2019-03-08 05:37:18 -0600 )edit
-1

answered 2017-02-08 01:04:21 -0600

Anees gravatar image

Use cv2.BackgroundSubtractorMOG(). because cv2.createBackgroundSubtractorMOG2 is an old one and it is replaced by cv2.BackgroundSubtractorMOG() in opencv latest versions.

edit flag offensive delete link more

Comments

Now i am using open CV version 4.0.0 and unfortunately none of these commands are working can anybody help me?

hari51 gravatar imagehari51 ( 2019-03-08 05:37:41 -0600 )edit
0

answered 2019-08-27 01:48:39 -0600

It depends on the version of python you are using. The opencv library has createBackgroundSubtractorMOG and createBackgroundSubtractorMOG2 for different versions of python. After python3, the createBackgroundSubtractorMOG is not available. So you have to use createBackgroundSubtractorMOG2.

So use cv2.createBackgroundSubtractorMOG2() if you are using Python3 else cv2.createBackgroundSubtractorMOG() if Python2

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2016-05-18 05:33:25 -0600

Seen: 32,251 times

Last updated: May 18 '16