黑桐谷歌本人照片:车牌定位 Matlab程序

来源:百度文库 编辑:九乡新闻网 时间:2024/05/03 11:03:33
2007-06-23 21:00
To任川:
你有什么问题在这里问吧。我可以给你一些程序入入门。
是车牌定位的。(不一定能适合你的车牌图片,你修改一下参数吧。)
clear;
clc;
close all;
chos=0;
possibility=9;
while chos~=possibility,
chos=menu('车牌定位系统','载入图片','二值化','边缘化','腐蚀','连通','滤波',...
'定位','倾斜校正','退出');
if chos==1,
clc;
[namefile,pathname]=uigetfile('*.jpg','Select image');
if namefile~=0
I=imread(strcat(pathname,namefile));
imshow(I);
end
end
if chos==2,
I1=rgb2gray(I);
imshow(I1);
end
if chos==3,
I2=edge(I1,'robert',0.15,'both');
imshow(I2);
end
if chos==4,
se=[1;1;1];
I3=imerode(I2,se);
imshow(I3);
end
if chos==5,
se=strel('rectangle',[25,25]);
I4=imclose(I3,se);
imshow(I4);
end
if chos==6,
I5=bwareaopen(I4,2000);
imshow(I5);
[y,x,z]=size(I5);
myI=I5;
end
if chos==7,
%%%%%%%%%%% 统计分析 %%%%%%%%%%%%%%%
%%%%%%%% Y 方向 %%%%%%%%%%
whitr_y=zeros(y,1);
for i=1:y
for j=1:x
if(myI(i,j,1)==1) % 白色RGB的灰度范围
whitr_y(i,1)= whitr_y(i,1)+1;      % 白色象素点统计
end
end
end
[temp MaxY]=max(whitr_y);         % Y方向车牌区域确定
PY1=MaxY;
while ((whitr_y(PY1,1)>=5)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while ((whitr_y(PY2,1)>=5)&&(PY2PY2=PY2+1;
end
IY=I(PY1:PY2,:,:);
%%%%%%%% X 方向 %%%%%%%%%%
whitr_x=zeros(1,x);              % 进一步确定X方向的车牌区域
for j=1:x
for i=PY1:PY2
if(myI(i,j,1)==1)
whitr_x(1,j)= whitr_x(1,j)+1;
end
end
end
PX1=1;
while ((whitr_x(1,PX1)<3)&&(PX1PX1=PX1+1;
end
PX2=x;
while ((whitr_x(1,PX2)<3)&&(PX2>PX1))
PX2=PX2-1;
end
Plate=I(PY1-13:PY2+13,PX1-5:PX2+5,:);%预留多些利于倾斜校正
%          t=toc % 读取计时
imshow(Plate);
end
if chos==8,
I=Plate;
level = graythresh(I);
I = im2bw(I,level);
%倾斜矫正
myI=edge(I,'sobel');
theta=0:179;
[r1,x1]=radon(myI,theta);
R1=sort(r1,'descend');
[x,y]=size(R1);
R=R1(1:10,:);
R=sum(R);
a=0.4;E(1)=R(1);
for i=2:length(R)
E(i)=a*R(i)+(1-a)*E(i-1);
end
a=tan((91-(find(E==max(E))))*pi/180);
I=imrotate(I,a);
imshow(I);
%水平方向倾斜矫正
Rfilter=0; Lfilter=0;
for j=alpha+10:length(E)-1
if (E(j)<=200)&&(E(j)Rfilter=j;
end
end
for j=2:alpha-10
if(E(j)<=200)&&(E(j)Lfilter=j;
end
end
E(Lfilter:Rfilter)=min(E(Lfilter),E(Rfilter));
for i=2:179
if(E(i)>=200)&&(E(i)>E(i-1))&&(E(i)>=E(i+1))
beta=i;
else
beta=0;
end
end
if alpha>91;
a=-tan(beta);
else a=tan(beta);
end
tform=maketform('affine',[1 0 0;a 1 0;0 0 1]);
goal=imtransform(I,tform,'bicubic');
%垂直方向矫正
if mean(goal)>0.5
goal=~goal;
end
imshow(goal(15:end-14,11:end-10));
end
end