关于OpenCV混合高斯模型的问题

geniuscod 2012-06-07 02:49:49
根据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 : ')'

...全文
642 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
benjamin1083 2014-03-02
  • 打赏
  • 举报
回复
#define CV_BG_STAT_MODEL_FIELDS() \ int type; /*type of BG model*/ \ CvReleaseBGStatModel release; \ CvUpdateBGStatModel update; \ IplImage* background; /*8UC3 reference background image*/ \ IplImage* foreground; /*8UC1 foreground image*/ \ IplImage** layers; /*8UC3 reference background image, can be null */ \ int layer_count; /* can be zero */ \ CvMemStorage* storage; /*storage for 揻oreground_regions?*/ \ //上面一行原来的文件少了一个* CvSeq* foreground_regions /*foreground object contours*/
benjamin1083 2014-03-02
  • 打赏
  • 举报
回复
cvaux.h文件错误
冷月清晖 2012-09-05
  • 打赏
  • 举报
回复
你看看“;”是不是你复制过来的是中文字符。
xiaopq123 2012-09-05
  • 打赏
  • 举报
回复
你是不是用的动态库
geniuscod 2012-06-12
  • 打赏
  • 举报
回复
恩,是编译错误,我说错了,但是这个头文件应该没错啊!会不会是代码的问题?
hard9999 2012-06-07
  • 打赏
  • 举报
回复
你这是编译错误,咋说成运行错误。
明显是头文件包含有问题。

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧