#include?“cv.h“
#include?“cvaux.h“
#include?“highgui.h“
#include?
#include?
void?play(CvCapture*?captureint?startint?end){???//讀取視頻片段的方法
???IplImage*?frame?=NULL;
???cvSetCaptureProperty(capture?CV_CAP_PROP_POS_frameS?start);
???cvNamedWindow(“Fragment“0);
????while?(start<=end)??
??{??
????start++;
???
????frame?=?cvQueryframe(capture);??
????if?(!frame)???
??????break;??
??
????cvShowImage(“Fragment“?frame);??
????cvWaitKey(30);???????
????
??}????
}
int?main(int?argc?char**?argv)
{
????/*?Start?capturing?*/
????CvCapture*?capture?=?0;
????CvMemStorage*?storage=?cvCreateMemStorage(0);
????CvSeq*?contour=?0;
????IplImage*?pFrImg?=?NULL;
????CvFont?font;
????int?nFrmNum?=?0;
????int?totalFrm?=?0;
????int?select;?
????cvInitFont(?&font?CV_FONT_VECTOR01?1?0?1?8);
????if(?argc?==?1?||?(argc?==?2?&&?strlen(argv[1])?==?1?&&?isdigit(argv[1][0])))?
????????capture?=?cvCaptureFromCAM(?argc?==?2???argv[1][0]?-?‘0‘?:?0?);
????else?if(?argc?==?2?)
????????capture?=?cvCaptureFromAVI(?argv[1]?);
????if(?!capture?)
????{
????????fprintf(stderr“Could?not?initialize...\n“);
????????return?-1;
????}
????/*?Capture?1?video?frame?for?initialization?*/
????IplImage*?videoframe?=?NULL;
????videoframe?=?cvQueryframe(capture);??//讀取視頻
????totalFrm?=?(int)?cvGetCaptureProperty(capture?CV_CAP_PROP_frame_COUNT);?//得到視頻總幀數
????printf(“%d\n“totalFrm);
????int?FallFrm[totalFrm];
????int?FallFrms[totalFrm][2];
????int?Cframes[totalFrm][2];
????int?Fframes[totalFrm][2];
????for(int?i=0;i????{
????FallFrm[i]?=0;
????for(int?j=0;j<2;j++)
????{
????FallFrms[i][j]?=0;
????Cframes[i][j]?=0;
????Fframes[i][j]?=0;
????}
????}
????if(!videoframe)
????{
????????printf(“Bad?frame?\n“);
????????exit(0);
????}
????//?Create?windows
????cvNamedWindow(“VIDEO“?1);
????cvNamedWindow(“FG“?1);
????cvNamedWindow(“DETECT“?1);
????cvMoveWindow(“VIDEO“?30?0);??
????cvMoveWindow(“FG“?360?0);??
????cvMoveWindow(“DETECT“?690?0);?
??????
????CvGaussBGStatModelParams*?params?=?new?CvGaussBGStatModelParams;??????//高斯建模參數
????params->win_size=200;?
????params->n_gauss=5;
????params->bg_threshold=0.5;
????params->std_threshold=3.5;
????params->minArea=15;
????params->weight_init=0.05;
????params->variance_init=30;
????//?Creat?CvBGStatModel
????//?cvCreateGaussianBGModel(?IplImage*?first_frame?CvGaussBGStatModelParams*?parameters?)
????//?or
????//?cvCreateGaussianBGModel(?IplImage*?first_frame?)
????CvBGStatModel*?bgModel?=?NULL;
????while(videoframe?=?cvQueryframe(capture))???//逐幀顯示視頻
????{
????????nFrmNum++;
????????if(nFrmNum?==?1)
????????//?Grab?a?fram
????????{
???????//?videoframe?=?cvQueryframe(capture);
????????pFrImg?=?cvCreateImage(cvSize(videoframe->width?videoframe->height)??IPL_DEPTH_8U1);
???????//?cvCvtColor(?videoframepFrImg?CV_BGR2GRAY);
????????//if(?!videoframe?)
?????????//???break;
????????bgModel?=?cvCreateGaussianBGModel(videoframe?params);??//建立高斯模型
????????}else
????????//?Update?model
{
???????cvUpdateBG
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7875??2012-01-11?17:17??gaosi\gaosi.cpp
?????目錄??????????0??2012-05-23?15:50??gaosi
-----------?---------??----------?-----??----
?????????????????7875????????????????????2