資源簡介
opencv 實(shí)現(xiàn)高斯混合算法,加入按幀讀取圖片和AVI讀取圖片,路徑需自己設(shè)定。
代碼片段和文件信息
//?detect_gauss.cpp?:?定義控制臺應(yīng)用程序的入口點(diǎn)。
//
#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:\\目標(biāo)識別\\素材\\對比素材\\“;
//初始化高斯混合模型參數(shù)
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函數(shù)返回值為CvBGStatModel*,
//需要強(qiáng)制轉(zhuǎn)換成CvGaussBGModel*
bg_model?=?(CvGaussBGModel*)cvCreateGaussianBGModel(pframeNULL);
}?????
else
{????
//更新高斯模型
//cvUpdateBGStatModel(pframe?(CvBGStatModel?*)bg_model?);
icvUpdateGaussianBGModel(pframebg_model-1);
//pFrImg為前景圖像,只能為單通道
//pBkImg為背景圖像,可以為單通道或與pframe通道數(shù)相同
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;
}?????
}
//釋放高斯模型參數(shù)占用內(nèi)存???
cvReleaseBGStatModel((CvBGStatModel**)&bg_model);
cvDestroyWindow(“video“);?
cvDestroyWindow(“background“);?
cvDestroyWindow(“foreground“);???
cvReleaseImage(&pFrImg);?
cvReleaseImage(&pBkImg);
cvReleaseImage(&pFrImg);
//cvReleaseCapture(&pCapture);???
return?0;
}
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????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.em
?????文件????????472??2011-10-27?11:35??detect_gauss\detect_gauss\Debug\detect_gauss.exe.em
?????文件????????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\li
?????文件??????????2??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件??????????2??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件??????????2??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件??????????2??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件??????????2??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件???????1814??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件???????3200??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件????????846??2011-10-31?21:49??detect_gauss\detect_gauss\Debug\li
?????文件????????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個(gè)文件信息
評論
共有 條評論