Ask Your Question
0

BackgroundSubtractorMOG

asked 2015-06-23 05:59:32 -0600

Nbb gravatar image

updated 2015-06-23 09:41:43 -0600

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

edit retag flag offensive close merge delete

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 ( 2015-06-23 08:42:44 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2015-06-23 06:02:46 -0600

LBerger gravatar image

updated 2015-06-25 06:08:31 -0600

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

edit flag offensive delete link more

Comments

2

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

berak gravatar imageberak ( 2015-06-23 06:08:33 -0600 )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 ( 2015-06-25 04:21:55 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-06-23 05:59:32 -0600

Seen: 4,199 times

Last updated: Jun 25 '15