I have a background image of a plain surface. My goals is to track objects that are positioned/moved over the surface.
I'm using MOG2 to find foreground objects with a learning rate of 0, so the background is not updated (otherwise a static object would be incorporated in the background).
The result is fine, but I have a huge problem with light: if the lighting changing after background acquiring, various artifacts are detected as foregorund objects.
How can I improve the robustness against lighting?
Update
I'm experimenting with a solution that works quite well, but it need some fixes.
I'm using MOG2 in this manner:
- Acquiring and learning background using the first frames (BGK)
- Apply MOG2 to current frame with learning rate of 0 (no update) and get foreground mask (FG_MASK)
- For the next frames I'm using FG_MASK to mask BGK and I'm using the result to Apply to MOG2 with some learning rate (this update the background).
- After that I'm updating BGK taking it from MOG2 algorythm.
In this way, objects are masked out of the background, and the background still updating. This can guarantee a good robustness against light changes.
There is some drawback, for example when the light is changing, the object mask ("mask blob") keep with the previous brightness, and if the difference is too high can be detected as new object.
In the above image you can see that the current frame is brighter and the mask for the static object is darker.
My idea is try to adapt the "mask blob" changing it's brightness following the light changing. How can i get this with OpenCV?
Fix for previous drawbacks
Using inpaint function instaead to simply mask the BGK (step 3) i can keep the "mask blobs" sync with background brightness changes. This fix has drawback too, it's not very perfomance.
Update 2
I think this is an interesting topic so I keep it updated. The inpaint function is very slow, so I'm trying another way. Using the Hsv color space allows you to manage the brightness channel, I can reduce the impact of brightness in this way:
- obtain the V channel with the Split function
- calculate the mean value of channel V
- apply a threshold truncate to the V channel using the mean value
- Rebuild frame using new V channel