@ -6,11 +6,11 @@ How to Use Background Subtraction Methods
* Background subtraction (BS) is a common and widely used technique for generating a foreground mask (namely, a binary image containing the pixels belonging to moving objects in the scene) by using static cameras.
* 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.
@ -214,7 +214,7 @@ The results as well as the input data are shown on the screen.
fn.assign(nextFrameFilename);
}
}
* The source file can be downloaded :download:`here <../../../../samples/cpp/tutorial_code/video/bg_sub.cpp>`.
@ -226,18 +226,18 @@ We discuss the main parts of the above code:
#. First, three Mat objects are allocated to store the current frame and two foreground masks, obtained by using two different BS algorithms.
..code-block:: cpp
Mat frame; //current frame
Mat fgMaskMOG; //fg mask generated by MOG method
Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
#. Two :background_subtractor:`BackgroundSubtractor <>` objects will be used to generate the foreground masks. In this example, default parameters are used, but it is also possible to declare specific parameters in the create function.
@ -277,11 +277,11 @@ We discuss the main parts of the above code:
//update the background model
pMOG->apply(frame, fgMaskMOG);
pMOG2->apply(frame, fgMaskMOG2);
#. The current frame number can be extracted from the :video_capture:`VideoCapture <>` object and stamped in the top left corner of the current frame. A white rectangle is used to highlight the black colored frame number.
..code-block:: cpp
//get the frame number and write it on the current frame
@ -299,7 +299,7 @@ We discuss the main parts of the above code:
imshow("Frame", frame);
imshow("FG Mask MOG", fgMaskMOG);
imshow("FG Mask MOG 2", fgMaskMOG2);
#. The same operations listed above can be performed using a sequence of images as input. The processImage function is called and, instead of using a :video_capture:`VideoCapture <>` object, the images are read by using :imread:`imread <>`, after individuating the correct path for the next frame to read.
..code-block:: cpp
@ -327,10 +327,7 @@ We discuss the main parts of the above code:
//update the path of the current frame
fn.assign(nextFrameFilename);
Note that:
* this example works only on image sequences in which the filename format is <n>.png, where n is the frame number (e.g., 7.png).
* Note that this example works only on image sequences in which the filename format is <n>.png, where n is the frame number (e.g., 7.png).
Results
=======
@ -382,13 +379,10 @@ In order to save the output images, we can use :imwrite:`imwrite <>`. Adding the
}
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) <http://bmc.univ-bpclermont.fr/>`_, then the result images can be used as input for the `BMC Wizard <http://bmc.univ-bpclermont.fr/?q=node/7>`_. The wizard can compute different measures about the accuracy of the results.
* Antoine Vacavant, Thierry Chateau, Alexis Wilhelm and Laurent Lequievre. A Benchmark Dataset for Foreground/Background Extraction. In ACCV 2012, Workshop: Background Models Challenge, LNCS 7728, 291-300. November 2012, Daejeon, Korea.