车牌字符分割

来源:互联网 发布:出名的网络翻唱歌手 编辑:程序博客网 时间:2024/04/30 04:03

接着上一篇文章,上面完成了陈派定位,那么现在就要对车牌进行字符分割,下面的程序每一步都有目的标注

%%%4.2车牌区域阈值化(OSTU)
I=imread('C:\Users\Administrator\Desktop\Des.jpg');
I=rgb2gray(I);
figure(1);
subplot(2,1,1);imshow(I);
lev=graythresh(I);
bw=im2bw(I,lev);
subplot(2,1,2);imshow(bw);

%%4.3.1车牌倾斜校正
%使用水平投影方法对图像倾斜校正
[n2,k2]=size(bw);
xdata=zeros(1,n2);
ydata=zeros(1,n2);
k1=1;
for l=1:1:n2
for k=1:1:k2
if bw(l,k)==1
xdata(k1)=l;
ydata(k1)=k;
k1=k1+1;
break;
end
end
end

res=fit(xdata',ydata','poly1');
p1=res.p1;
R=imrotate(bw,p1);
figure(2);
subplot(2,1,1);imshow(bw);
subplot(2,1,2);imshow(R);

%%%4.4字符切分
%字符向下投影,绘制字符周期性的位置
v=sum(R);
figure(3);
subplot(2,1,1);plot(v);
ma=max(v);
length=size(v,2);
for i=1:1:length
if v(1,i)<0.1*ma
v(1,i)=0;
end
end
subplot(2,1,2);plot(v);

%%然后根据竖直投影的规律确定每个字符的起止位置
str=zeros(1,7);
quit=zeros(1,7);
k=1;
for i=2:1:length
if (v(i-1)==0)&(v(i)>0)
str(k)=i;
else 
if (v(i-1)>0)&(v(i)==0)
quit(k)=i-1;
k=k+1;
continue;
end
end
end
%%切割每个字符
figure(4);
p1=R(:,str(1):quit(1));
subplot(4,2,1);imshow(p1);
p2=R(:,str(2):quit(2));
subplot(4,2,2);imshow(p2);
p3=R(:,str(3):quit(3));
subplot(4,2,3);imshow(p3);
p4=R(:,str(4):quit(4));
subplot(4,2,4);imshow(p4);
p5=R(:,str(5):quit(5));
subplot(4,2,5);imshow(p5);
p6=R(:,str(6):quit(6));
subplot(4,2,6);imshow(p6);
p7=R(:,str(7):quit(7));
subplot(4,2,7);imshow(p7);

figure(1)

figure(2)


figure(3)


figure(4)


2 0