In OpenCV 3 the public cv::BackgroundSubtractorMOG2() is now abstract so
we cannot inherit directly from it.
The concrete class would be BackgroundSubtractorMOG2Imp from
modules/video/src/bgfg_gaussmix2.cpp but it is private so we cannot
inherit from it either.
Use the factory method as documented to get a cv::BackgroundSubtractor
instance of the desired type and use is as a property in the
MOG2Segmentation class.
* http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html
*/
* http://docs.opencv.org/master/d1/dc5/tutorial_background_subtraction.html
*/
-class MOG2Segmentation : public Segmentation, public cv::BackgroundSubtractorMOG2 {
+class MOG2Segmentation : public Segmentation {
- MOG2Segmentation(cv::VideoCapture& inputVideo, int learning_frames) :
- cv::BackgroundSubtractorMOG2()
+ MOG2Segmentation(cv::VideoCapture& inputVideo, int learning_frames)
{
cv::Mat background;
cv::Mat foreground_mask;
{
cv::Mat background;
cv::Mat foreground_mask;
+ pMOG2 = cv::createBackgroundSubtractorMOG2();
for (int i = 0; i < learning_frames; i++) {
inputVideo >> background;
for (int i = 0; i < learning_frames; i++) {
inputVideo >> background;
- this->operator()(background, foreground_mask);
+ pMOG2->apply(background, foreground_mask);
{
cv::Mat foreground_mask;
{
cv::Mat foreground_mask;
- this->operator()(frame, foreground_mask, 0);
+ pMOG2->apply(frame, foreground_mask, 0);
cv::erode(foreground_mask, foreground_mask, cv::Mat());
cv::dilate(foreground_mask, foreground_mask, cv::Mat());
cv::threshold(foreground_mask, foreground_mask, 0, 255, CV_THRESH_OTSU);
cv::erode(foreground_mask, foreground_mask, cv::Mat());
cv::dilate(foreground_mask, foreground_mask, cv::Mat());
cv::threshold(foreground_mask, foreground_mask, 0, 255, CV_THRESH_OTSU);
return foreground_mask;
}
return foreground_mask;
}
+
+ void getBackgroundImage(const cv::Mat& background)
+ {
+ pMOG2->getBackgroundImage(background);
+ }
+
+private:
+ cv::Ptr<cv::BackgroundSubtractor> pMOG2;
};
#endif // SEGMENTATION_HPP
};
#endif // SEGMENTATION_HPP