First time here? Check out the FAQ!

Ask Your Question
0

BackgroundSubtractorMOG

asked Jun 23 '15

Nbb gravatar image

updated Jun 23 '15

LorenaGdL gravatar image

Hello forum,

I tried to follow this tutorial on background subtraction at http://docs.opencv.org/master/d1/dc5/...

I seem to be having a problem though.

pMOG = createBackgroundSubtractorMOG(); //MOG approach

gives me an error

Error: identifier "createBackgroundSubtractorMOG" is undefined.

Also, for the BackgroundSubtractorMOG2, how do I remove shadows ? I cant seem to add in any parameters when I create the background subtractor MOG2. Looking through http://docs.opencv.org/modules/video/... does not tell me how to use the backgroundsubtractors. Hope someone can clarify on this. Thanks

Preview: (hide)

Comments

1

Regarding BackgroundSubtractorMOG2 and shadows, in that very same link you provided you can see how to remove them. The constructor is BackgroundSubtractorMOG2(int history, float varThreshold, bool bShadowDetection=true ) where bShadowDetection turns on/off shadow detection. The parameter uchar nShadowDetection controls the value assigned to detected shadows (127 by default)

LorenaGdL gravatar imageLorenaGdL (Jun 23 '15)edit

1 answer

Sort by » oldest newest most voted
2

answered Jun 23 '15

LBerger gravatar image

updated Jun 25 '15

You should used cv::bgsegm::createBackgroundSubtractorMOG(); in opencv 3.0 You have a tutorial for MOG you can use this parameters for MOG

cv::Ptr<cv::BackgroundSubtractor> b;
b = cv::bgsegm::createBackgroundSubtractorMOG(); 
b.dynamicCast<cv::bgsegm::BackgroundSubtractorMOG>()->setHistory(history);
b.dynamicCast<cv::bgsegm::BackgroundSubtractorMOG>()->setBackgroundRatio(BackgroundRatio);
b.dynamicCast<cv::bgsegm::BackgroundSubtractorMOG>()->setNMixtures(mixtures);
b.dynamicCast<cv::bgsegm::BackgroundSubtractorMOG>()->setNoiseSigma(NoiseSigma);
b.dynamicCast<cv::bgsegm::BackgroundSubtractorMOG>()->apply(img, imDst,learningRate);

and this for MOG2

cv::Ptr<cv::BackgroundSubtractor> b;
    b = cv::createBackgroundSubtractorMOG2(); 
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setHistory(history);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setNMixtures(mixtures);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setBackgroundRatio(BackgroundRatio);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setVarThreshold(VarThreshold);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setVarThresholdGen(VarThresholdGen);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setVarInit(VarInit);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setVarMin(VarMin);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setVarMax(VarMax);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setComplexityReductionThreshold(ComplexityReductionThreshold);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setDetectShadows(DetectShadows);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setShadowValue(ShadowValue);
    b.dynamicCast<cv::BackgroundSubtractorMOG2>()->setVarThreshold(ShadowThreshold);
b.dynamicCast<cv::BackgroundSubtractorMOG2>()->apply(img, imDst, learningRate);

PS I haven't test syntax

Preview: (hide)

Comments

2

also, BackgroundSubtractorMOG and BackgroundSubtractorGMG got moved to https://github.com/Itseez/opencv_contrib

berak gravatar imageberak (Jun 23 '15)edit

http://docs.opencv.org/master/d1/dc5/...

The results at the end show the difference between MOG and MOG2. May I know if it is possible to tune the MOG2 to achieve the same results as the MOG ?

I have been reading the articles at http://docs.opencv.org/modules/video/... under backgroundsubtractorMOG and backgroundsubtractorMOG2 and am in the process of figuring out the main difference.

Nbb gravatar imageNbb (Jun 25 '15)edit

Question Tools

1 follower

Stats

Asked: Jun 23 '15

Seen: 4,211 times

Last updated: Jun 25 '15