资源描述:
《济冀津晋京警兰辽领鲁蒙闽宁青琼陕使苏皖湘新学渝豫粤云.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、liccode=char(['0':'9''A':'Z''藏川甘赣贵桂黑沪吉济冀津晋京警兰辽领鲁蒙闽宁青琼陕使苏皖湘新学渝豫粤云浙']);%建立自动识别字符代码表tt=1;l=1;forI=1:7ii=int2str(I);t=imread([ii,'.jpg']);t=255-t;level=graythresh(t);t=im2bw(t,level);SegBw2=imresize(t,[2214],'nearest');iftt==1%第一位汉字识别kmin=37;kmax=72;t=~t;SegBw2=imresize(t,[2214],'nearest');else
2、iftt==2%第二位A~Z字母识别kmin=11;kmax=36;else%第三位以后是字母或数字识别kmin=1;kmax=36;endfork2=kmin:kmaxfname=strcat('codemoduleSam',liccode(k2),'.jpg');SamBw22=imread(fname);SamBw22=rgb2gray(SamBw22);SamBw2=imresize(SamBw22,[2214],'nearest');level=graythresh(SamBw2);SamBw2=im2bw(SamBw2,level);fori=1:22forj=
3、1:14SubBw2(i,j)=SegBw2(i,j)-SamBw2(i,j);endend%以上相当于两幅图相减得到第三幅图Dmax=0;fork1=1:22forl1=1:14if(SubBw2(k1,l1)>0
4、
5、SubBw2(k1,l1)<0)Dmax=Dmax+1;endendendError(k2)=Dmax;endError1=Error(kmin:kmax);MinError=min(Error1);findc=find(Error1==MinError);iftt==1findc=findc+36;endiftt==2findc=findc+10;endtt
6、=tt+1;res=liccode(findc);shibiejieguo(1,l)=res;l=l+1;end%%%getword子函数为:function[word,result]=getword(d)word=[];flag=0;y1=8;y2=0.5;whileflag==0[m,n]=size(d);wide=0;whilesum(d(:,wide+1))~=0&&wide<=n-2wide=wide+1;endtemp=qiege(imcrop(d,[11widem]));[m1,n1]=size(temp);ifwidey2d(:,[1:w
7、ide])=0;ifsum(sum(d))~=0d=qiege(d);%切割出最小范围elseword=[];flag=1;endelseword=qiege(imcrop(d,[11widem]));d(:,[1:wide])=0;ifsum(sum(d))~=0;d=qiege(d);flag=1;elsed=[];endendendresult=d;%%%qiege子函数为:functione=qiege(d)[m,n]=size(d);top=1;bottom=m;left=1;right=n;%initwhilesum(d(top,:))==0&&top<=mtop
8、=top+1;endwhilesum(d(bottom,:))==0&&bottom>1bottom=bottom-1;endwhilesum(d(:,left))==0&&left=1right=right-1;enddd=right-left;hh=bottom-top;e=imcrop(d,[lefttopddhh]);