Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to give createBackgroundSubtractorMOG2 selective history images.

I am currently running this to acquire images:

 fgbg = cv2.createBackgroundSubtractorMOG2(detectShadows=False)
 for frame in cam.camera.capture_continuous(raw, format="rgb", use_video_port=True):
    img = frame.array
    fgmask = fgbg.apply(img)

How can I go about choosing which images to save in the history. I want to build a function where I can select which images are background. For example initially the first 50 input images will be used as history for the subtractor and after that all masks that have under a certain threshold of difference will be used as history too. I basically do not want the new foreground images to be used as history is that possible?

How to give createBackgroundSubtractorMOG2 selective history images.

I am currently running this to acquire images:

 fgbg = cv2.createBackgroundSubtractorMOG2(detectShadows=False)
 for frame in cam.camera.capture_continuous(raw, format="rgb", use_video_port=True):
    img = frame.array
    fgmask = fgbg.apply(img)

How can I go about choosing which images to save in the history. I want to build a function where I can select which images are background. For example initially the first 50 input images will be used as history for the subtractor and after that all masks that have under a certain threshold of difference will be used as history too. I basically do not want the new foreground images to be used as history is that possible?

I have written this code:

fgmask = fgbg.apply(img, bg_learning_rate)

# check if should learn from content
perc_black = np.count_nonzero(fgmask) / len(fgmask)
if perc_black > MOVEMENT_THRESH:
    # something is happening in image
    bg_learning_rate = 0
else:
    bg_learning_rate = -1

but this teaches the system to not use the next image in the model which is not that useful although highly probable that it will still feature a large object.

I am doing this to extract people from a static background.