Background subtraction is a major preprocessing steps in many vision based applications. For example, consider the cases like visitor counter where a static camera takes the number of visitors entering or leaving the room, or a traffic camera extracting information about the vehicles etc. In all these cases, first you need to extract the person or vehicles alone. Technically, you need to extract the moving foreground from static background
The basic methods have several limitations:
- They are based on the history of the single pixel;
- They don't use spatial information;
- The thresholds and parameters are difficult to to choose.
The methods applied in this simple example are:
- Previous frame: the background estimated at step 'n' is the image analyzed in step 'n-1';
- Moving average: the background is estimated as the average of the last 'k' frames ('k' determines how much
quickly the background adapts to changes);
- Exponential moving average: the alpha parameter determines the speed of background update.
sudo apt-get install libopencv-dev python3-opencv
bash install-opencv.sh