clear ;
clc
close all;
%获取图像 装入待处理彩色图像并显示原始图像
[fn,pn,fi]=uigetfile('*.png','选择图片');
Scolor=imread([pn fn]);
figure,imshow(Scolor),title('原始图像');
%将彩色图像转换为黑白并显示
Sgray = rgb2gray(Scolor);%rgb2gray转换成灰度图
figure,imshow(Sgray),title('灰度图像');
figure,Sgray=imresize(Sgray,[200 200]);imshow(Sgray),title('归一化图像');
mainfc;
liccode=char(['0','1', '2', '3','4']); %建立自动识别字符代码表
tt=1;
l=1;
t=Sgray;
t=255-t;
level=graythresh(t);
t=im2bw(t,level);
SegBw2=imresize(t,[200 200],'nearest');
if tt==1 %第一位汉字识别
kmin=1;
kmax=5;
t=~t;
SegBw2=imresize(t,[200 200],'nearest');
end
for k2=kmin:kmax
fname=strcat('code module\',liccode(k2),'.bmp');
%SamBw2 = imread(fname);
SamBw22 = imread(fname);
SamBw2=imresize(SamBw22,[200 200],'nearest');
level=graythresh(SamBw2);
SamBw2=im2bw(SamBw2,level);
for i=1:200
for j=1:200
SubBw2(i,j)=SegBw2(i,j)-SamBw2(i,j);
end
end
% 以上相当于两幅图相减得到第三幅图
Dmax=0;
for k1=1:200
for l1=1:200
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);
if tt==1
findc=findc;
end
tt=tt+1;
res=liccode(findc);
shibiejieguo(1,l)=res;
l=l+1;
shibiejieguo
%==========================对话框显示显示=============================================
if shibiejieguo=='0'
msgbox('限速60')
elseif shibiejieguo=='1'
msgbox('T型路口');
elseif shibiejieguo=='2'
msgbox('禁止鸣笛');
elseif shibiejieguo=='3'
msgbox('非机动车道');
elseif shibiejieguo=='4'
msgbox('禁止停车');
end