40
40
In the following you can find the source code. We will let the user chose to process either a video
41
41
file or a sequence of images.
42
42
43
- Two different methods are used to generate two foreground masks:
44
- -# cv::bgsegm::BackgroundSubtractorMOG
45
- -# @ref cv::BackgroundSubtractorMOG2
43
+ We will use @ref cv::BackgroundSubtractorMOG2 in this sample, to generate the foreground mask.
46
44
47
45
The results as well as the input data are shown on the screen.
48
46
The source file can be downloaded [ here ] ( https://github.com/opencv/opencv/tree/master/samples/cpp/tutorial_code/video/bg_sub.cpp ) .
@@ -54,22 +52,19 @@ Explanation
54
52
55
53
We discuss the main parts of the above code:
56
54
57
- -# First, three Mat objects are allocated to store the current frame and two foreground masks,
55
+ -# First, two Mat objects are allocated to store the current frame and two foreground masks,
58
56
obtained by using two different BS algorithms.
59
57
@code {.cpp}
60
58
Mat frame; //current frame
61
- Mat fgMaskMOG; //fg mask generated by MOG method
62
59
Mat fgMaskMOG2; //fg mask fg mask generated by MOG2 method
63
60
@endcode
64
- -# Two @ref cv::BackgroundSubtractor objects will be used to generate the foreground masks . In this
61
+ -# A @ref cv::BackgroundSubtractor object will be used to generate the foreground mask . In this
65
62
example, default parameters are used, but it is also possible to declare specific parameters in
66
63
the create function.
67
64
@code {.cpp}
68
- Ptr<BackgroundSubtractor > pMOG; //MOG Background subtractor
69
65
Ptr<BackgroundSubtractor > pMOG2; //MOG2 Background subtractor
70
66
...
71
- //create Background Subtractor objects
72
- pMOG = createBackgroundSubtractorMOG(); //MOG approach
67
+ //create Background Subtractor object
73
68
pMOG2 = createBackgroundSubtractorMOG2(); //MOG2 approach
74
69
@endcode
75
70
-# The command line arguments are analysed. The user can chose between two options:
@@ -101,7 +96,6 @@ We discuss the main parts of the above code:
101
96
set a specific learning rate by passing a third parameter to the 'apply' method.
102
97
@code {.cpp}
103
98
//update the background model
104
- pMOG->apply(frame, fgMaskMOG);
105
99
pMOG2->apply(frame, fgMaskMOG2);
106
100
@endcode
107
101
-# The current frame number can be extracted from the @ref cv::VideoCapture object and stamped in
@@ -121,7 +115,6 @@ We discuss the main parts of the above code:
121
115
@code {.cpp}
122
116
//show the current frame and the fg masks
123
117
imshow("Frame", frame);
124
- imshow("FG Mask MOG", fgMaskMOG);
125
118
imshow("FG Mask MOG 2", fgMaskMOG2);
126
119
@endcode
127
120
-# The same operations listed above can be performed using a sequence of images as input. The
0 commit comments