基于模板匹配的车牌识别及matlab实现(7)

2019-08-31 14:10

d(:,[1:wide])=0; d=qiege(d); else

temp=qiege(imcrop(d,[1 1 wide m])); [m,n]=size(temp); all=sum(sum(temp));

two_thirds=sum(sum(temp([round(m/3):2*round(m/3)],:))); if two_thirds/all>y2

flag=1;word1=temp; % WORD 1 end

d(:,[1:wide])=0;d=qiege(d); end

end% 分割出第二个字符

[word2,d]=getword(d);% 分割出第三个字符 [word3,d]=getword(d);% 分割出第四个字符 [word4,d]=getword(d);% 分割出第五个字符 [word5,d]=getword(d);% 分割出第六个字符 [word6,d]=getword(d);% 分割出第七个字符 [word7,d]=getword(d);

figure(8),subplot(1,7,1),imshow(word1),title('第一位'); figure(8),subplot(1,7,2),imshow(word2),title('第二位'); figure(8),subplot(1,7,3),imshow(word3),title('第三位'); figure(8),subplot(1,7,4),imshow(word4),title('第四位'); figure(8),subplot(1,7,5),imshow(word5),title('第五位'); figure(8),subplot(1,7,6),imshow(word6),title('第六位'); figure(8),subplot(1,7,7),imshow(word7),title('第七位');

[m,n]=size(word1);% 商用系统程序中归一化大小为 40*20,此处演示 word1=imresize(word1,[40 20]); word2=imresize(word2,[40 20]);

第 29页 共 33页

word3=imresize(word3,[40 20]); word4=imresize(word4,[40 20]); word5=imresize(word5,[40 20]); word6=imresize(word6,[40 20]); word7=imresize(word7,[40 20]);

figure(9),subplot(1,7,1),imshow(word1),title('第一位'); figure(9),subplot(1,7,2),imshow(word2),title('第二位'); figure(9),subplot(1,7,3),imshow(word3),title('第三位'); figure(9),subplot(1,7,4),imshow(word4),title('第四位'); figure(9),subplot(1,7,5),imshow(word5),title('第五位'); figure(9),subplot(1,7,6),imshow(word6),title('第六位'); figure(9),subplot(1,7,7),imshow(word7),title('第七位'); imwrite(word1,'C:\\Users\\fushaodong\\Desktop\\1.jpg'); imwrite(word2,'C:\\Users\\fushaodong\\Desktop\\2.jpg'); imwrite(word3,'C:\\Users\\fushaodong\\Desktop\\3.jpg'); imwrite(word4,'C:\\Users\\fushaodong\\Desktop\\4.jpg'); imwrite(word5,'C:\\Users\\fushaodong\\Desktop\\5.jpg'); imwrite(word6,'C:\\Users\\fushaodong\\Desktop\\6.jpg'); imwrite(word7,'C:\\Users\\fushaodong\\Desktop\\7.jpg');

liccode=char(['0123456789' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ' '云贵川藏']); %建立自动识别字符代码表

SubBw2=zeros(40,20); l=1; for I=1:7

ii=int2str(I); t=imread([ii,'.jpg']);

SegBw2=imresize(t,[40 20],'nearest');

if l==1 %第一位汉字识别 kmin=37;

第 30页 共 33页

kmax=40;

elseif l==2 %第二位 A~Z 字母识别 kmin=11; kmax=36;

else l>=3 %第三位以后是字母或数字识别 kmin=1; kmax=36; end

for k2=kmin:kmax

fname=strcat('C:\\Users\\fushaodong\\Desktop\\sample\\',liccode(k2),'.jpg'); SamBw2 = imread(fname); for i=1:40 for j=1:20

SubBw2(i,j)=SegBw2(i,j)-SamBw2(i,j); end

end % 以上相当于两幅图相减得到第三幅图 Dmax=0; for k1=1:40 for l1=1:20

if ( SubBw2(k1,l1) > 0 | SubBw2(k1,l1) <0 ) Dmax=Dmax+1; end end end

Error(k2)=Dmax; end

Error1=Error(kmin:kmax); MinError=min(Error1); findc=find(Error1==MinError);

第 31页 共 33页

Code(l*2-1)=liccode(findc(1)+kmin-1); Code(l*2)=' '; l=l+1; end

figure,imshow(dw),title (['车牌号码:', Code],'Color','black')

子程序1: function e=qiege(d) [m,n]=size(d);

top=1;bottom=m;left=1;right=n; % init while sum(d(top,:))==0 && top<=m top=top+1; end

while sum(d(bottom,:))==0 && bottom>=1 bottom=bottom-1; end

while sum(d(:,left))==0 && left<=n left=left+1; end

while sum(d(:,right))==0 && right>=1 right=right-1; end dd=right-left; hh=bottom-top;

e=imcrop(d,[left top dd hh]);

子程序2:

function [word,result]=getword(d) word=[];flag=0;y1=8;y2=0.5;

第 32页 共 33页

while flag==0 [m,n]=size(d); wide=0;

while sum(d(:,wide+1))~=0 && wide<=n-2 wide=wide+1; end

temp=qiege(imcrop(d,[1 1 wide m])); [m1,n1]=size(temp); if widey2 d(:,[1:wide])=0; if sum(sum(d))~=0

d=qiege(d); % 切割出最小范围 else word=[];flag=1; end else

word=qiege(imcrop(d,[1 1 wide m])); d(:,[1:wide])=0; if sum(sum(d))~=0; d=qiege(d);flag=1; else d=[]; end end end %end result=d;

第 33页 共 33页


基于模板匹配的车牌识别及matlab实现(7).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:宁波分行会计柜面岗位试题

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: