关于OpenCV混合高斯模型的问题
根据http://baike.baidu.com/view/2663975.htm所说的配置,并修改源代码如下:
#include <stdio.h>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <cvaux.h>
void main( )
{
IplImage* pFrame = NULL;
IplImage* pFrImg = NULL;
IplImage* pBkImg = NULL;
CvCapture* pCapture = NULL;
int nFrmNum = 0;
cvNamedWindow("video", 1);
cvNamedWindow("background",1);
cvNamedWindow("foreground",1);
cvMoveWindow("video", 30, 0);
cvMoveWindow("background", 360, 0);
cvMoveWindow("foreground", 690, 0);
//打开视频文件
pCapture = cvCaptureFromFile("video.avi") ;
//初始化高斯混合模型参数
CvGaussBGModel* bg_model=NULL;
while(pFrame = cvQueryFrame( pCapture ))
{
nFrmNum++;
if(nFrmNum == 1)
{
pBkImg = cvCreateImage(cvSize(pFrame->width, pFrame->height), IPL_DEPTH_8U,3);
pFrImg = cvCreateImage(cvSize(pFrame->width, pFrame->height), IPL_DEPTH_8U,1);
//高斯背景建模,pFrame可以是多通道图像也可以是单通道图像
//cvCreateGaussianBGModel函数返回值为CvBGStatModel*,
//需要强制转换成CvGaussBGModel*
bg_model = (CvGaussBGModel*)cvCreateGaussianBGModel(pFrame, 0);
}
else
{
//更新高斯模型
cvUpdateBGStatModel(pFrame, (CvBGStatModel *)bg_model );
//pFrImg为前景图像,只能为单通道
//pBkImg为背景图像,可以为单通道或与pFrame通道数相同
cvCopy(bg_model->foreground,pFrImg,0);
cvCopy(bg_model->background,pBkImg,0);
//把图像正过来
pBkImg->origin=0;
pFrImg->origin=0;
cvShowImage("video", pFrame);
cvShowImage("background", pBkImg);
cvShowImage("foreground", pFrImg);
if( cvWaitKey(2) >= 0 )
break;
}
}
//释放内存
cvReleaseBGStatModel((CvBGStatModel**)&bg_model);
cvDestroyWindow("video");
cvDestroyWindow("background");
cvDestroyWindow("foreground");
cvReleaseImage(&pFrImg);
cvReleaseImage(&pBkImg);
cvReleaseCapture(&pCapture);
}
可运行起来有如下错误,希望高手指点!
c:\program files\opencv\cvaux\include\cvaux.h(1142) : error C2059: syntax error : ';'
c:\program files\opencv\cvaux\include\cvaux.h(1143) : error C2059: syntax error : '}'
c:\program files\opencv\cvaux\include\cvaux.h(1149) : error C2143: syntax error : missing ')' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1149) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1149) : error C2059: syntax error : ')'
c:\program files\opencv\cvaux\include\cvaux.h(1150) : error C2054: expected '(' to follow 'bg_model'
c:\program files\opencv\cvaux\include\cvaux.h(1156) : error C2143: syntax error : missing ')' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1156) : error C2081: 'CvBGStatModel' : name in formal parameter list illegal
c:\program files\opencv\cvaux\include\cvaux.h(1156) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1156) : error C2059: syntax error : ')'
c:\program files\opencv\cvaux\include\cvaux.h(1157) : error C2040: 'bg_model' : 'int *' differs in levels of indirection from 'int ** '
c:\program files\opencv\cvaux\include\cvaux.h(1157) : error C2054: expected '(' to follow 'bg_model'
c:\program files\opencv\cvaux\include\cvaux.h(1166) : error C2143: syntax error : missing ')' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1166) : error C2081: 'CvBGStatModel' : name in formal parameter list illegal
c:\program files\opencv\cvaux\include\cvaux.h(1166) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1166) : error C2059: syntax error : ')'
c:\program files\opencv\cvaux\include\cvaux.h(1166) : error C2040: 'bg_model' : 'int *' differs in levels of indirection from 'int ** '
c:\program files\opencv\cvaux\include\cvaux.h(1241) : error C2059: syntax error : ';'
c:\program files\opencv\cvaux\include\cvaux.h(1247) : error C2059: syntax error : '}'
c:\program files\opencv\cvaux\include\cvaux.h(1251) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1301) : error C2059: syntax error : ';'
c:\program files\opencv\cvaux\include\cvaux.h(1302) : error C2371: 'params' : redefinition; different basic types
c:\program files\opencv\cvaux\include\cvaux.h(1246) : see declaration of 'params'
c:\program files\opencv\cvaux\include\cvaux.h(1305) : error C2059: syntax error : '}'
c:\program files\opencv\cvaux\include\cvaux.h(1310) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1312) : error C2143: syntax error : missing ')' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1312) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1312) : error C2059: syntax error : ')'
c:\program files\opencv\cvaux\include\cvaux.h(1313) : error C2143: syntax error : missing ')' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1313) : error C2081: 'CvGaussBGModel' : name in formal parameter list illegal
c:\program files\opencv\cvaux\include\cvaux.h(1313) : error C2143: syntax error : missing '{' before '*'
c:\program files\opencv\cvaux\include\cvaux.h(1313) : error C2059: syntax error : ')'
c:\program files\opencv\cvaux\include\cvaux.h(1313) : error C2040: 'bg_model' : 'int *' differs in levels of indirection from 'int ** '
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(23) : error C2065: 'CvGaussBGModel' : undeclared identifier
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(23) : error C2297: '*' : illegal, right operand has type 'int ** '
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(34) : error C2059: syntax error : ')'
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(39) : warning C4013: 'cvUpdateBGStatModel' undefined; assuming extern returning int
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(39) : error C2065: 'CvBGStatModel' : undeclared identifier
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(39) : error C2059: syntax error : ')'
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(42) : error C2223: left of '->foreground' must point to struct/union
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(42) : error C2198: 'cvCopy' : too few actual parameters
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(43) : error C2223: left of '->background' must point to struct/union
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(43) : error C2198: 'cvCopy' : too few actual parameters
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(55) : warning C4013: 'cvReleaseBGStatModel' undefined; assuming extern returning int
c:\users\administrator\desktop\例5-8 - 副本\motiondetect.c(55) : error C2059: syntax error : ')'