matlab车牌识别程序代码.docx
- 文档编号:26224628
- 上传时间:2023-06-17
- 格式:DOCX
- 页数:58
- 大小:24.60KB
matlab车牌识别程序代码.docx
《matlab车牌识别程序代码.docx》由会员分享,可在线阅读,更多相关《matlab车牌识别程序代码.docx(58页珍藏版)》请在冰豆网上搜索。
matlab车牌识别程序代码
%车牌识别程序主体
clc;
closeall;
clearall;
%==========================================================
%说明:
%
%
%===========================================================
%==============测定算法执行的时间,开始计时=================
tic%%%%%记录程序运行时间
%=====================读入图片================================
[fn,pn,fi]=uigetfile('*.jpg','选择图片');
I=imread([pnfn]);
figure;
imshow(I);
title('原始图像');%显示原始图像
chepailujing=[pnfn]
I_bai=I;
[PY2,PY1,PX2,PX1]=caitu_fenge(I);
%I=rgb2hsv(I);
%[PY2,PY1,PX2,PX1]=caitu_tiqu(I,I_bai);%用HSI模型识别蓝色,用rgb模型识别白色
%================分割车牌区域=================================
%===============车牌区域根据面积二次修正======================
[PY2,PY1,PX2,PX1,threshold]=SEC_xiuzheng(PY2,PY1,PX2,PX1);
%==============更新图片=============================
Plate=I_bai(PY1:
PY2,PX1:
PX2,:
);%使用caitu_tiqu
%==============考虑用腐蚀解决蓝色车问题=============
bw=Plate;figure,imshow(bw);title('车牌图像');%hsv彩图提取图像
%==============这里要根据图像的倾斜度进行选择这里选择的图片20090425686.jpg
bw=rgb2gray(bw);figure,imshow(bw);title('灰度图像');
%================倾斜校正======================
qingxiejiao=rando_bianhuan(bw)
bw=imrotate(bw,qingxiejiao,'bilinear','crop');figure,imshow(bw);title('倾斜校正');%取值为负值向右旋转
%==============================================
bw=im2bw(bw,graythresh(bw));%figure,imshow(bw);
bw=bwmorph(bw,'hbreak',inf);%figure,imshow(bw);
bw=bwmorph(bw,'spur',inf);%figure,imshow(bw);title('擦除之前');
');闭合运算bw=bwmorph(bw,'open',5);%figure,imshow(bw);title('
bw=bwareaopen(bw,threshold);figure,imshow(bw);title('擦除');
%==================加入进度条================================
%h=waitbar(0,'程序运行中,请稍等......')
%fori=1:
10000
%waitbar(i/5000,h)
%end
%close(h);
%wavplay(wavread('程序运行中.wav'),22000);
%==========================================================
bw=~bw;figure,imshow(bw);title('擦除反色');
%=============对图像进一步裁剪,保证边框贴近字体===========
bw=touying(bw);figure;imshow(bw);title('Y方向处理');
bw=~bw;
bw=bwareaopen(bw,threshold);
bw=~bw;%figure,imshow(bw);title('二次擦除');
[y,x]=size(bw);%对长宽重新赋值
%=================文字分割=================================
fenge=shuzifenge(bw,qingxiejiao)
[m,k]=size(fenge);
%=================显示分割图像结果=========================
figure;
fors=1:
2:
k-1
subplot(1,k/2,(s+1)/2);imshow(bw(1:
y,fenge(s):
fenge(s+1)));
end
%================给七张图片定位===============桂AV6388
han_zi=bw(1:
y,fenge
(1):
fenge
(2));
zi_mu=bw(1:
y,fenge(3):
fenge(4));
zm_sz_1=bw(1:
y,fenge(5):
fenge(6));
zm_sz_2=bw(1:
y,fenge(7):
fenge(8));
shuzi_1=bw(1:
y,fenge(9):
fenge(10));
shuzi_2=bw(1:
y,fenge(11):
fenge(12));
shuzi_3=bw(1:
y,fenge(13):
fenge(14));
%==========================识别====================================
%======================把修正数据读入==============================
xiuzhenghanzi=imresize(han_zi,[11055],'bilinear');
xiuzhengzimu=imresize(zi_mu,[11055],'bilinear');
xiuzhengzm_sz_1=imresize(zm_sz_1,[11055],'bilinear');
xiuzhengzm_sz_2=imresize(zm_sz_2,[11055],'bilinear');
xiuzhengshuzi_1=imresize(shuzi_1,[11055],'bilinear');
xiuzhengshuzi_2=imresize(shuzi_2,[11055],'bilinear');
xiuzhengshuzi_3=imresize(shuzi_3,[11055],'bilinear');
%============把0-9,A-Z以及省份简称的数据存储方便访问====================
hanzishengfen=duquhanzi(imread('cpgui.bmp'),imread('cpguizhou.bmp'),imread('cpjing.bmp'),imread('cpsu.bmp'),imread('cpyue.bmp'));
%因数字和字母比例不同。
这里要修改
shuzizimu=duquszzm(imread('0.bmp'),imread('1.bmp'),imread('2.bmp'),imread('3.bmp'),imread('4.bmp'),...
imread('5.bmp'),imread('6.bmp'),imread('7.bmp'),imread('8.bmp'),imread('9.bmp'),...
imread('10.bmp'),imread('11.bmp'),imread('12.bmp'),imread('13.bmp'),imread('14.bmp'),...
imread('15.bmp'),imread('16.bmp'),imread('17.bmp'),imread('18.bmp'),imread('19.bmp'),...
imread('20.bmp'),imread('21.bmp'),imread('22.bmp'),imread('23.bmp'),imread('24.bmp'),...
imread('25.bmp'),imread('26.bmp'),imread('27.bmp'),imread('28.bmp'),imread('29.bmp'),...
imread('30.bmp'),imread('31.bmp'),imread('32.bmp'),imread('33.bmp'));
zimu=
duquzimu(imread('10.bmp'),imread('11.bmp'),imread('12.bmp'),imread('13.bmp'),imread('14.bmp'),...
imread('15.bmp'),imread('16.bmp'),imread('17.bmp'),imread('18.bmp'),imread('19.bmp'),...
imread('20.bmp'),imread('21.bmp'),imread('22.bmp'),imread('23.bmp'),imread('24.bmp'),...
imread('25.bmp'),imread('26.bmp'),imread('27.bmp'),imread('28.bmp'),imread('29.bmp'),...
imread('30.bmp'),imread('31.bmp'),imread('32.bmp'),imread('33.bmp'));
shuzi=
duqushuzi(imread('0.bmp'),imread('1.bmp'),imread('2.bmp'),imread('3.bmp'),imread('4.bmp'),...
imread('5.bmp'),imread('6.bmp'),imread('7.bmp'),imread('8.bmp'),imread('9.bmp'));
%============================识别结果================================
i=1;%shibiezm_sz该函数识别数字有问题
jieguohanzi=shibiehanzi(hanzishengfen,xiuzhenghanzi);shibiejieguo(1,i)=jieguohanzi;i=i+1;
jieguozimu=shibiezimu(zimu,xiuzhengzimu);shibiejieguo(1,i)=jieguozimu;
i=i+1;
jieguozm_sz_1=shibiezm_sz(shuzizimu,xiuzhengzm_sz_1);shibiejieguo(1,i)
=jieguozm_sz_1;i=i+1;
jieguozm_sz_2=shibiezm_sz(shuzizimu,xiuzhengzm_sz_2);shibiejieguo(1,i)
=jieguozm_sz_2;i=i+1;
jieguoshuzi_1=shibieshuzi(shuzi,xiuzhengshuzi_1);shibiejieguo(1,i)=jieguoshuzi_1;i=i+1;
jieguoshuzi_2=shibieshuzi(shuzi,xiuzhengshuzi_2);shibiejieguo(1,i)=jieguoshuzi_2;i=i+1;
jieguoshuzi_3=shibieshuzi(shuzi,xiuzhengshuzi_3);shibiejieguo(1,i)=jieguoshuzi_3;i=i+1;
%==========================对话框显示显示=============================================
shibiejieguo
===============后面的注释掉了(语音读出这一部分)%%%%========
msgbox(shibiejieguo,'识别结果');
%%=====================导出文本==================
%fid=fopen('Data.xls','a+');
%fprintf(fid,'%s\r\n',shibiejieguo,datestr(now));
%fclose(fid);
%%===================读出声音===================
%duchushengyin(shibiejieguo);
%================读取计时==========================
t=toc%%%记录程序运行时间
%============================================
自己编写的子函数
functionbw_fir=touying(imane_bw)
X_yuzhi=1;
[y,x]=size(imane_bw);
Y_touying=(sum((~imane_bw)'))';%往左边投影统计黑点
X_touying=sum((~imane_bw));%往下面投影
%找黑体边缘
Y_up=fix(y/2);
Y_yuzhi=mean(Y_touying((fix(y/2)-10):
(fix(y/2)+10),1))/1.6;
while((Y_touying(Y_up,1)>=Y_yuzhi)&&(Y_up>1))%找到图片上边界
Y_up=Y_up-1;
end
Y_down=fix(y/2);
while((Y_touying(Y_down,1)>=Y_yuzhi)&&(Y_down Y_down=Y_down+1; end %去除左边边框干扰 X_right=1; if(X_touying(1,fix(x/14)))<=X_yuzhi X_right=fix(x/14) end %找黑体边缘 bw_fir=imane_bw(Y_up: Y_down,X_right: x); 自己编写的子函数 functionfenge=shuzifenge(imfenge,qingxiejiao) [y,x]=size(imfenge); %===============用函数设定分割阈值======================== SS=x*y ifSS<=20000 shedingyuzhi=4; elseifSS>20000&&SS<=30000 shedingyuzhi=4; elseifSS>30000&&SS<=50000 shedingyuzhi=4; elseifSS>50000&&SS<=80000 shedingyuzhi=4; else shedingyuzhi=4; end ganrao=SS/100; %========================================================= %定义数组histogram存储垂直方向的黑点数 histogram=sum(~imfenge); %=================文字分割============================= k=1; forh=1: x-1 if ((histogram(1,h)<=shedingyuzhi)&&(histogram(1,h+1)>shedingyuzhi))||((h==1)&&histogram(1,h)>shedingyuzhi) fenge(1,k)=h; k=k+1; elseif ((histogram(1,h)>shedingyuzhi)&&(histogram(1,h+1)<=shedingyuzhi))||((h==x-1)&&histogram(1,h)>shedingyuzhi) fenge(1,k)=h+1; k=k+1; end end k=k-1;%去掉多产生的一个K值 ifk<10 msgbox('提取出错','警告'); wavplay(wavread('提取出错.wav'),22000); pause; end %============================================== if (sum(histogram(1,fenge(1,1): fenge(1,2))) fori=3: k fenge(1,i-2)=fenge(1,i); end end [mn]=size(fenge); ifn<14 msgbox('提取出错','警告'); wavplay(wavread('提取出错.wav'),22000); pause; end fenge=fenge(1,1: 14); 自己编写的子函数 functionshibiezm_sz=shibiezm_sz(shuzizimu,xiuzhengzm_sz); [y,x,z]=size(xiuzhengzm_sz); fork=1: 34 sum=0; fori=1: y forj=1: x ifshuzizimu(i,j,k)==xiuzhengzm_sz(i,j)%统计黑白 sum=sum+1; end end end baifenbi(1,k)=double(sum/(x*y)); end chepai=find(baifenbi>=max(baifenbi)); chepai=chepai(1,1); %===================数字直接返回========================= if(chepai>=1)&&(chepai<=10) zm_sz=chepai-1; zm_sz=num2str(zm_sz); elseif(chepai>=11)&&(chepai<=34) %==================字母对应序号转字母==================== %=========11-15ABCDE16-20FGHIJ21-25KLMNP26-30QRSTU31-35VWXYZ ifchepai==11 zm_sz='A'; elseifchepai==12 zm_sz='B'; elseifchepai==13 zm_sz='C'; elseifchepai==14 zm_sz='D'; elseifchepai==15 zm_sz='E'; elseifchepai==16 zm_sz='F'; elseifchepai==17 zm_sz='G'; elseifchepai==18 zm_sz='H'; elseifchepai==19 zm_sz='J'; elseifchepai==20 zm_sz='K'; elseifchepai==21 zm_sz='L'; elseifchepai==22 zm_sz='M'; elseifchepai==23 zm_sz='N'; elseifchepai==24 zm_sz='P'; elseifchepai==25 zm_sz='Q'; elseifchepai==26 zm_sz='R'; elseifchepai==27 zm_sz='S'; elseifchepai==28 zm_sz='T'; elseifchepai==29 zm_sz='U'; elseifchepai==30 zm_sz='V'; elseifchepai==31 zm_sz='W'; elseifchepai==32 zm_sz='X'; elseifchepai==33 zm_sz='Y'; elseifchepai==34 zm_sz='Z'; end end shibiezm_sz=zm_sz; 自己编写的子函数 functionshibiezm_sz=shibiezm_sz(shuzizimu,xiuzhengzm_sz); [y,x,z]=size(xiuzhengzm_sz); fork=1: 34 sum=0; fori=1: y forj=1: x ifshuzizimu(i,j,k)==xiuzhengzm_sz(i,j)%统计黑白 sum=sum+1; end end end baifenbi(1,k)=double(sum/(x*y)); end chepai=fi
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- matlab 车牌 识别 程序代码