【OpenCV】高斯混合背景建模

本文介绍了OpenCV中的两种高斯混合背景/前景分割方法:BackgroundSubtractorMOG和BackgroundSubtractorMOG2。通过示例展示了如何使用它们进行背景建模,并提到了相关参数设置和阴影检测功能。同时,文中提及了获取背景图像的方法以及相关参考资料。
摘要由CSDN通过智能技术生成

OpenCV中实现了两个版本的高斯混合背景/前景分割方法(Gaussian Mixture-based Background/Foreground Segmentation Algorithm)[1-2],调用接口很明朗,效果也很好。

BackgroundSubtractorMOG 使用示例

 

int main(){
	VideoCapture video("1.avi");
	Mat frame,mask,thresholdImage, output;
	video>>frame;
	BackgroundSubtractorMOG bgSubtractor(20,10,0.5,false);
	while(true){
		video>>frame;
		++frameNum;
		bgSubtractor(frame,mask,0.001);
		imshow("mask",mask);
		waitKey(10);
	}
	return 0;
}

构造函数可以使用默认构造函数或带形参的构造函数:

 

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

 

其中history为使用历史帧的数目,nmixtures为混合高斯数量,backgroundRatio为背景比例,noiseSigma为噪声权重。

 

而调用的接口只有重载操作符():

 

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

其中image为当前帧图像,fgmask为输出的前景mask,learningRate为背景学习速率。

 

以下是使用BackgroundSubtractorMOG进行前景/背景检测的一个截图。

评论 17
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值