# 一个车牌定位方法，包括图像的灰度化，二值化，数学形态学的处理，滤波等

• 虫虫123456
了解作者
• matlab
开发工具
• 1.4KB
文件大小
• rar
文件格式
• 0
收藏次数
• 5 积分
下载积分
• 0
下载次数
• 2022-06-15 14:48
上传日期

ly1eQIyYF9o7Sy (1).rar
• locating.m
3.6KB

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); I1=im2double(I1); imshow(I1); end if chos==3 I2=edge(I1,'canny'); 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 tic 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)&&(PY2<5)) PY2=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)&&(PX1<x)) PX1=PX1+1; end PX2=x; while ((whitr_x(1,PX2)<3)&&(PX2>PX1)) PX2=PX2-1; end Plate=I(PY1:PY2,PX1:PX2,:);%预留多些利于倾斜校正 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)<E(j-1))&&(E(j)<=E(j+1)) Rfilter=j; end end for j=2:alpha-10 if (E(j)<200)&&(E(j)<E(j-1))&&(E(j)<=E(j+1)) 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

相关推荐