在好例子网,分享、交流、成长!
您当前所在位置:首页MATLAB 开发实例MATLAB语言基础 → matlab车牌识别代码

matlab车牌识别代码

MATLAB语言基础

下载此实例
  • 开发语言:MATLAB
  • 实例大小:6.09KB
  • 下载次数:13
  • 浏览次数:87
  • 发布时间:2020-12-07
  • 实例类别:MATLAB语言基础
  • 发 布 人:Valeon
  • 文件格式:.m
  • 所需积分: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

实例下载地址

matlab车牌识别代码

不能下载?内容有错? 点击这里报错 + 投诉 + 提问

好例子网口号:伸出你的我的手 — 分享

网友评论

发表评论

(您的评论需要经过审核才能显示)

查看所有0条评论>>

小贴士

感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。

  • 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
  • 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
  • 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
  • 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。

关于好例子网

本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明

;
报警