这个是一个图像处理的源程序,有错误不能运行,我是一个新手,由于作毕业设计,才学习的C,但是这个源程序不是纯C的,中间有点是C++的,还请各位高手给我修改一下。
#include "iostream.h"
#include "stdio.h"
#include "stdlib.h"
#include "math.h"
#define word unsigned short int
#define dword unsigned long int
void sobel(char *a);
struct bmp
{word bmpid;
dword filesize;
word reserved1;
word reserved2;
dword imageoffset;
dword headersize;
dword imagewidth;
dword imageheight;
word equiplevel;
word bitsperpixel;
dword encodetype;
dword imagesize;
dword xpixelpermeter;
dword ypixelpermeter;
dword colorused;
dword colorimportant;
};
void main()
{ char a[32];
printf("input the route :\n");
gets(a);
sobel(a);
}
void sobel(char *a)
{struct bmp *bmp1;
bmp1=(struct bmp*)malloc(sizeof(struct bmp));
FILE *fp1,*fp2;
fp1=fopen(a,"rb");
fread(bmp1,sizeof(struct bmp),1,fp1);
unsigned short tiaoseban,i,j;
if(((*bmp1).colorused==0)&&((*bmp1).bitsperpixel!=24))
tiaoseban=(unsigned short int)pow(2,(*bmp1).bitsperpixel);
else if(((*bmp1).colorused!=0)&&((*bmp1).bitsperpixel!=24))
tiaoseban=(*bmp1).colorused;
else if(((*bmp1).colorused==0)&&((*bmp1).bitsperpixel==24))
tiaoseban=0;
unsigned short row,col;
row=(*bmp1).imageheight;
col=(*bmp1).imagewidth;
unsigned char *xiehui;
xiehui=(unsigned char *)malloc(1);
fp2=fopen("linda1.bmp","wb");
rewind(fp1);
unsigned short count=0;
do{ fread(xiehui,1,1,fp1);
fwrite(xiehui,1,1,fp2);
count++;}while(count<=(54+4*tiaoseban));
unsigned char black=0,white=255;
for(j=0;j<3*col;j++)
fwrite(&white,1,1,fp2);
for(j=0;j<3;j++)
fwrite(&white,1,1,fp2);
unsigned char *head1;
head1=(*fp1).curp;
unsigned char *r[3];
r[0]=head1+1;
unsigned short moban[3][3];
unsigned short temp,temp1,temp2;
unsigned short w1[3][3]={{-1,0,1},{-2,0,2},{-1,0,1}};
unsigned short w2[3][3]={{1,2,1},{0,0,0},{-1,-2,-1}};
unsigned short jishu=0; count=0;
do{ temp=0;temp1=0;temp2=0;
r[1]=r[0]+3*col;r[2]=r[1]+3*col;
for(i=0;i<3;i++)
for(j=0;j<3;j++)
moban[i][j]=*(r[i]+3*j+2);
for(i=0;i<3;i++)
for(j=0;j<3;j++)
temp1+=moban[i][j]*w1[i][j];
for(i=0;i<3;i++)
for(j=0;j<3;j++)
temp2+=moban[i][j]*w2[i][j];
temp=abs(temp1)+abs(temp2);
if (temp>=120) temp=0;
else temp=255;
(unsigned char)temp;
fwrite(&temp,1,1,fp2);
fwrite(&temp,1,1,fp2);
fwrite(&temp,1,1,fp2);
count++;
if(count==col-2)
{ count=0;
for(j=0;j<6;j++)
fwrite(&white,1,1,fp2);}
jishu++;
if (jishu==col-2)
r[0]+=9;
else
r[0]+=3;
}while(r[0]<=head1+3*col*(row-2));
for(j=0;j<3*col;j++)
fwrite(&white,1,1,fp2);
for(j=0;j<3;j++)
fwrite(&white,1,1,fp2);
fclose(fp1);fclose(fp2);
}
struct bmp
{
}
这个结构体是bmp图像前54字节所代表的数据。
soble是对图像边缘处理的算法。
运行时head1=(*fp1).curp;中错误,错误是crup不是,struct_iobuf的成员变量
struct _iobuf
{
char *_ptr;
int _cnt;
char *_base;
int _flag;
int _flie;
int _charbuf;
int _bufsiz;
char *_bmpfname;
}
但是如果要把crup换成iobuf中的char类型的,程序正确没有什么语法错误,但是出来的dos界面后,
input the route :后输入路径后,但是不能运行,键盘不管输入什么都不可行。
我也不知道是哪个地方错的,还请各位高手能帮帮忙,先谢谢各位了