基于OPENCV的背景减除方法openCV2009-04-2714:59:32阅读59评论0字号:大中小//经实验发现,用背景减除方法也可以针对某些摄像机运动的情况,而非像大部分文章中所提到的该方法仅仅适合于摄像机静止的情况,而且效果还要较好!!/**建立多高斯背景模型*/voidCMotionAnalysisPlatformView::OnBackgdiff(){ //TODO:mandhandlercodehere 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(intfr=1;tmp_frame;tmp_frame=cvQueryFrame(m_capture),fr++){ //printf("frame#%d:",fr); //获得背景模型更新过程所花费的时间,以CPU时钟/每微秒为单位计数 //doublet=(double)cvGetTickCount(); //模型更新之前 cvUpdateBGStatModel(tmp_frame,bg_model); //真正的函数实现体是在:icvUpdateFGDStatModel(tmp_frame,bg_model) //t=(double)cvGetTickCount()- t; //模型更新之后//以左下角为坐标原点bg_model->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/(cvGetTickFrequency()*1000.));//最后输出结果以毫秒为单位 cvShowImage("背景图像",bg_model->background); cvCopy(bg_model->foreground,dst); cvSmooth(dst,dst,CV_GAUSSIAN,5); cvMorphologyEx(dst,dst,0,0,CV_MOP_CLOSE,3); cvMorphologyEx(dst,dst,0,0,CV_MO
基于OPENCV的背景减除方法 来自淘豆网m.daumloan.com转载请标明出处.