clc;close all;clear all;
%load('P.mat');
%load('T.mat');
[L0,I0]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\0\');
[L1,I1]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\1\');
[L2,I2]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\2\');
[L3,I3]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\3\');
[L4,I4]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\4\');
[L5,I5]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\5\');
[L6,I6]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\6\');
[L7,I7]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\7\');
[L8,I8]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\8\');
[L9,I9]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\9\');
[L10,I10]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\A\');
[L11,I11]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\B\');
[L12,I12]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\C\');
[L13,I13]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\D\');
[L14,I14]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\E\');
[L15,I15]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\F\');
[L16,I16]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\J\');
[L17,I17]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\H\');
[L18,I18]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\J\');
[L19,I19]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\K\');
[L20,I20]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\L\');
[L21,I21]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\M\');
[L22,I22]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\N\');
[L23,I23]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\P\');
[L24,I24]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\Q\');
[L25,I25]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\R\');
[L26,I26]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\S\');
[L27,I27]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\T\');
[L28,I28]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\U\');
[L29,I29]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\V\');
[L30,I30]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\W\');
[L31,I31]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\X\');
[L32,I32]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\Y\');
[L33,I33]=pretreatment('汽车车牌识别图像库\字符模板\font_ra\Z\');
P=[I0',I1',I2',I3',I4',I5',I6',I7',I8',I9',I10',I11',I12',I13',I14',I15',I16',I17',I18',I19',I20',I21',I22',I23',I24',I25',I26',I27',I28',I29',I30',I31',I32',I33'];
T1=eye(34,34);
T=[repmat(T1(:,1),1,L0),repmat(T1(:,2),1,L1),repmat(T1(:,3),1,L2),repmat(T1(:,4),1,L3),repmat(T1(:,5),1,L4)...
repmat(T1(:,6),1,L5),repmat(T1(:,7),1,L6),repmat(T1(:,8),1,L7),repmat(T1(:,9),1,L8),repmat(T1(:,10),1,L9)...
repmat(T1(:,11),1,L10),repmat(T1(:,12),1,L11),repmat(T1(:,13),1,L12),repmat(T1(:,14),1,L13),repmat(T1(:,15),1,L14)...
repmat(T1(:,16),1,L15),repmat(T1(:,17),1,L16),repmat(T1(:,18),1,L17),repmat(T1(:,19),1,L18),repmat(T1(:,20),1,L19)...
repmat(T1(:,21),1,L20),repmat(T1(:,22),1,L21),repmat(T1(:,23),1,L22),repmat(T1(:,24),1,L23),repmat(T1(:,25),1,L24)...
repmat(T1(:,26),1,L25),repmat(T1(:,27),1,L26),repmat(T1(:,28),1,L27),repmat(T1(:,29),1,L28),repmat(T1(:,30),1,L29)...
repmat(T1(:,31),1,L30),repmat(T1(:,32),1,L31),repmat(T1(:,33),1,L32),repmat(T1(:,34),1,L33)];
net=newff(minmax(P),[1000,200,34],{'logsig','logsig','logsig'},'trainrp');%1000 100 2000,300minmax()求矩阵每一行向量的最大值和最小值
%函数newff建立一个可训练的前馈网络。这需要4个输入参数。
%第一个参数是一个Rx2的矩阵以定义R个输入向量的最小值和最大值;
%第二个参数是一个设定每层神经元个数的数组;
%第三个参数是包含每层用到的传递函数名称的细胞数组;
%最后一个参数是用到的训练函数的名称。
net.inputWeights{1,1}.initFcn='randnr';
net.inputWeights{2,1}.initFcn='randnr';
net.trainparam.epochs=8000;
net.trainparam.show=50;
net.trainparam.goal=0.001;%0.0000000001;
net=init(net);%初始化权重和偏置的工作用命令init来实现。这个函数接收网络对象并初始化权重和偏置后返回网络对象。
[net,tr]=train(net,P,T);
i=imread('car1.jpg');
dw=location(i);%车牌定位,
[PIN0,PIN1,PIN2,PIN3,PIN4,PIN5,PIN6]=stringsplit(dw);%字符分割,见上篇文章
PIN0=pretreatment2(PIN0);
PIN1=pretreatment2(PIN1);
PIN2=pretreatment2(PIN2);
PIN3=pretreatment2(PIN3);
PIN4=pretreatment2(PIN4);
PIN5=pretreatment2(PIN5);
PIN6=pretreatment2(PIN6);
P0=[PIN0',PIN1',PIN2',PIN3',PIN4',PIN5',PIN6'];
for i=2:7
T0=sim(net,P0(:,i));%T0为P0(:,i)输入神经网络得到的输出,T0为34x1的列向量
T1=compet(T0);% compet是神经网络的竞争传递函数,用于指出矩阵中每列的最大值。对应最大值的行的值为1,其他行的值都为0
d=find(T1==1)-1;
if(d==10)
str='A';
elseif(d==11)
str='B';
elseif(d==12)
str='C';
elseif(d==13)
str='D';
elseif(d==14)
str='E';
elseif(d==15)
str='F';
elseif(d==16)
str='G';
elseif(d==17)
str='H';
elseif(d==18)
str='J';
elseif(d==19)
str='K';
elseif(d==20)
str='L';
elseif(d==21)
str='M';
elseif(d==22)
str='N';
elseif(d==23)
str='P';
elseif(d==24)
str='Q';
elseif(d==25)
str='R';
elseif(d==26)
str='S';
elseif(d==27)
str='T';
elseif(d==28)
str='U';
elseif(d==29)
str='V';
elseif(d==30)
str='W';
elseif(d==31)
str='X';
elseif(d==32)
str='Y';
elseif(d==33)
str='Z';
else
str=num2str(d);
end
switch i
case 2
str1=str;
case 3
str2=str;
case 4
str3=str;
case 5
str4=str;
case 6
str5=str;
otherwise
str6=str;
end
end
s=strcat('沪',str1,str2,str3,str4,str5,str6);
figure();
imshow(dw),title(s);