Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

backgroundsubtractormog with python

Hello, I want to use backgroundsubtractormog with python so my code is this

import cv2 import numpy as np

winname = "GRS"

bgs_mog = cv2.BackgroundSubtractorMOG(500, 6, 0.9, 1)

capture = cv2.VideoCapture(0)

frame = capture.read()[1]

if __name__ == "__main__": while frame != None: #fgmask = bgs_mog.apply(frame) cv2.imshow(winname, frame) c = cv2.waitKey(1) if c == 27: cv2.destroyWindow(winname) break frame = capture.read()[1] cv2.destroyAllWindows()

The output I am having is some mask of binary images. But I want only coloured image of moving objects. I do not know how to implement this mask to get the coloured image of moving objects only. I have referred the opencv2refman doc about this function but I am no getting clear about how to determine the parameters for mog constructor. Can somebody explain how to do this, Plz. Thanks

click to hide/show revision 2
No.2 Revision

updated 2013-07-28 07:00:25 -0600

berak gravatar image

backgroundsubtractormog with python

Hello, I want to use backgroundsubtractormog with python so my code is this

import cv2
import numpy as np

np winname = "GRS"

"GRS" bgs_mog = cv2.BackgroundSubtractorMOG(500, 6, 0.9, 1)

1) capture = cv2.VideoCapture(0)

cv2.VideoCapture(0) frame = capture.read()[1]

capture.read()[1] if __name__ == "__main__": while frame != None: #fgmask = bgs_mog.apply(frame) cv2.imshow(winname, frame) c = cv2.waitKey(1) if c == 27: cv2.destroyWindow(winname) break frame = capture.read()[1] cv2.destroyAllWindows()

cv2.destroyAllWindows()

The output I am having is some mask of binary images. But I want only coloured image of moving objects. I do not know how to implement this mask to get the coloured image of moving objects only. I have referred the opencv2refman doc about this function but I am no getting clear about how to determine the parameters for mog constructor. Can somebody explain how to do this, Plz. Thanks