麻烦哪位大仙能帮我看看下面的代码哪里错了?vc6.0+opencv1.0

海之梦-爱琴海 2013-01-22 02:03:06
麻烦哪位大仙能帮我看看下面的代码哪里错了?本人是初学者。。。代码是在vc6.0+opencv1.0环境下的,代码编译通过了,只是运行以后会弹出一个对话框,好像是NULL pointer(opencv gui error hander)

#include"cv.h"
#include"highgui.h"
#include"math.h"
#include"cxcore.h"
#include"stdio.h"

int main()
{ int i,j;
IplImage* image1=0;
IplImage *gg1=0, *gg2=0, *gg3=0, *gg4=0, *gg5=0, *gg6=0, *gg=0;
IplImage* image2=0;
IplImage* image3=0;
IplImage* image4=0;
IplImage* image5=0;


IplImage* tempImg1=0;
IplImage* tempImg2=0;
IplImage* tempImg3=0;
CvSize size;


image3=cvLoadImage("3.bmp", 0);

image1=cvLoadImage("1.bmp", 0);
image2=cvLoadImage("2.bmp", 0);

image4=cvLoadImage("4.bmp", 0);
image5=cvLoadImage("5.bmp", 0);

gg1=cvCreateImage(cvSize(image3->width,image3->height), 8, 1 );
gg2=cvCreateImage(cvSize(image3->width,image3->height), 8, 1);
gg3=cvCreateImage(cvSize(image3->width,image3->height), 8, 1);
gg4=cvCreateImage(cvSize(image3->width,image3->height), 8, 1);
gg5=cvCreateImage(cvSize(image3->width,image3->height), 8, 1);
gg6=cvCreateImage(cvSize(image3->width,image3->height), 8, 1);



size = cvSize(image3->width, image3->height);
//tempImg1 = cvCreateImage( cvSize((size.width & -2)/2, (size.height & -2)/2), 8, 1 );
tempImg1 = cvCreateImage( cvSize( image3 -> width/2, image3 -> height/2 ), image3 -> depth, image3 -> nChannels );



for(i=0;i<image3->width;i++)
{

for(j=0;j<image3->height;j++)
{
CvPoint pt = {i,j};
((uchar*)(gg1->imageData + gg1->widthStep*pt.y))[pt.x]=abs(
((uchar*)(image3->imageData + image3->widthStep*pt.y))[pt.x]-
((uchar*)(image1->imageData + image1->widthStep*pt.y))[pt.x]);

((uchar*)(gg2->imageData + gg2->widthStep*pt.y))[pt.x]=abs(
((uchar*)(image5->imageData + image5->widthStep*pt.y))[pt.x]-
((uchar*)(image3->imageData + image3->widthStep*pt.y))[pt.x]);
}
}
cvAnd(gg1, gg2, gg3,0);
cvPyrDown(gg3, tempImg1, CV_GAUSSIAN_5x5);
cvDilate(gg3, gg3, 0, 1);
IplImage *gg7= cvCreateImage( cvSize( tempImg1 -> width*2, tempImg1 -> height*2 ),
tempImg1 -> depth, tempImg1 -> nChannels );
cvPyrUp(tempImg1, gg7, CV_GAUSSIAN_5x5);



tempImg2 = cvCreateImage( cvSize( image3 -> width/2, image3 -> height/2 ), image3 -> depth, image3 -> nChannels );
for(i=0;i<image3->width;i++)
{

for(j=0;j<image3->height;j++)
{
CvPoint pt = {i,j};
((uchar*)(gg4->imageData + gg4->widthStep*pt.y))[pt.x]=abs(
((uchar*)(image2->imageData + image2->widthStep*pt.y))[pt.x]-
((uchar*)(image3->imageData + image3->widthStep*pt.y))[pt.x]);

((uchar*)(gg5->imageData + gg5->widthStep*pt.y))[pt.x]=abs(
((uchar*)(image4->imageData + image4->widthStep*pt.y))[pt.x]-
((uchar*)(image3->imageData + image3->widthStep*pt.y))[pt.x]);
}
}
cvAnd(gg4, gg5, gg6,0);
cvPyrDown(gg6, tempImg2, CV_GAUSSIAN_5x5);
cvDilate(gg6, gg6, 0, 1);
IplImage *gg8= cvCreateImage( cvSize( tempImg2 -> width*2, tempImg2 -> height*2 ),
tempImg2 -> depth, tempImg2 -> nChannels );
cvPyrUp(tempImg2, gg8, CV_GAUSSIAN_5x5);



cvOr(gg7, gg8, gg, 0); cvPyrDown(gg, tempImg3, CV_GAUSSIAN_5x5);
printf("OK\n");




cvDilate(gg7, gg7, 0, 3);//pengzhang
cvErode(gg7, gg7, 0, 3);//fushi




cvNamedWindow( "运动图像1", 0);
cvNamedWindow( "运动图像2", 0);
cvNamedWindow( "运动图像3", 0);
cvNamedWindow( "运动图像4", 0);
cvNamedWindow( "运动图像5", 0);
cvNamedWindow( "帧间差分图像1", 0);
cvNamedWindow( "帧间差分图像2", 0);
cvNamedWindow( "帧间差分图像3", 0);


cvShowImage("运动图像1",image1);
cvShowImage("运动图像2",image2);
cvShowImage("运动图像3",image3);
cvShowImage("运动图像4",image4);
cvShowImage("运动图像5",image5);


cvShowImage("帧间差分图像1",gg3);
cvShowImage("帧间差分图像2",gg6);
cvShowImage("帧间差分图像3",gg);
cvWaitKey(0);//等待按键

//释放图像
cvReleaseImage(&image1);
cvReleaseImage(&image2);
cvReleaseImage(&image3);
cvReleaseImage(&image4);
cvReleaseImage(&image5);
cvReleaseImage(&gg3);
cvReleaseImage(&gg6);
cvReleaseImage(&gg);
//销毁窗口
cvDestroyWindow("运动图像1");
cvDestroyWindow("运动图像2");
cvDestroyWindow("运动图像3");
cvDestroyWindow("运动图像4");
cvDestroyWindow("运动图像5");
cvDestroyWindow("帧间差分图像1");
cvDestroyWindow("帧间差分图像2");
cvDestroyWindow("帧间差分图像3");

return(0);
}
...全文
26 1 点赞 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
zzz_zou 2013-01-22
看看堆栈信息,你就能知道是哪里错了。代码崩溃后,如果是调试状态,点击break,然后看看call stack。 很方便定位错误的。
  • 打赏
  • 举报
回复
相关推荐
发帖
图形处理/算法
加入

1.9w+

社区成员

VC/MFC 图形处理/算法
申请成为版主
帖子事件
创建了帖子
2013-01-22 02:03
社区公告
暂无公告