车牌识别源代码.docVIP

  • 14
  • 0
  • 约 22页
  • 2017-01-09 发布于贵州
  • 举报
车牌识别源代码车牌识别源代码

//--------------------------------------------------------------------------- #include vcl.h #include math.h #pragma hdrstop #include Unit1.h //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma resource *.dfm TForm1 *Form1; Graphics::TBitmap *bitmap1; //定义bitmap1和bitmap2是TBitmap Graphics::TBitmap *bitmap2; Graphics::TBitmap *bitmap3; struct COLOUR //定义颜色结构体,有r,g,b(红,绿,蓝)三分量 { Byte r; Byte g; Byte b; }; COLOUR **col; //------------------------------------------------------------------------------ //彩色图象转灰度图象, col是原图象彩色象素数组,w是图象宽度,h是图象高度 Byte **ColorToGray(COLOUR **col,int w,int h) { int i,j,k; double y; Byte **result=(Byte**)malloc((unsigned) h*sizeof(Byte*)); //开辟动态数组result,存放处理结果 for ( i=0;ih;i++ ) result[i]=new Byte[w]; for ( i=0;ih;i++ ) //遍历图象 for ( j=0;jw;j++ ) { y=0.3*col[i][j].r+0.59*col[i][j].g+0.11*col[i][j].b; //灰度合成 result[i][j]=(Byte)y; } return result; //返回处理结果 } //------------------------------------------------------------------------------ //灰度图像均衡化,Image是画均衡化直方图的位置,w是原图像宽度,h是原图像高度 Byte **Equalize(TImage *Image,int w,int h) { int i,j,k; long sum=0; Byte *ptr,*newscan; double H; //用来计算某灰度值在灰度图中垂直方向的长度 long hgray[256]; //定义灰度值的数组 int tt[256]; //新直方图灰度级的数组 long tgray[256];//新直方图各灰度级像素的数组 Byte **result=(Byte**)malloc((unsigned) h*sizeof(Byte*)); for ( i=0;ih;i++ ) result[i]=new Byte[w]; for (i=0;i256;i++) //数组初始化 { hgray[i]=0; tgray[i]=0; } for ( i=0;ih;i++ ) //统计各灰度值像素数 { ptr=static_castByte*(bitmap1-ScanLine[i]); for( j=0;jw;j++ ) hgray[ptr[j*3]]++; } //ShowMessage(n); for(i=0;i256;i++) { sum+=hgray[i]; tt[i]=sum; } for(i=0;i256;i++) tt[i]=(int)(255*tt[i]/sum+0.5); for(i=0;i256;i++) tgray[tt[i]]+=hgray[i]; for (k=0;k256;k++) { H=int(tgray[k]*5000/(h*w)); Image-Canvas-MoveTo(k,Image-Height); Image-Canvas-LineTo(k,Ima

文档评论(0)

1亿VIP精品文档

相关文档