基于OPENCV的背景减除方法
openCV 2009-04-27 14:59:32 阅读59 评论0 字号:大中小
//经实验发现,用背景减除方法也可以针对某些摄像机运动的情况,而非像大部分文章中所提到的该方法仅仅适合于摄像机静止的情况,而且效果还要较好!!
/*
*建立多高斯背景模型
*/
void CMotionAnalysisPlatformView::OnBackgdiff()
{
// TODO: Add mand handler code here
IplImage* tmp_frame = 0;
IplImage* dst = 0;
if(!m_capture)
{
MessageBox("读取视频文件失败,请重新打开真彩色(24位)视频!", "错误信息");
return;
}
tmp_frame = cvQueryFrame(m_capture);
dst = cvCreateImage(cvGetSize(tmp_frame), 8, 1);
dst->origin = 1;
if(!tmp_frame)
{
MessageBox("读取视频文件失败,请重新打开真彩色(24位)视频!", "错误信息");
return;
}
cvNamedWindow("背景图像"
, 1);
cvNamedWindow("前景图像", 1);
//创建多高斯模型
CvBGStatModel* bg_model = cvCreateGaussianBGModel(tmp_frame);
for( int fr = 1;tmp_frame; tmp_frame = cvQueryFrame(m_capture), fr++ )
{
//printf("frame# %d : ", fr);
//获得背景模型更新过程所花费的时间,以 CPU时钟/每微秒为单位计数
//double t = (double)cvGetTickCount(); //模型更新之前
cvUpdateBGStatModel( tmp_frame, bg_model );
//真正的函数实现体是在: icvUpdateFGDStatModel(tmp_frame, bg_model)
// t = (double)cvGetTickCount() - t; //模型更新之后
// 以左下角为坐标原点
bg_mo
del->foreground->origin = bg_model->background->origin = 1;
//cvErode(bg_model->background, bg_model->background);
//滤除噪声
//cvErode(bg_model->foreground, bg_model->foreground);
//滤除噪声
//printf( "%.1f毫秒n", t/(cvGe
基于OPENCV的背景减除方法 来自淘豆网m.daumloan.com转载请标明出处.