车牌识别--模板库C语言数组的制作

阅读: 评论:0

车牌识别--模板库C语⾔数组的制作
在车牌识别中,字符模板匹配的模板库是很⼤的。
包括 10个阿拉伯数字以及26个英⽂字母还有⼏⼗个汉字,每个库都是⼀张⼩图⽚,加载起来也⽐较繁琐。
后⾯还有可能为提⾼识别增加额外的模板库。
之前的处理中,是把这些库的图⽚⽂件放到⼀个⽂件夹中,程序启动后,再⼀个⼀个读取,这样⽂件的数量就⽐较多。
原图⽚模板如下:
程序稳定后,我们就不要这些字符模板库了,可以⽤数组的形式代替,就是把这些⽂件数据保存⼀个c语⾔数组⾥⾯,直接编译到程序中,运⾏程序的时候直接使⽤,不⽤⼀个⼀个加载,再去匹配。
强电井⽬前使⽤的moan库图⽚是20x40的8bit灰度BMP格式⽂件,其信息头长度54+256x4=1078,直接略过信息头和调⾊板获取图⽚数据信息
模板制作的c代码如下:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define CHAR_NUM 66
#define CHAR_WIDHT 20
#define CHAR_HEIGHT 40
char template[CHAR_NUM][CHAR_WIDHT * CHAR_HEIGHT];
int readstr(FILE *inFIL, unsigned char *srcBmp)
{
int width,height, headlength;
int i,j,line8;
unsigned char *temp;
unsigned char temp1;
width = CHAR_WIDHT;
height = CHAR_HEIGHT;
headlength = 1078;//54 + 256 * 4;
line8=(width*8+31)/32*4;
temp=(char *)malloc(height * line8 * sizeof(char));
fseek(inFIL, headlength, SEEK_SET);
fread(temp, line8 * height,1, inFIL);
if(temp==NULL)
{
printf("\n读取失败\n");
return -1;
}
for(i=0;i<height;i++)
{
for(j=0;j<width;j++)
{
一氧化氮 笑气
temp1 = temp[i*line8+j];
if(temp1 > 150)
temp1 = 255;
else
temp1 = 0;
srcBmp[(height-i-1)*width+j]= temp1;// (temp1 > 150 ? 255:0);//(byte)(0.299*bitmap[temp[i*line8+j]].bitb+0.578*bitmap[temp[i*line8+j]].bitg+0.114*bitmap[temp[i*l  }
}
free(temp);
temp=NULL;
return 0;
}
int readtemplate(char *path, char src[CHAR_NUM][CHAR_WIDHT * CHAR_HEIGHT])
{
FILE *f[72];
int i;
char str[100];
for(i = 0; i <= CHAR_NUM; i++)
{
sprintf(str, "%s%d.bmp", path, i);
f[i]=fopen(str,"rb");
if(f[i]==NULL)
{
printf("can't open patch:%s\n", str);
return -1;
}
readstr(f[i], src[i]);
fclose(f[i]);
}
return 0;
}
int main()
{
int i, j;
FILE *f;
unsigned char p;
叶轮给粉机char buf[5];
f = fopen("Template.h", "wb");欧米伽3榨油机
if(f == NULL)
{
printf("Can't open the file\n");
return -1;
}
if(readtemplate(".\\test\\moban\\", template) != 0)
{
printf("readtemplate error\n");
return -1;
}
for(i = 0; i < CHAR_NUM; i++)
for(j = 0; j < CHAR_WIDHT * CHAR_HEIGHT; j ++)  {
if((j%800 == 0))
fwrite("\n",strlen("\n"),1,f);
p = template[i][j];
sprintf(buf,"%4d,", p);
fwrite(buf,strlen(buf),1,f);
}
fclose(f);
return 0;
}
制作后的数组如下(变量名⾃⾏添加)
之前算法是⼀个⼀个读取,然后重新复制⼀遍
void readmoban(char *path,struct BMP_Plate *img2)
{
FILE *f[72];
int i;
char str[80];
for(i=0;i<=66;i++)
{
sprintf(str,"%s%d.bmp", path, i);
f[i]=fopen(str,"rb");
if(f[i]==NULL)
{
printf("can't open moban:%d,%s\n", i, str);
exit(-1);
}
readstr(f[i],img2->strc[i]);
displayGray(img2->strc[i],20,40,0,0);
fclose(f[i]);
}
烟雾过滤器}
现在,只需要,指定数组指针,不⽤加载图⽚,也不⽤复制
int readtemplate(char *moban,struct BMP_Plate *img2)
{
int i;
#if 0
for(i = 0; i <= CHAR_NUM; i++)
{
memcpy(img2->strc[i],&moban[i * TEMPPLATE_SIZE], TEMPPLATE_SIZE);
}
#else
for(i = 0; i <= CHAR_NUM; i++)
{
img2->strc[i] = &moban[i * TEMPPLATE_SIZE];
}
分凝器
#endif
return 0;
}
不⽤再重新复制数据了,优化了代码,节省了时间(其实节省的也不是很多^^ )。

本文发布于:2023-06-01 10:45:16,感谢您对本站的认可!

本文链接:https://patent.en369.cn/patent/2/121535.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:模板   数组   程序   数据   识别   信息   件夹
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2022 Comsenz Inc.Powered by © 369专利查询检索平台 豫ICP备2021025688号-20 网站地图