I also tackled the problem of moving-window brightness calibration in a related (but more constrained) problem --- tracking water fleas moving in a tank of water where an overhead light might periodically turn on and wash out the picture.
I essentially subtracted the current frame from the max across a moving window.
I essentially subtracted the current frame from the max across a moving window.
I'd be interested to chat about it if you like, my email is in my profile. The code is at https://github.com/nuchi/multi_object_tracking