图像处理-----取轮廓
//取轮廓// /***********************************************************/ unsigned char* Outline(GPtr globals,unsigned char *Gray) { unsigned char* wn=NULL; unsigned char* n=NULL; unsigned char* en=NULL; unsigned char* w=NULL; unsigned char* e=NULL; unsigned char* ws=NULL; unsigned char* s=NULL; unsigned char* es=NULL; static unsigned char* Gray2=NULL; //unsigned char* p=NULL; int32 filterSize = gStuff->imageSize.v*gStuff->imageSize.h; Gray2=(unsigned char *)malloc(filterSize); memcpy(Gray2,Gray,filterSize);
int i=0,j=0,sum=0;
for(i=0;i<gStuff->imageSize.v;i++) //将所有非白的像素变为纯黑 { for(j=0;j<gStuff->imageSize.h;j++) { if(*(Gray+(gStuff->imageSize.h*i)+j)!=255) { *(Gray2+gStuff->imageSize.h*i+j)=(BYTE)0; *(Gray+(gStuff->imageSize.h*i)+j)=(BYTE)0; } } } for(i=1;i<gStuff->imageSize.v-1;i++) { for(j=1;j<gStuff->imageSize.h-1;j++) { sum = 0; if(*(Gray+(gStuff->imageSize.h*i)+j)==0) { w=Gray+(gStuff->imageSize.h*i)+j-1; e=Gray+(gStuff->imageSize.h*i)+j+1; wn=Gray+(gStuff->imageSize.h*i)+j-gStuff->imageSize.h-1; n=Gray+(gStuff->imageSize.h*i)+j-gStuff->imageSize.h; en=Gray+(gStuff->imageSize.h*i)+j-gStuff->imageSize.h+1; ws=Gray+(gStuff->imageSize.h*i)+j+gStuff->imageSize.h-1; s=Gray+(gStuff->imageSize.h*i)+j+gStuff->imageSize.h; es=Gray+(gStuff->imageSize.h*i)+j+gStuff->imageSize.h+1; sum=(*w)+(*e)+*(wn)+(*n)+(*en)+(*ws)+(*s)+(*es); if(sum==0) { *(Gray2+gStuff->imageSize.h*i+j)=(BYTE)255;
} } } } memcpy(Gray, Gray2, filterSize);
return Gray; //if( Gray2!= NULL ) free( Gray2 ); }