资源简介

opencv 实现高斯混合算法,加入按帧读取图片和AVI读取图片,路径需自己设定。

资源截图

代码片段和文件信息

// detect_gauss.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h“
#include 
#include 
#include 
#include //必须引此头文件
#include “openFile.h“
#include “gauss.h“
using namespace std;

int _tmain(int argc _TCHAR* argv[])
{
IplImage* pframe = NULL;
IplImage* pFrImg = NULL;
IplImage* pBkImg = NULL;
//CvCapture* pCapture = NULL;
int nFrmNum = 0;

cvNamedWindow(“video“);
cvNamedWindow(“background“);
cvNamedWindow(“foreground“);

//打开视频文件
string filepath = “E:\\目标识别\\素材\\对比素材\\“;


//初始化高斯混合模型参数
CvGaussBGModel* bg_model=NULL;

//while(pframe = cvQueryframe( pCapture ))
while(pframe = cvLoadImage(generantFileName(filepath““nFrmNum).c_str()))

nFrmNum++;           
if(nFrmNum == 1)   
{    
pBkImg = cvCreateImage(cvSize(pframe->width pframe->height)  IPL_DEPTH_8U3);
pFrImg = cvCreateImage(cvSize(pframe->width pframe->height)  IPL_DEPTH_8U1);


//高斯背景建模,pframe可以是多通道图像也可以是单通道图像
//cvCreateGaussianBGModel函数返回值为CvBGStatModel*,
//需要强制转换成CvGaussBGModel*
bg_model = (CvGaussBGModel*)cvCreateGaussianBGModel(pframeNULL);
}     
else
{    
//更新高斯模型
//cvUpdateBGStatModel(pframe (CvBGStatModel *)bg_model );
icvUpdateGaussianBGModel(pframebg_model-1);
//pFrImg为前景图像,只能为单通道
//pBkImg为背景图像,可以为单通道或与pframe通道数相同
cvCopy(bg_model->foregroundpFrImg0);
cvCopy(bg_model->backgroundpBkImg0);

//把图像正过来
//pBkImg->origin=1;
//pFrImg->origin=1;

cvShowImage(“video“ pframe);    
cvShowImage(“background“ pBkImg);    
cvShowImage(“foreground“ pFrImg);       
if( cvWaitKey(2) == 27 )
break;
}     

}

//释放高斯模型参数占用内存   
cvReleaseBGStatModel((CvBGStatModel**)&bg_model);
cvDestroyWindow(“video“); 
cvDestroyWindow(“background“); 
cvDestroyWindow(“foreground“);   
cvReleaseImage(&pFrImg); 
cvReleaseImage(&pBkImg);
cvReleaseImage(&pFrImg);
//cvReleaseCapture(&pCapture);   
return 0;
}


 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件      83456  2011-10-31 21:49  detect_gauss\Debug\detect_gauss.exe

     文件     691208  2011-10-31 21:49  detect_gauss\Debug\detect_gauss.ilk

     文件    1485824  2011-10-31 21:49  detect_gauss\Debug\detect_gauss.pdb

     文件       1474  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\cl.command.1.tlog

     文件      28994  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\CL.read.1.tlog

     文件        784  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\CL.write.1.tlog

     文件        406  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\detect_gauss.exe.embed.manifest

     文件        472  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\detect_gauss.exe.embed.manifest.res

     文件        381  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\detect_gauss.exe.intermediate.manifest

     文件         51  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\detect_gauss.lastbuildstate

     文件       3436  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\detect_gauss.log

     文件     293418  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\detect_gauss.obj

     文件    1179648  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\detect_gauss.pch

     文件        214  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\detect_gauss_manifest.rc

     文件          2  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link-cvtres.read.1.tlog

     文件          2  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link-cvtres.write.1.tlog

     文件          2  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.4372-cvtres.read.1.tlog

     文件          2  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.4372-cvtres.write.1.tlog

     文件          2  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.4372.read.1.tlog

     文件          2  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.4372.write.1.tlog

     文件       1814  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.command.1.tlog

     文件       3200  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.read.1.tlog

     文件        846  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\link.write.1.tlog

     文件        406  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\mt.command.1.tlog

     文件        390  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\mt.read.1.tlog

     文件        322  2011-10-31 21:49  detect_gauss\detect_gauss\Debug\mt.write.1.tlog

     文件        562  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\rc.command.1.tlog

     文件        294  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\rc.read.1.tlog

     文件        302  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\rc.write.1.tlog

     文件      11971  2011-10-27 11:35  detect_gauss\detect_gauss\Debug\stdafx.obj

............此处省略43个文件信息

评论

共有 条评论