基本信息
源码名称:matlab车牌识别代码
源码大小:6.09KB
文件格式:.m
开发语言:MATLAB
更新时间:2020-12-07
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 2 元 
   源码介绍


car=imread('car1.jpg');
imshow(car);
%color image to gray
car1=rgb2gray(car);
figure,imshow(car1);
car2=histeq(car1);
figure,imshow(car2);
%edge detection
temp=edge(car1,'sobel');
figure,imshow(temp);
[x,y]=size(temp);
d=2;
temp1=temp;
%continuous peoperty test
for i=1:x
    for j=d 1:y-d
        if(2*temp(i,j)-temp(i,j-d)-temp(i,j d)==0)
            temp1(i,j)=0;
        else
            temp1(i,j)=temp1(i,j);
        end
    end
end
figure,imshow(temp1);
%character compensation
se=ones(3);
temp2=imclose(temp1,se);
figure,imshow(temp2);
temp3=temp2;
th=20;
th1=70;
%property transformation
for i=1:x
    bp=[];
    bp1=[];
    pos=[];
    len=[];
    ind=find(temp2(i,:)==1);
    [m,n]=size(ind);
    index=0;
    if n~=0
        for j=1:n-1
            if ind(1,j 1)-ind(1,j)>th
                index=index 1;
                bp(1,index)=ind(j 1);
                bp1(1,index)=ind(j);
            end
        end
        [x1,y1]=size(bp);
        if y1~=0
            pos(1,1)=ind(1,1);
            pos(2:y1 1)=bp;
            len(1,1)=bp1(1,1)-pos(1,1);
            for k=1:y1-1
                len(1,k 1)=bp1(1,k 1)-bp(1,k);
            end
            len(1,y1 1)=ind(1,n)-pos(1,y1 1);
            for k=1:y1 1
                if len(k)>=th1
                    temp2(i,pos(k):pos(k) len(k))=1;
                else
                    temp2(i,pos(k):pos(k) len(k))=0;
                end
            end
        elseif ind(n)-ind(1)>=th1
            temp2(i,ind(1):ind(n))=1;
        else
            temp2(i,ind(1):ind(n))=0;
        end
    end
end
figure,imshow(temp2);
%final locate
connComp=bwconncomp(temp2);
features=regionprops(connComp,'basic');
borders=[features.BoundingBox];
area=[features.Area];
for i=1:connComp.NumObjects
    leftx=borders((i-1)*4 1);
    lefty=borders((i-1)*4 2);
    width=borders((i-i)*4 3);
    height=borders((i-1)*4 4);
    if area(i)<1000 || area(i)>5000
        temp2(connComp.PixelIdxList{i})=0;
    elseif width/height>6 || width/height<3
        temp2(connComp.PixelIdxList{i})=0;
    end
end
figure,imshow(temp2);
%calculate plate coordinates
[x,y]=size(temp2);
xcounts=zeros(x,1);
for i=1:x
    for j=1:y
        if(temp2(i,j)==1)
            xcounts(i,1)=xcounts(i,1) 1;
        end
    end
end
[mv,maxx]=max(xcounts);
px1=maxx;
while((xcounts(px1,1)>=5)&&(px1>1))
    px1=px1-1;
end
px2=maxx;
while((xcounts(px2,1)>=5)&&(px2<x))
    px2=px2 1;
end
ycounts=zeros(1,y);
for j=1:y
    for i=px1:px2
        if(temp2(i,j)==1)
            ycounts(1,j)=ycounts(1,j) 1;
        end
    end
end
py1=1;
while((ycounts(1,py1)<3)&&(py1<y))
    py1=py1 1;
end
py2=y;
while((ycounts(1,py2)<3)&&(py2>py1))
py2=py2-1;
end
%car plate image to gray
temp3=car(px1:px2,py1:py2,:);
figure,imshow(temp3);
temp4=rgb2gray(temp3);
figure,imshow(temp4);
%car plate image binarize
g_max=double(max(max(temp4)));
g_min=double(min(min(temp4)));
T=round(g_max-(g_max-g_min)/2);
[m,n]=size(temp4);
temp5=double(temp4)>=T;
figure,imshow(temp5);title('temp5');
%median filter
h=fspecial('average',3);
temp6=im2bw(round(filter2(h,temp5)));
figure,imshow(temp6);
%Character diviSion
[m,n]=size(temp5);
char_width=[100];
char_position=[100];
%vertical diviSion
s1=sum(temp5);
content1=find(s1>=10 & s1<=n*0.8);
[m2,n2]=size(content1);
height1=content1(1);
height2=content1(n2);
%hotiZontai diviSion
s=sum(temp5(height1:height2,0:1));
j=1;
i=1;
flag=1;
content=find(s~=0);
[m1,n1]=size(content);
for i=2:n1
    if(content(i)-content(i-1)>1)
        flag=flag 1;
        char_position(flag)=content(i);
        char_width(flag-1)=content(i-1)-char_position(flag-1);
    end
end
char_position(1)=1;
char_width(1)=char_width(1)-1;
char_width(flag)=content(n1)-char_position(flag);
%write the chatacters IntO p1CS
word1=temp5(height1:height2,char_position(1):char_position(1) char_width(1));
figure,imshow(word1);
word2=temp5(height1:height2,char_position(2):char_position(2) char_width(2));
figure,imshow(word2);
word3=temp5(height1:height2,char_position(3):char_position(3) char_width(3));
figure,imshow(word3);
word4=temp5(height1:height2,char_position(4):char_position(4) char_width(4));
figure,imshow(word4);
word5=temp5(height1:height2,char_position(5):char_position(5) char_width(5));
figure,imshow(word5);
word6=temp5(height1:height2,char_position(6):char_position(6) char-width(6));
figure,imshow(word6);
word7=temp5(height1:height2,char_position(7):char_position(7) char-width(7));
figure,imshow(word7);
%character normialization
word1=imresize(word1,[32,16]);
word2=imresize(word2,[32,16]);
word3=imresize(word3,[32,16]);
word4=imresize(word4,[32,16]);
word5=imresize(word5,[32,16]);
word6=imresize(word6,[32,16]);
word7=imresize(word7,[32,16]);
imshow(word1);
imshow(word2);
imshow(word3);
imshow(word4);
imshow(word5);
imshow(word6);
imshow(word7);
imwrite(word1,'1.jpg');
imwrite(word2,'2.jpg');
imwrite(word3,'3.jpg');
imwrite(word4,'4.jpg');
imwrite(word5,'5.jpg');
imwrite(word6,'6.jpg');
imwrite(word7,'7.jpg');

%file name list
liccode=char(['0':'9' 'A':'Z' '京津沪渝冀晋辽吉黑苏浙皖闽赣鲁豫鄂湘粤琼川贵云陕甘青藏桂蒙新宁港']);

subbw=zeros(32,16);
l=1;
%compare with the standard models
for i=1:7
    ii=int2str(i);
    t=imread([ii,'.jpg']);
    seg=im2bw(t);
    if i==1
        kmin=37;
        kmax=68;
    elseif i==2
        kmin=11;
        kmax:36;
    elseif i>=3
        kmin=1;
        kmax=36;
    end

    for k2=kmin:kmax
        fname=strcat('',liccode(k2),'.bmp');
        t1=imread(fname);
        sam=im2bw(t1);
        for i=1:32
            for j=1:16
                subbw(i,j)=seg(i,j)-sam(i,j);
            end
        end
        dmax=0;
        for i=l:32
            for J=1:16
                if(subbw(i,j)~=0)
                end
            end
            dmax=dmax 1;
        end
        error(k2)=dmax;
    end
%find the minimum number of 1s
    Error1=error(kmin:kmax);
    MinError=min(Error1);
    findc=find(Error1==MinError);
    Code(1*2-1)=liccode(findc(1) kmin-1);
    Code(1*2)=' ';
    l=l 1;
end