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.
no, not possible,bad idea in the 1st place.
(you, as a human, might be able to tell "good" from "bad" images. -- your machine can't)
Can you expand a bit? If I leave it to train on 500 images first of all. After that I set a blackness threshold and if it exceeds it there must be a new dominating object in which is not a background therefore why would I train it to think that it is a background?
What if the object was in the image in the first 500 frames? Then you would be rejecting the background, and keeping the object.
I can tell you for a fact it won't be.
Then you should turn the learning rate to 0, apply, check, then if it should be included, turn the learning rate to -1 and apply again. Messy, but it should do what you want.
See my code above!