赞
踩
[fn,pn,fi]=uigetfile('AD.jpg','选择图片');
I=imread([pn fn]);
figure,
imshow(I);
title('原始图像');
Im1=rgb2gray(I);
figure(2),
subplot(1,2,1),
imshow(Im1);
title('灰度图');
figure(2),
subplot(1,2,2),
imhist(Im1);
title('灰度图的直方图');
Tiao=imadjust(Im1,[0.19,0.78],[0,1]);
figure(3),
subplot(1,2,1),
imshow(Tiao);
title('增强灰度图');
figure(3),
subplot(1,2,2),
imhist(Tiao);
title('增强灰度图的直方图');
Im2=edge(Im1,'sobel',0.15,'both');
figure(4),
imshow(Im2);
title('sobel算子实现边缘检测')
se=[1;1;1;];
Im3=imerode(Im2,se);
figure(5),
imshow(Im3);
title('腐蚀效果图');
se=strel('rectangle',[25,25]);
Im4=imclose(Im3,se);
figure(6),
imshow(Im4);
title('平滑图像的轮廓');
Im5=bwareaopen(Im4,2000);
figure(7),
imshow(Im5);
title('移除小对象');
[y,x,z]=size(Im5);
Im6=double(Im5);
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if(Im6(i,j,1)==1)
Blue_y(i,1)=Blue_y(i,1)+1;
end
end
end
[temp MaxY]=max(Blue_y);
PY1=MaxY;
while((Blue_y(PY1,1)>=5)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while((Blue_y(PY2,1)>=5)&&(PY2
PY2=PY2+1;
end
IY=I(PY1:PY2,:,:);
Blue_x=zeros(1,x);
for j=1:x
for i=PY1:PY2
if(Im6(i,j,1)==1)
Blue_x(1,j)=Blue_x(1,j)+1;
end
end
end
PX1=1;
while((Blue_x(1,PX1)<3)&&(PX1
PX1=PX1+1;
end
PX2=x;
while((Blue_x(1,PX2)<3)&&(PX2>PX1))
PX2=PX2-1;
end
PX1=PX1-1;
PX2=PX2+1;
dw=I(PY1:PY2-6,PX1:PX2,:);
figure(8),
subplot(1,2,1),
imshow(IY),
title('垂直方向合理区域');
figure(8),
subplot(1,2,2),
imshow(dw),
title('定位剪切后的彩色车牌图像')
imwrite(dw,'dw.jpg');
a=imread('dw.jpg');
b=rgb2gray(a);
imwrite(b,'车牌灰度图像.jpg');
figure(9);
subplot(3,2,1),
imshow(b),
title('1.车牌灰度图像')
g_max=double(max(max(b)));
g_min=double(min(min(b)));
T=round(g_max-(g_max-g_min)/3);
[m,n]=size(b);
d=(double(b)>=T);
imwrite(d,'车牌二值图像.jpg');
figure(9)
subplot(3,2,2),
imshow(d),
title('2.车牌二值图像')
figure(9)
subplot(3,2,3),
imshow(d),
title('3.均值滤波前')
h=fspecial('average',3);
d=im2bw(round(filter2(h,d)));
imwrite(d,'均值滤波后.jpg');
figure(9)
subplot(3,2,4),
imshow(d),
title('4.均值滤波后')
se=eye(2);
[m,n]=size(d);
if bwarea(d)/m/n>=0.365
d=imerode(d,se);
elseif bwarea(d)/m/n<=0.235
d=imdilate(d,se);
end
imwrite(d,'膨胀或腐蚀后处理后.jpg');
figure(9)
subplot(3,2,5),
imshow(d),
title('5.膨胀或腐蚀后处理后')
d=QieGe(d);
[m,n]=size(d);
k1=1;k2=1;s=sum(d);j=1;
while j~=n
while s(j)==0;
j=j+1;
end
k1=j;
while s(j)~=0&&j<=n-1
j=j+1;
end
k2=j-1;
if k2-k1>=round(n/6.5)
[val,num]=min(sum(d(:,[k1+5:k2-5])));
d(:,k1+num+5)=0;
end
end
d=QieGe(d);
y1=10;y2=0.25;flag=0;word1=[];
while flag==0
[m,n]=size(d);
left=1;wide=0;
while sum(d(:,wide+1))~=0
wide=wide+1;
end
if wide
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>2
flag=1;word1=temp;
end
d(:,1:wide)=0;d=QieGe(d);
end
end
[word2,d]=FenGe(d);
[word3,d]=FenGe(d);
[word4,d]=FenGe(d);
[word5,d]=FenGe(d);
[word6,d]=FenGe(d);
[word7,d]=FenGe(d);
word1=imresize(word1,[40 20]);
word2=imresize(word2,[40 20]);
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
subplot(2,7,1),
imshow(word1),
title('1');
subplot(2,7,2),
imshow(word2),
title('2');
subplot(2,7,3),
imshow(word3),
title('3');
subplot(2,7,4),
imshow(word4),
title('4');
subplot(2,7,5),
imshow(word5),
title('5');
subplot(2,7,6),
imshow(word6),
title('6');
subplot(2,7,7),
imshow(word7),
title('7');
imwrite(word,'1.jpg');
imwrite(word,'2.jpg');
imwrite(word,'3.jpg');
imwrite(word,'4.jpg');
imwrite(word,'5.jpg');
imwrite(word,'6.jpg');
imwrite(word,'7.jpg');
liccode=char('0':'9''A':'Z''京津冀晋蒙辽吉黑沪苏浙皖闽赣鲁豫鄂湘粤桂琼渝川贵云藏陕甘青宁新');
l=1;
for I=1:7
ii=int2str(I);
t=imread([ii,'.jpg']);
SegBw2=imresize(t,[40,20],'nearest');
if 1==1
kmin=37;
kmax=40;
elseif 1>=2&&1<=3
kmin=11;
kmax=36;
elseif 1>=4&1<=7
kmin=1;
kmax=10;
end
for k2=kmin:kmax
fname=stract('字符模板|',liccode(k2),'.jpg');
SamBw2=imread(fname);
Dm=0;
for k1=1:40
for11=1:20;
if SegBw2(k1,11)==SamBw2(k1,11)
Dm=Dm+1;
end
end
end
Error(k2)=Dm;
end
Error1=Error(kmin:kmax);
MinError=max(Error1);
findc=find(Error1==MinError);
Resault(1*2-1)=liccode(find(1)+kmin-1);
Resault(1*2)='';
l=1+1;
t=toc;
Resault;
mesgbox(Resault,'识别结果')
fid=fopen('Data.xls','a+');
fprintf(fid,'%s|r|n',Resault,datestr(now));
fclose(fid);
索引超出矩阵维度。
出错 main (line 152)
while sum(d(:,wide+1))~=0
DZ.jpg
(188.91 KB, 下载次数: 0)
2020-5-11 15:42 上传
2020-5-11 15:41 上传
点击文件名下载附件
571 Bytes, 下载次数: 6
2020-5-11 15:41 上传
点击文件名下载附件
365 Bytes, 下载次数: 7
自定义函数2
2020-5-11 15:41 上传
点击文件名下载附件
5.01 KB, 下载次数: 4
主函数
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。