| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 928 人关注过本帖
标题:[求助]用C对图像处理
只看楼主 加入收藏
gazihu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-23
收藏
 问题点数:0 回复次数:6 
[求助]用C对图像处理

这个是一个图像处理的源程序,有错误不能运行,我是一个新手,由于作毕业设计,才学习的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 :后输入路径后,但是不能运行,键盘不管输入什么都不可行。
我也不知道是哪个地方错的,还请各位高手能帮帮忙,先谢谢各位了

搜索更多相关主题的帖子: 图像处理 
2006-05-28 21:32
–★–
Rank: 3Rank: 3
等 级:新手上路
威 望:6
帖 子:1512
专家分:0
注 册:2006-5-1
收藏
得分:0 
“如果要把crup换成iobuf中的char类型的”
这句话不大好理解。因为与文件指针相关的全套定义是由编译系统预先规定好的,程序员只能使用不能作任何改动

落霞与孤鹜齐飞,秋水共长天一色! 心有多大,路有多宽。三教九流,鸡鸣狗盗。兼收并蓄,海纳百川。
2006-05-29 03:18
gazihu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-23
收藏
得分:0 

编译时提示:crup不是iobuf中的成员变量
iobuf中不时有很多成员变量吗?如果把crup换成iobuf中的一个,程序没有什么语法错误,但是就是不能运行,还请各位哥哥给改下,错误还是和我上面说的一样。

2006-05-29 12:07
gazihu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-23
收藏
得分:0 
还请各位看看是不是程序里面的函数,或者其他的语句有没有错误。
2006-05-29 12:08
sgfxj
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-5-29
收藏
得分:0 
我写了一个可以用但是是16色的
struct bmphead
{
unsigned char b;
unsigned char m;
unsigned long bfsize;
unsigned int bfresterved1;
unsigned int bfresterved2;
unsigned long bfoffbits;
unsigned long bitsize;
unsigned long bmpwidth;
unsigned long bmpheight;
unsigned int bmpplanes;
unsigned int bmpcount;
unsigned long bmpcompression;
unsigned long bmpimgsize;
unsigned long bmpxpeispermeter;
unsigned long bmpypeispermeter;
unsigned long bmpcirused;
unsigned long bmpimportant;
};

/*----------------------------------------------------------------------------------------------*/

struct ColorIndex
{
unsigned char Blue;
unsigned char Green;
unsigned char Red;
unsigned char Reserved;
};

int pageno;

/*==============================================================================================*/

void SetPlate(int ColorIndex,char Red,char Green,char Blue)
{
outportb(0x3c8,ColorIndex);
outportb(0x3c9,Red);
outportb(0x3c9,Green);
outportb(0x3c9,Blue);
}
/*----------------------------------------------------------------------------------------------*/


showbmp(int x,int y,char *filename)/*显示函数*/
{
FILE *fp;
char c,temp1,temp2;
struct bmphead bmp;
struct ColorIndex index[16];
register int m;
int n;
register unsigned long i=0,j=0;
/* struct palettetype oldq; */
struct palettetype *sq;
/* getpalette(&oldq); */
if((fp=fopen(filename,"rb"))==NULL)
{
printf("can't open file!");
}
else
{
fread(&bmp,sizeof(struct bmphead),1,fp);
fread(index,sizeof(struct ColorIndex),16,fp);
}

if(bmp.bmpwidth%32==00)
{
n=bmp.bmpwidth/2;
}
else
{
n=4+bmp.bmpwidth/2-(bmp.bmpwidth/2)%4;
}
m=9;
SetPlate(57,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(58,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(59,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(60,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(61,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(62,index[m].Red,index[m].Green,index[m].Blue);
m++;
SetPlate(63,index[m].Red,index[m].Green,index[m].Blue);
fseek(fp, bmp.bfoffbits,0);
for(m=0; m<bmp.bmpheight; m++)
{
j=0;
for(i=0;i<n;i++)
{
c=fgetc(fp);
if(j<bmp.bmpwidth)
{
temp1=(c&0xF0)>>4;
temp2=c&0x0F;
if(temp1 != 0)
{
putpixel(x+j,320+y-m,temp1);
}
j++;
if(temp2 != 0)
{
putpixel(x+j,320+y-m,temp2);
}
j++;
}
}
}
fclose(fp);
/* setallpalette(&oldq); */
}
你看看 但bmp文件不能大于64K

2006-05-30 10:30
sgfxj
Rank: 1
等 级:新手上路
帖 子:26
专家分:0
注 册:2006-5-29
收藏
得分:0 

对了是TC的 你看看
我在我的程序里是正确的,要一个大一点的,你就只好拼图了

2006-05-30 10:31
gazihu
Rank: 1
等 级:新手上路
帖 子:5
专家分:0
注 册:2006-5-23
收藏
得分:0 
好的,谢谢啊,我运行看看
2006-05-30 11:46
快速回复:[求助]用C对图像处理
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.014819 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved