大后天要交作业了,大家帮忙啊,我的程序发生奇怪事件!!!

johnaaron 2009-12-28 02:35:06
只是切换了图片,小图50*50工作正常:




大图1024*768只工作到三分之一的地方直接结束没有报错什么的,见图:





我特意在一些地方放了打印文本的指令,可以看出差别了吧,跳掉了后面的部分

如下是我的程序,省略了一部分:

#include "stdio.h"
#include "stdlib.h"
#include "machine_vision.h"
#define PI 3.14159265
void MeanFilter(void);
void GaussianFilter(void);
void MedianFilter(void);
void Contrastenhancement(void);
void maxandmin(void);
void connectedcomponent(void);
void Center(void);
FILE *FilePtr;


int main(void)
{
char num[10];
char number[128];
unsigned int i,n=0;
unsigned int choice;

LoadBMPImage("c:\\Irb1400_Image1.bmp");
mprintf("\n\t ------ Menu ------\n");
mprintf("Enter No of Elements\n");
mprintf("\n\tEnter Choice\n\t1.Mean\n\t2.Gaussian\n\t3.Median\n\t4.Contrast enhancement\n\t5.Max and min\n\t6.Connected component \n\t7.Center \n\t8.Exit");

do
{
mscanf(num);
choice=atoi(num);
scanf("%d",choice);
switch(choice)
{
case 1:
MeanFilter();
break;
case 2:
GaussianFilter();
break;
case 3:
MedianFilter();
break;
case 4:
Contrastenhancement();
break;
case 5:
maxandmin();
break;
case 6:
connectedcomponent();
break;
case 7:
Center();
break;
case 8:
break;
}
}while(choice!=8);
}


void Center(void)
{
unsigned int *ImageDestination ;
int long Height,Width,leftp,currentp,topp,temp;
unsigned int *Temp_Image,TempPixRed ,TempPixGreen,TempPixBlue, Temp_Pixel;
unsigned int TempGrey;
unsigned int i,j,k,countobj=1,image[5000],corresp[5000],c,ne,nb; // for lab 3
int ctx,cty,area1; //for lab 4
double a1,b1,c1,tempangle,tangle,cx=0,cy=0;

mprintf("\n You chose Laboration 4 !\n");
//LoadBMPImage("c:\\connect_component_bw_small.bmp");
//LoadBMPImage("c:\\Irb1400_Image1.bmp");
ImageDestination=GetImageDest();
Height=GetImageHeight();
Width=GetImageWidth();

if ((Temp_Image = (unsigned int *)malloc(Height*Width*sizeof(unsigned int))) == NULL)
{
mprintf("Not enough memory to allocate buffer\n");
return;
}


for (i=0 ; i < Height*Width ;i++)
{
TempPixRed=RGB_RED(ImageDestination[i]);
TempPixGreen=RGB_GREEN(ImageDestination[i]);
TempPixBlue=RGB_BLUE(ImageDestination[i]);
TempGrey=(TempPixRed+ TempPixGreen+ TempPixBlue)/3 ;
ImageDestination[i]=RGB_C(TempGrey,TempGrey,TempGrey);
if (TempGrey > 100) //create balck and white
ImageDestination[i] = WHITE;
else if (TempGrey < 100)
ImageDestination[i] = BLACK;
}
Update();


for (i=0 ; i < Height*Width ;i++) //first run
{
if (RGB_RED(ImageDestination[i])!=BLACK)
image[i]=0;
else
image[i]=1;
} //换小图后,后面不执行,直接结束

for (i=Height-1; i>0; i--) //CC算法
{
for(j=0; j<Width-1; j++)
{
leftp=image[Width*i+(j-1)]; //left
topp=image[Width*(i+1)+j]; //top
currentp=image[Width*i+j]; //current

if (currentp!=0)
{
if (leftp==0 && topp>0)
image[Width*i+j]=topp;
else if(topp==0 && leftp>0)
image[Width*i+j]=leftp;
else if(leftp==topp && leftp>0 && topp>0)
image[Width*i+j]=leftp;
else if (leftp!=topp && leftp>0 && topp>0)
{
if (leftp > topp)
{image[Width*i+j]=topp;
corresp[leftp]=topp;}
else if (leftp < topp)
{image[Width*i+j]=leftp;
corresp[topp]=leftp;}
}
else
{
image[Width*i+j]=countobj;
nb=countobj;
corresp[nb]=nb;
countobj=countobj+1;}
}
}
}

for (i=1; i<=nb; i++) //depends on corresp list
{
k=i;
if (corresp[k]!=k)
{
k=corresp[k];
corresp[i]=corresp[k];
}
}


for (i=1; i<Height-1; i++)
{
for(j=1; j<Width-1; j++)
{
if (image[Width*i+j]!=0)
{
c=image[Width*i+j]; // transform
image[Width*i+j]=corresp[c];
}
}
}

if ((FilePtr= fopen("c:\\image.txt","w"))==NULL) //output image
mprintf("file could not be opend");

for (i=Height-1; i>0; i--)
{
for (j=0;j<Width-1;j++)
{
fprintf(FilePtr,"%2d",image[Width*i+j]);
}
fprintf(FilePtr,"\n");
}
fclose(FilePtr);



//*************************
for(c=1;c<=nb;c++)
{
area1=0; //reset to zero
ctx=0;
cty=0;
a1=0;
b1=0;
c1=0;
for (i=1; i<Height-1; i++)
{
for(j=1; j<Width-1; j++)
{
if (image[Width*i+j]==c)
{
ctx=(float)(j*1+ctx);
cty=(float)(i*1+cty);
area1=area1+1;
}
}
}

if (area1>0)
{
cx=(float)(ctx/area1);
cy=(float)(cty/area1);
mprintf("\n Object Information %d",c);
mprintf(" X-value of center position =%f",cx);
mprintf(" Y-value of center position =%f",cy);

for (i=1; i<Height-1; i++)
{
for(j=1; j<Width-1; j++)
{
if (image[Width*i+j]==c)
{
a1=(j-cx)*(j-cx)+a1;
b1=(j-cx)*(i-cy)+b1;
c1=(i-cy)*(i-cy)+c1;
}
}
}

if (a1==c1 && b1==0)
mprintf(" The orientation of object is not unique");
else
{ tangle=0.5*atan2(2*b1,a1-c1)*180/PI;
mprintf(" The Angle=%f\n",tangle);}

}
}

free(Temp_Image);
return 0;
}

...全文
196 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
johnaaron 2009-12-29
  • 打赏
  • 举报
回复
我完成了是越界问题,但是还是要谢谢大家
crushor 2009-12-28
  • 打赏
  • 举报
回复
你不是问怎么定义大数组吗?所以我告诉你用malloc罗,看你的代码像是C,如果C++的话,就用new罗。
johnaaron 2009-12-28
  • 打赏
  • 举报
回复
楼上什么意思啊?
crushor 2009-12-28
  • 打赏
  • 举报
回复
malloc
johnaaron 2009-12-28
  • 打赏
  • 举报
回复
发现个问题啊,我怎么定义一个数组,有八十万个数的,例如image[800000],怎么定义啊,我也新手啊
dskit 2009-12-28
  • 打赏
  • 举报
回复
跟到Center()里面去看下
sagegz 2009-12-28
  • 打赏
  • 举报
回复
但不调试下!F11
KnowKjava 2009-12-28
  • 打赏
  • 举报
回复
stdlib
MagiSu 2009-12-28
  • 打赏
  • 举报
回复
debug一下啊看看具体的数值。

65,187

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

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