opencv BackgroundSubtractorMOG和BackgroundSubtractorMOG2的区别

本文详细介绍了两种背景差分算法BackgroundSubtractorMOG和BackgroundSubtractorMOG2的构造函数及参数含义,对比了两者的差异,并展示了如何使用这两种算法更新背景模型并计算前景掩膜。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、官网BackgroundSubtractorMOG:
BackgroundSubtractorMOG::BackgroundSubtractorMOG

The constructors.

C++: BackgroundSubtractorMOG::BackgroundSubtractorMOG()

C++: BackgroundSubtractorMOG::BackgroundSubtractorMOG(int history, int nmixtures, double backgroundRatio, double noiseSigma=0)

Python: cv2.BackgroundSubtractorMOG([history, nmixtures, backgroundRatio[, noiseSigma]]) → <BackgroundSubtractorMOG object>
    Parameters:	

        history – Length of the history.
        nmixtures – Number of Gaussian mixtures.
        backgroundRatio – Background ratio.
        noiseSigma – Noise strength.

Default constructor sets all parameters to default values.
BackgroundSubtractorMOG::operator()

Updates the background model and returns the foreground mask

C++: void BackgroundSubtractorMOG::operator()(InputArray image, OutputArray fgmask, double learningRate=0)

Parameters are the same as in BackgroundSubtractor::operator()


2、BackgroundSubtractorMOG2:

BackgroundSubtractorMOG2::BackgroundSubtractorMOG2

The constructors.

C++: BackgroundSubtractorMOG2::BackgroundSubtractorMOG2()

C++: BackgroundSubtractorMOG2::BackgroundSubtractorMOG2(int history, float varThreshold, bool bShadowDetection=true )
    Parameters:	

        history – Length of the history.
        varThreshold – Threshold on the squared Mahalanobis distance to decide whether it is well described by the background model (see Cthr??). This parameter does not affect the background update. A typical value could be 4 sigma, that is, varThreshold=4*4=16; (see Tb??).
        bShadowDetection – Parameter defining whether shadow detection should be enabled (true or false).

BackgroundSubtractorMOG2::operator()

Updates the background model and computes the foreground mask

C++: void BackgroundSubtractorMOG2::operator()(InputArray image, OutputArray fgmask, double learningRate=-1)

    See BackgroundSubtractor::operator().


3、两者参数有点不同,比较坑的是两者都有提取背景的函数

C++: void BackgroundSubtractor::getBackgroundImage(OutputArray backgroundImage) const

C++: void BackgroundSubtractorMOG2::getBackgroundImage(OutputArray backgroundImage)
但在程序中测试,BackgroundSubtractor传入Mat,并没获得它的背景(传入的Mat没发生改变)

BackgroundSubtractorMOG2可以获得背景





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值