As the name suggests, BS calculates the foreground mask performing a subtraction between the current frame and a background model, containing the static part of the scene or, more in general, everything that can be considered as background given the characteristics of the observed scene.
Background modeling consists of two main steps:
In the first step, an initial model of the background is computed, while in the second step that model is updated in order to adapt to possible changes in the scene.
In this tutorial you will learn how to:
In the following you can find the source code. We will let the user chose to process either a video file or a sequence of images.
Two different methods are used to generate two foreground masks:
The results as well as the input data are shown on the screen. The source file can be downloaded here.
We discuss the main parts of the above code:
Given the following input parameters:
The output of the program will look as the following:
If you want to process a sequence of images, then the '-img' option has to be chosen:
The output of the program will look as the following:
To quantitatively evaluate the results obtained, we need to:
In order to save the output images, we can use cv::imwrite . Adding the following code allows for saving the foreground masks.
Once we have collected the result images, we can compare them with the ground truth data. There exist several publicly available sequences for background subtraction that come with ground truth data. If you decide to use the Background Models Challenge (BMC), then the result images can be used as input for the BMC Wizard. The wizard can compute different measures about the accuracy of the results.