android 车牌字符分割,车牌字符不能正确分割

clc;

clear;

close all;

I=imread('3.png');

figure(1),imshow(I);title('原图');

I1=rgb2gray(I);

figure(2),subplot(1,2,1),imshow(I1);title('灰度图');

figure(2),subplot(1,2,2),imhist(I1);title('灰度图直方图');

I2=edge(I1,'canny',[0.2,0.55]);

figure(3),imshow(I2);title('canny算子边缘检测')

se=[1;1;1];

I3=imerode(I2,se);

figure(4),imshow(I3);title('腐蚀后图像');

se=strel('rectangle',[40,40]);

I4=imclose(I3,se);

figure(5),imshow(I4);title('平滑图像的轮廓');

I5=bwareaopen(I4,2000);

figure(6),imshow(I5);title('从对象中移除小对象');

[y,x,z]=size(I5);

myI=double(I5);

%begin横向扫描

Blue_y=zeros(y,1);

for i=1:y

for j=1:x

if(myI(i,j,1)==1)

%如果myI(i,j,1)即myI图像中坐标为(i,j)的点为蓝色

%则Blue_y的相应行的元素white_y(i,1)值加1

Blue_y(i,1)= Blue_y(i,1)+1;%蓝色像素点统计

end

end

end

[temp MaxY]=max(Blue_y);%temp为向量white_y的元素中的最大值,MaxY为该值的索引( 在向量中的位置)

PY1=MaxY;

while ((Blue_y(PY1,1)>=50)&&(PY1>1))

PY1=PY1-1;

end

PY2=MaxY;

while ((Blue_y(PY2,1)>=10)&&(PY2

PY2=PY2+1;

end

IY=I(PY1:PY2,:,:);

%IY为原始图像I中截取的纵坐标在PY1:PY2之间的部分

%end横向扫描

%begin纵向扫描

Blue_x=zeros(1,x);%进一步确定x方向的车牌区域

for j=1:x

for i=PY1:PY2

if(myI(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+15;

PY1=PY1-2.5;

%end纵向扫描

dw=I(PY1:PY2,PX1:PX2,:);

imwrite(dw,'dw.jpg');

figure(7),subplot(1,2,1),imshow(IY),title('行方向合理区域');

figure(7),subplot(1,2,2),imshow(dw),title('定位剪切后的彩色车牌图像')

%利用radon变换做水平矫正

bw=rgb2gray(dw);

bw1=edge(bw,'sobel','horizontal');

theta=0:179;

r=radon(bw1,theta);

[m,n]=size(r);

c=1;

for i=1:m

for j=1:n

if r(1,1)

r(1,1)=r(i,j);

c=j;

end

end

end

rot=90-c+2;

pic=imrotate(bw,rot,'crop');

figure(8),subplot(3,1,1),imshow(bw),title('1.定位后的这牌灰度图像');

figure(8),subplot(3,1,2),imshow(pic),title('2.利用radon算子做水平方向矫正');

%字符分割前的预处理

g_max=double(max(max(pic)));

g_min=double(min(min(pic)));

T=round(g_max-(g_max-g_min)/3); % T 为二值化的阈值

[m,n]=size(pic);

d=im2bw(pic,T/256);  % d:二值图像

figure(9);subplot(2,2,1),imshow(d),title('1.车牌二值图像')

% 滤波

h=fspecial('average',3);

d=im2bw(round(filter2(h,d)));

figure(9),subplot(2,2,2),imshow(d),title('2.均值滤波后')

% 某些图像进行操作

% 膨胀或腐蚀

se=strel('square',3); % 使用一个3X3的正方形结果元素对象对创建的图像膨胀

se=eye(2); % eye(n) returns the n-by-n identity matrix 单位矩阵

[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

figure(9),subplot(2,2,3),imshow(d),title('3.膨胀或腐蚀处理后')

%对图像的边框进行裁剪,只留下有效字符部分

[y1,x1,z1]=size(d);

I3=double(d);

TT=1;

Y1=zeros(y1,1);

for i=1:y1

for j=1:x1

if(I3(i,j,1)==1)

Y1(i,1)= Y1(i,1)+1 ;

end

end

end

Py1=1;

Py0=1;

while ((Y1(Py0,1)<30)&&(Py0

Py0=Py0+1;

end

Py1=Py0;

while((Y1(Py1,1)>=30)&&(Py1

Py1=Py1+1;

end

d=d(Py0:Py1,:,:);

figure(9),subplot(2,2,4);

imshow(d),title('4.目标车牌区域');

%在列方向上进行灰度值累加

X1=zeros(1,x1);

for j=1:x1

for i=1:y1

if(I3(i,j,1)==1)

X1(1,j)= X1(1,j)+1;

end

end

end

figure(10);

plot(0:x1-1,X1),title('列方向像素点灰度值累计和'),xlabel('列值'),ylabel('累计像素量');

Px0=1;

Px1=1;

%%%%%%%%%%%%分割字符%%%%%%%%%%%%%%%%%%

for i=1:7

while ((X1(1,Px0)<2)&&(Px0

Px0=Px0+1;

end

Px1=Px0;

while (((X1(1,Px1)>=3)&&(Px1

Px1=Px1+1;

end

Z=d(:,Px0:Px1,:);

switch strcat('Z',num2str(i))

case 'Z1'

PIN0=Z;

case 'Z2'

PIN1=Z;

case 'Z3'

PIN2=Z;

case 'Z4'

PIN3=Z;

case 'Z5'

PIN4=Z;

case 'Z6'

PIN5=Z;

otherwise

PIN6=Z;

end

figure(11);

subplot(1,7,i);

imshow(Z);

Px0=Px1;

end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值