diff --git a/doc/conf.py b/doc/conf.py index 2cbcdf8867..2477a300ea 100755 --- a/doc/conf.py +++ b/doc/conf.py @@ -416,5 +416,9 @@ extlinks = { 'brute_force_matcher' : ('http://docs.opencv.org/modules/features2d/doc/common_interfaces_of_descriptor_matchers.html?highlight=bruteforcematcher#bruteforcematcher%s', None ), 'cascade_classifier' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=cascadeclassifier#cascadeclassifier%s', None ), 'cascade_classifier_load' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=load#cascadeclassifier-load%s', None ), - 'cascade_classifier_detect_multiscale' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale%s', None ) + 'cascade_classifier_detect_multiscale' : ('http://docs.opencv.org/modules/objdetect/doc/cascade_classification.html?highlight=detectmultiscale#cascadeclassifier-detectmultiscale%s', None ), + 'background_subtractor' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractor#backgroundsubtractor%s', None), + 'background_subtractor_mog' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG#backgroundsubtractormog%s', None), + 'background_subtractor_mog_two' : ('http://docs.opencv.org/modules/video/doc/motion_analysis_and_object_tracking.html?highlight=backgroundsubtractorMOG2#backgroundsubtractormog2%s', None), + 'video_capture' : ('http://docs.opencv.org/modules/highgui/doc/reading_and_writing_images_and_video.html?highlight=videocapture#videocapture%s', None) } diff --git a/doc/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst b/doc/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst index ef47b23230..54bac5bcab 100644 --- a/doc/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst +++ b/doc/py_tutorials/py_video/py_bg_subtraction/py_bg_subtraction.rst @@ -1,4 +1,4 @@ -.. _background_subtraction: +.. _py_background_subtraction: Background Subtraction diff --git a/doc/py_tutorials/py_video/py_table_of_contents_video/py_table_of_contents_video.rst b/doc/py_tutorials/py_video/py_table_of_contents_video/py_table_of_contents_video.rst index 79c99553c1..a8c2d3dba6 100644 --- a/doc/py_tutorials/py_video/py_table_of_contents_video/py_table_of_contents_video.rst +++ b/doc/py_tutorials/py_video/py_table_of_contents_video/py_table_of_contents_video.rst @@ -32,7 +32,7 @@ Video Analysis :width: 90pt -* :ref:`background_subtraction` +* :ref:`py_background_subtraction` .. tabularcolumns:: m{100pt} m{300pt} .. cssclass:: toctableopencv diff --git a/doc/tutorials/definitions/tocDefinitions.rst b/doc/tutorials/definitions/tocDefinitions.rst index d1fb039702..c036b0b708 100644 --- a/doc/tutorials/definitions/tocDefinitions.rst +++ b/doc/tutorials/definitions/tocDefinitions.rst @@ -11,4 +11,5 @@ .. |Author_EricCh| unicode:: Eric U+0020 Christiansen .. |Author_AndreyP| unicode:: Andrey U+0020 Pavlenko .. |Author_AlexS| unicode:: Alexander U+0020 Smorkalov -.. |Author_BarisD| unicode:: Bar U+0131 U+015F U+0020 Evrim U+0020 Demir U+00F6 z \ No newline at end of file +.. |Author_BarisD| unicode:: Bar U+0131 U+015F U+0020 Evrim U+0020 Demir U+00F6 z +.. |Author_DomenicoB| unicode:: Domenico U+0020 Daniele U+0020 Bloisi diff --git a/doc/tutorials/video/background_subtraction/background_subtraction.rst b/doc/tutorials/video/background_subtraction/background_subtraction.rst new file mode 100644 index 0000000000..0ef5ef5162 --- /dev/null +++ b/doc/tutorials/video/background_subtraction/background_subtraction.rst @@ -0,0 +1,388 @@ +.. _Background_Subtraction: + +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. + + .. image:: images/Background_Subtraction_Tutorial_Scheme.png + :alt: Background Subtraction - General Scheme + :align: center + +* Background modeling consists of two main steps: + + #. Background Initialization; + #. Background Update. + + 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 we will learn how to perform BS by using OpenCV. As input, we will use data coming from the publicly available data set `Background Models Challenge (BMC) `_ . + +Goals +====== + +In this tutorial you will learn how to: + + #. Read data from videos by using :video_capture:`VideoCapture <>` or image sequences by using :imread:`imread <>`; + #. Create and update the background model by using :background_subtractor:`BackgroundSubtractor <>` class; + #. Get and show the foreground mask by using :imshow:`imshow <>`; + #. Save the output by using :imwrite:`imwrite <>` to quantitatively evaluate the results. + +Code +===== + +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: + #. :background_subtractor_mog:`MOG <>` + #. :background_subtractor_mog_two:`MOG2 <>` + +The results as well as the input data are shown on the screen. + +.. code-block:: cpp + + //opencv + #include + #include + //C + #include + //C++ + #include + #include + + using namespace cv; + using namespace std; + + //global variables + Mat frame; //current frame + Mat fgMaskMOG; //fg mask generated by MOG method + Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method + Ptr pMOG; //MOG Background subtractor + Ptr pMOG2; //MOG2 Background subtractor + int keyboard; + + //function declarations + void help(); + void processVideo(char* videoFilename); + void processImages(char* firstFrameFilename); + + void help() + { + cout + << "--------------------------------------------------------------------------" << endl + << "This program shows how to use background subtraction methods provided by " << endl + << " OpenCV. You can process both videos (-vid) and images (-img)." << endl + << endl + << "Usage:" << endl + << "./bs {-vid