Ask Your Question

help regarding MOG back ground subtraction using opencv

asked 2017-07-10 06:18:14 -0500

updated 2017-07-10 06:46:29 -0500

berak gravatar image

hi, i have been working ono mog background subtraction with the following program,if i use mog2 it is working but working on mog and gmg doesnt seem to work,i am using opencv3.2.0

the program is

import numpy as np import cv2

cap = cv2.VideoCapture(0)

fgbg = cv2.BackgroundSubtractorMOG()

while(1): ret, frame =

fgmask = fgbg.apply(frame)

cv2.imshow('frame',fgmask) if cv2.waitKey(1) & 0xFF == ord('q'): break

cap.release() cv2.destroyAllWindows()

this is the error coming

File "", line 6, in <module> fgbg = cv2.BackgroundSubtractorMOG2() AttributeError: 'module' object has no attribute 'BackgroundSubtractorMOG2'

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2017-07-10 06:46:02 -0500

berak gravatar image

updated 2017-07-11 23:58:15 -0500

MOG and GMG were moved to opencv_contrib with opencv3, and you have to call a "create" function, not a constructor, like:

 fgbg = cv2.createBackgroundSubtractorMOG2()

also have a look at:

 >>> help(cv2.createBackgroundSubtractorMOG2())
edit flag offensive delete link more


hey i tried the mog2 subtractor is working,but MOG and GMG are not working,i have also installed opencv_contirb,but i still get errors

arvvind gravatar imagearvvind ( 2017-07-10 23:33:11 -0500 )edit


berak gravatar imageberak ( 2017-07-11 00:47:38 -0500 )edit

sir, i tried this to,yet couldnt get the result,,,can you kindly mention me opencv version and link to install opencv and opencv contrib again

arvvind gravatar imagearvvind ( 2017-07-11 23:50:18 -0500 )edit

apologies, i got it all wrong, initially, it's createXXXX(), not XXXX_create()

berak gravatar imageberak ( 2017-07-11 23:59:24 -0500 )edit

berak ,i tried either mais there any way to check whether the extra modules has been installed,when i ran installation it showed sucees oly..,

arvvind gravatar imagearvvind ( 2017-07-13 00:06:58 -0500 )edit

^^ sorry i have no idea, what you are talking about.

berak gravatar imageberak ( 2017-07-13 02:40:08 -0500 )edit
Login/Signup to Answer

Question Tools



Asked: 2017-07-10 06:18:14 -0500

Seen: 169 times

Last updated: Jul 11 '17