OpenCV
4.5.0
Open Source Computer Vision
|
Next Tutorial: Meanshift and Camshift
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 choose to process either a video file or a sequence of images.
We will use cv::BackgroundSubtractorMOG2 in this sample, to generate the foreground mask.
The results as well as the input data are shown on the screen.
We discuss the main parts of the code above:
apply
method.With the vtest.avi
video, for the following frame:
The output of the program will look as the following for MOG2 method (gray areas are detected shadows):
The output of the program will look as the following for the KNN method (gray areas are detected shadows):