# 哪位高手能给小弟提供些车牌识别的相关资料

944136 2003-07-22 11:15:19

944136@sina.com
...全文
91 11 打赏 收藏 举报

11 条回复

greenbugs 2003-10-10
• 打赏
• 举报

xl44(妩清风)老兄，注释可否再详细一点

E_mail:greenbugs@163.com
944136 2003-09-04
• 打赏
• 举报

xl44 2003-09-03
• 打赏
• 举报

xl44 2003-09-03
• 打赏
• 举报

//BP.h bp算法
#include "StdAfx.h"
#include <math.h>
#include <stdlib.h>

double Sigmoid(double x)

{
double f=(double)(1.0/(1.0+exp(-x)));
return(f);
}

double Sigmoid2(double x)
{
double f=(double)(exp(-x)/((1+exp(-x))*(1+exp(-x))));
return f;
}
void change(UINT t,double* T,UINT m)
{
UINT f=t;
for(UINT i=0; i < 5;i++){
double l=(double)(f%2);
T[m*5+i]=fabs(l - 0.1);
f = f/2;
}
}

UINT BPModel(UINT width,UINT height,LPSTR g,UINT f)
{
//读取权值
char pFileName[256];
GetModuleFileName( NULL, pFileName, 255 );
CString csFullPath(pFileName);
CString fn;
int nPos = csFullPath.ReverseFind( _T('\\') );
if( nPos >= 0 )
fn=csFullPath.Left( nPos );
switch (f){
case 0:
fn +="\\BPcn.xl44";break;
case 1:
fn +="\\BPen.xl44";break;
case 2:
fn +="\\BPen2.xl44";break;
default:
fn +="\\BPnum.xl44";break;
}
CFile fp;
if(!fp.Open(fn, CFile::modeReadWrite | CFile::shareExclusive | CFile::typeBinary)) {
return 44;
}
double Wji[40][121];
double Wkj[5][40];
//取得输入
UINT w_8=w_8(width);
double train[121];
for(UINT y=0; y < 11;y++){
for(UINT x=0; x < 11;x++){
UINT num=0;
if(g[3*y*w_8 + 3*x] == (BYTE)0x00)
num++;
if(g[3*y*w_8 + 3*x + 1] == (BYTE)0x00)
num++;
if(g[3*y*w_8 + 3*x + 2] == (BYTE)0x00)
num++;
if(g[(3*y + 1)*w_8 + 3*x] == (BYTE)0x00)
num++;
if(g[(3*y + 1)*w_8 + 3*x + 1] == (BYTE)0x00)
num++;
if(g[(3*y + 1)*w_8 + 3*x + 2] == (BYTE)0x00)
num++;
if(g[(3*y + 2)*w_8 + 3*x] == (BYTE)0x00)
num++;
if(g[(3*y + 2)*w_8 + 3*x + 1] == (BYTE)0x00)
num++;
if(g[(3*y + 2)*w_8 + 3*x + 2] == (BYTE)0x00)
num++;
train[y*11 + x] = (double)(num/9);
}
}
double Ij[40];
double Oj[40];
double Ik[5];
double Ok[5];
UINT ci=0;
UINT cj=0;
UINT ck=0;

for(cj=0;cj < 40;cj++){
Ij[cj]=0.0;
Oj[cj]=0.0;
}
for(ck=0;ck < 5;ck++){
Ik[ck]=0.0;
Ok[ck]=0.0;
}

for(cj = 0;cj < 40;cj++){
for(ci =0;ci < 121;ci++){
Ij[cj] +=Wji[cj][ci]*train[ci];
}

Oj[cj] = Sigmoid(Ij[cj]);
}

for(ck = 0;ck < 5;ck++){
for(cj = 0;cj < 40;cj++){
Ik[ck] += Wkj[ck][cj] * Oj[cj];
}
Ok[ck]=Sigmoid(Ik[ck]);
}

UINT tem[5];
for(ck = 0;ck < 5;ck++){
if(fabs(Ok[ck] - 0.0) < 0.5)
tem[ck]=0;
else
tem[ck]=1;
}

fp.Close();
UINT cn=tem[0] + tem[1]*2 +tem[2]*4 + tem[3]*8 + tem[4]*16;
return cn;
}

UINT train()
{
//打开文件,字符存为34*34像素，另加2位字符编号
char pFileName[256];
GetModuleFileName( NULL, pFileName, 255 );
CString csFullPath(pFileName);
CString fn;
int nPos = csFullPath.ReverseFind( _T('\\') );
if( nPos >= 0 )
fn=csFullPath.Left( nPos );
fn+="\\num.xl44";
CFile fp;
if(!fp.Open(fn, CFile::modeReadWrite | CFile::shareExclusive | CFile::typeText)) {
return 44;
}
double Wji[40][121];//权值，隐节点40 ，输入11*11
double Wkj[5][40];//权值，输出5
//double level1[j][i];
//double level2[k][j];
double Ij[40];//输入
double Oj[40];//输出
double Ik[5];
double Ok[5];
double n=(double)0.6;//学习率
UINT flag=0;
UINT ci=0;//循环变量
UINT cj=0;
UINT ck=0;
double train[121*24];//样本数据
double Target[5*24];//训练目标，24个样本
UINT target;//训练目标
char lib[34*34];//字符
char tar[2];//字符编号

for(UINT m = 0;m < 24;m++){
//为提高速度,取特征11X11
for(UINT y = 0;y < 11;y++){
for(UINT x = 0;x < 11;x++){
UINT num = 0;
if(lib[3*y*34 + 3*x] == '1')
num++;
if(lib[3*y*34 + 3*x + 1] == '1')
num++;
if(lib[3*y*34 + 3*x + 2] == '1')
num++;
if(lib[(3*y + 1)*34 + 3*x] == '1')
num++;
if(lib[(3*y + 1)*34 + 3*x + 1] == '1')
num++;
if(lib[(3*y + 1)*34 + 3*x + 2] == '1')
num++;
if(lib[(3*y + 2)*34 + 3*x] == '1')
num++;
if(lib[(3*y + 2)*34 + 3*x + 1] == '1')
num++;
if(lib[(3*y + 2)*34 + 3*x + 2] == '1')
num++;
train[m*121 + y*11 + x] = (double)((double)(num)/9);

}
}
target=((UINT)tar[0] - 48)*10 + ((UINT)tar[1] - 48);
change(target,Target,m);
}
fp.Close();
//赋初值

double tem=0.0;
for(cj=0;cj < 40;cj++){
for(ci=0;ci < 121;ci++){
tem=(double)((rand()%100)/100.0);
if(tem > 0.5)
tem-=1.0;
Wji[cj][ci]=tem;
}
}
for(ck=0;ck < 5;ck++){
for(cj=0;cj < 40;cj++){
tem=(double)((rand()%100)/100.0);
if(tem > 0.5)
tem-=1.0;
Wkj[ck][cj]=tem;
}
}

//开始训练
for(UINT num = 0;num < 50000;num++){
//样本24个
for(UINT m = 0;m < 24;m++){

for(cj=0;cj < 40;cj++){
Ij[cj]=0.0;
Oj[cj]=0.0;
}
for(ck=0;ck < 5;ck++){
Ik[ck]=0.0;
Ok[ck]=0.0;
}
for(cj = 0;cj < 40;cj++){
for(ci =0;ci < 121;ci++){
Ij[cj] +=Wji[cj][ci]*train[m*121+ci];
}

Oj[cj] = Sigmoid(Ij[cj]);CString ss;
}

for(ck = 0;ck < 5;ck++){
for(cj = 0;cj < 40;cj++){
Ik[ck] += Wkj[ck][cj] * Oj[cj];
}
Ok[ck]=Sigmoid(Ik[ck]);

}

double s1=0.0;
for(cj=0; cj < 40;cj++){
for(ci=0; ci < 121;ci++){
for(ck=0; ck < 5;ck++){
s1 += (Ok[ck] - Target[5*m+ck])*Ok[ck]*(1-Ok[ck])*Wkj[ck][cj];
}
Wji[cj][ci] += n*s1*Oj[cj]*(1-Oj[cj])*train[m*121+ci];

}
}

for(ck=0;ck < 5;ck++){
for(cj=0; cj < 40;cj++){
Wkj[ck][cj] += n*(Target[5*m+ck]-Ok[ck])*Ok[ck]*(1-Ok[ck])*Oj[cj];

}
}
UINT pp=0;

for(ck=0;ck < 5;ck++){
if(fabs(Ok[ck]-Target[5*m+ck]) < 0.3)
pp++;
}

if(pp == 5)
flag++;

}
if(flag == 24){
if(flag == 24){
char pFileName2[256];
GetModuleFileName( NULL, pFileName2, 255 );
CString csFullPath(pFileName2);
CString fn2;
int nPos = csFullPath.ReverseFind( _T('\\') );
if( nPos >= 0 )
fn2=csFullPath.Left( nPos );
fn2 +="\\BPnum.xl44";
CFile fp2;
if(!fp2.Open(fn2, CFile::modeReadWrite | CFile::shareExclusive | CFile::typeBinary)) {
return 44;
}
fp2.SeekToEnd();
fp2.Write(Wji,121*40*8);
fp2.SeekToEnd();
fp2.Write(Wkj,5*40*8);
fp2.Close();
}
//if(num == 99999){
/*char pFileName0[256];
GetModuleFileName( NULL, pFileName0, 255 );
CString csFullPath(pFileName0);
CString fn0;
int nPos0 = csFullPath.ReverseFind( _T('\\') );
if( nPos0 >= 0 )
fn0=csFullPath.Left( nPos0 );
fn0 +="\\BP2.xl44";
CFile fp0;
if(!fp0.Open(fn0, CFile::modeCreate | CFile::modeReadWrite | CFile::shareExclusive | CFile::typeText))
return 44;
fp0.SeekToEnd();
fp0.Write(Wji,121*20*4);
fp0.SeekToEnd();
fp0.Write(Wkj,5*20*4);
fp0.Close();*/
//return 2;
//}
return num;
}
/*for(j=0;j < 5;j++){
for(i=0;i < 2;i++){
level11[j][i]=level1[j][i];
}
level22[j]=level2[j];
}*/
flag=0;
}
return 0;
}

asleepingfish 2003-09-03
• 打赏
• 举报

xl44(妩清风)兄好，能否提供车牌定位方面的资料和源码？当然有识别方面的更好。
944136 2003-08-22
• 打赏
• 举报

xl44 2003-08-02
• 打赏
• 举报

xl44 2003-08-02
• 打赏
• 举报

MXHCXY 2003-07-23
• 打赏
• 举报

ljranby 2003-07-23
• 打赏
• 举报

BlueSky2008 2003-07-23
• 打赏
• 举报

4372

2003-07-22 11:15