基于matlab车牌的定位与分割识别程序.docx
- 文档编号:5055227
- 上传时间:2022-12-12
- 格式:DOCX
- 页数:14
- 大小:544.83KB
基于matlab车牌的定位与分割识别程序.docx
《基于matlab车牌的定位与分割识别程序.docx》由会员分享,可在线阅读,更多相关《基于matlab车牌的定位与分割识别程序.docx(14页珍藏版)》请在冰豆网上搜索。
基于matlab车牌的定位与分割识别程序
》
基于Matlab的车牌定位与分割
经典算法
I=imread('');%读取图像
figure();subplot(3,2,1),imshow(I),title('原始图像');
I1=rgb2gray(I);%转化为灰度图像
subplot(3,2,2),imshow(I1),title('灰度图像');
(
I2=edge(I1,'robert',,'both');%采用robert算子进行边缘检测
subplot(3,2,3),imshow(I2),title('边缘检测后图像');
se=[1;1;1];%线型结构元素
I3=imerode(I2,se);%腐蚀图像
subplot(3,2,4),imshow(I3),title('腐蚀后边缘图像');
se=strel('rectangle',[25,25]);矩形结构元素
]
I4=imclose(I3,se);%图像聚类、填充图像
subplot(3,2,5),imshow(I4),title('填充后图像');
I5=bwareaopen(I4,2000);%去除聚团灰度值小于2000的部分
subplot(3,2,6),imshow(I5),title('形态滤波后图像');
[y,x,z]=size(I5);
I6=double(I5);
Y1=zeros(y,1);
fori=1:
y
forj=1:
x
if(I6(i,j,1)==1)
Y1(i,1)=Y1(i,1)+1;
end
end
end
'
[tempMaxY]=max(Y1);
figure();
subplot(3,2,1),plot(0:
y-1,Y1),title('行方向像素点灰度值累计和'),xlabel('行值'),ylabel('像素');
%求的车牌的行起始位置和终止位置
PY1=MaxY;
while((Y1(PY1,1)>=50)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while((Y1(PY2,1)>=50)&&(PY2 PY2=PY2+1; end IY=I(PY1: PY2,: : ); X1=zeros(1,x); forj=1: x , fori=PY1: PY2 if(I6(i,j,1)==1) X1(1,j)=X1(1,j)+1; end endend subplot(3,2,2),plot(0: x-1,X1),title('列方向像素点灰度值累计和'),xlabel('列值'),ylabel('像数'); %求的车牌的列起始位置和终止位置PX1=1; { while((X1(1,PX1)<3)&&(PX1 PX1=PX1+1; end PX2=x; while((X1(1,PX2)<3)&&(PX2>PX1)) PX2=PX2-1; end PX1=PX1-1; , PX2=PX2+1; %分割出车牌图像% dw=I(PY1: PY2,PX1: PX2,: ); subplot(3,2,3),imshow(dw),title('定位剪切后的彩色车牌图像') 车牌字符分割 确定车牌位置后下一步的任务就是进行字符切分分离出车牌号码的全部字符图像。 ifisrgb(I) 】 I1=rgb2gray(I);%将RGB图像转化为灰度图像 elseI1=I;end g_max=double(max(max(I1))); g_min=double(min(min(I1))); T=round(g_max-(g_max-g_min)/3);%T为二值化的阈值 [m,n]=size(I1);%d: 二值图像 %h=graythresh(I1); I1=im2bw(I1,T/256); ) subplot(3,2,4); imshow(I1),title('二值化车牌图像'); I2=bwareaopen(I1,20); subplot(3,2,5); imshow(I2),title('形态学滤波后的二值化图像'); ? [y1,x1,z1]=size(I2); I3=double(I2); TT=1; %%%%%%%去除图像顶端和底端的不感兴趣区域%%%%% Y1=zeros(y1,1); fori=1: y1 forj=1: x1 if(I3(i,j,1)==1) ( Y1(i,1)=Y1(i,1)+1; end end end Py1=1; Py0=1; while((Y1(Py0,1)<20)&&(Py0 Py0=Py0+1; … end Py1=Py0; while((Y1(Py1,1)>=20)&&(Py1 Py1=Py1+1; end I2=I2(Py0: Py1,: : ); subplot(3,2,6); imshow(I2),title('目标车牌区域'); ` %分割字符按行积累量% X1=zeros(1,x1); forj=1: x1 fori=1: y1 if(I3(i,j,1)==1) X1(1,j)=X1(1,j)+1; end } end end figure(5); plot(0: x1-1,X1),title('列方向像素点灰度值累计和'),xlabel('列值'),ylabel('累计像素量'); Px0=1; Px1=1; %分割字符 ` fori=1: 7 while((X1(1,Px0)<3)&&(Px0 Px0=Px0+1; end Px1=Px0; while(((X1(1,Px1)>=3)&&(Px1 Px1=Px1+1; end | Z=I2(: Px0: Px1,: ); switchstrcat('Z',num2str(i)) case'Z1' PIN0=Z; case'Z2' PIN1=Z; case'Z3' PIN2=Z; ? case'Z4' PIN3=Z; case'Z5' PIN4=Z; case'Z6' PIN5=Z; otherwise PIN6=Z; ? end figure(3); subplot(1,7,i); imshow(Z); Px0=Px1; End functioninpt=pretreatment(I) [ %YUCHULISummaryofthisfunctiongoeshere %Detailedexplanationgoeshere ifisrgb(I) I1=rgb2gray(I); else I1=I; end I1=imresize(I1,[5020]);%将图片统一划为50*20大小 # I1=im2bw(I1,; [m,n]=size(I1); inpt=zeros(1,m*n); %将图像按列转换成一个行向量 forj=1: n fori=1: m inpt(1,m*(j-1)+i)=I1(i,j); end / end %神经网络进行识别。 closeall; clearall; %%%%归一化训练样本%%%%%% I0=pretreatment(imread('')); I1=pretreatment(imread('')); ~ I2=pretreatment(imread('')); I3=pretreatment(imread('')); I4=pretreatment(imread('')); I5=pretreatment(imread('')); I6=pretreatment(imread('')); I7=pretreatment(imread('')); I8=pretreatment(imread('')); I9=pretreatment(imread('')); ^ I10=pretreatment(imread('')); I11=pretreatment(imread('')); I12=pretreatment(imread('')); I13=pretreatment(imread('')); I14=pretreatment(imread('')); I15=pretreatment(imread('')); I16=pretreatment(imread('')); I17=pretreatment(imread('')); : P=[I0',I1',I2',I3',I4',I5',I6',I7',I8',I9',I10',I11',I12',I13',I14',I15',I16',I17']; %输出样本%%% T=eye(18,18); %%bp神经网络参数设置 net=newff(minmax(P),[1000,32,18],{'logsig','logsig','logsig'},'trainrp'); {1,1}.initFcn='randnr'; {2,1}.initFcn='randnr'; 训练样本%%%% 《 [net,tr]=train(net,P,T); %%%%%%%测试%%%%%%%%% %I=imread(''); I=imread(''); dw=location(I);%车牌定位 [PIN0,PIN1,PIN2,PIN3,PIN4,PIN5,PIN6]=StringSplit(dw);%字符分割及处理 %%%%%%%%%%%测试字符,得到识别数值%%%% & PIN0=pretreatment(PIN0); PIN1=pretreatment(PIN1); PIN2=pretreatment(PIN2); PIN3=pretreatment(PIN3); PIN4=pretreatment(PIN4); PIN5=pretreatment(PIN5); PIN6=pretreatment(PIN6); P0=[PIN0',PIN1',PIN2',PIN3',PIN4',PIN5',PIN6']; < fori=2: 7 T0=sim(net,P0(: i)); T1=compet(T0); d=find(T1==1)-1 if(d==10) str='A'; elseif(d==11) str='C'; < elseif(d==12) str='G'; elseif(d==13) str='L'; elseif(d==14) str='M'; elseif(d==15) str='R'; elseif(d==16) str='H'; elseif(d==17) str='N'; else str=num2str(d); end switchi case2 str1=str; case3 str2=str; case4 str3=str; case5 str4=str; case6 str5=str; otherwise str6=str; end end %显示定位后的分割出的车牌彩图,% %%%%%%识别结果以标题形式显示在图上%%% s=strcat('渝',str1,str2,str3,str4,str5,str6); figure(); imshow(dw),title(s); 非诚勿扰欢迎下载
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 基于 matlab 车牌 定位 分割 识别 程序