matlab车牌识别程序代码

更新时间:2023-10-16 13:38:01 阅读量: 综合文库 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

% 车牌识别程序主体 clc;

close all; clear all;

%========================================================== %说明: % %

%=========================================================== % ==============测定算法执行的时间,开始计时================= tic %%%%%记录程序运行时间

%=====================读入图片================================ [fn,pn,fi]=uigetfile('*.jpg','选择图片'); I=imread([pn fn]); figure; imshow(I);

title('原始图像');%显示原始图像

chepailujing=[pn fn] 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,'程序运行中,请稍等......') % for i=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;

for s=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, [110 55],'bilinear'); xiuzhengzimu = imresize(zi_mu, [110 55],'bilinear'); xiuzhengzm_sz_1= imresize(zm_sz_1,[110 55],'bilinear'); xiuzhengzm_sz_2 = imresize(zm_sz_2,[110 55],'bilinear'); xiuzhengshuzi_1 = imresize(shuzi_1,[110 55],'bilinear'); xiuzhengshuzi_2 = imresize(shuzi_2,[110 55],'bilinear'); xiuzhengshuzi_3 = imresize(shuzi_3,[110 55],'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 %%%记录程序运行时间

%============================================

自己编写的子函数

function bw_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

%去除左边边框干扰 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);

自己编写的子函数

function fenge = shuzifenge(imfenge,qingxiejiao) [y,x]=size(imfenge);

%===============用函数设定分割阈值======================== SS=x*y

if SS<=20000 shedingyuzhi=4;

elseif SS>20000&&SS<=30000 shedingyuzhi=4;

elseif SS>30000&&SS<=50000 shedingyuzhi=4;

elseif SS>50000&&SS<=80000 shedingyuzhi=4; else

shedingyuzhi=4; end

ganrao=SS/100;

%========================================================= %定义数组histogram存储垂直方向的黑点数 histogram=sum(~imfenge);

%=================文字分割============================= k=1;

for h=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值 if k<10

msgbox('提取出错','警告');

wavplay(wavread('提取出错.wav'),22000); pause;

end

%============================================== if

(sum(histogram(1,fenge(1,1):fenge(1,2)))

for i=3:k

fenge(1,i-2)=fenge(1,i); end end

[m n]=size(fenge); if n<14

msgbox('提取出错','警告');

wavplay(wavread('提取出错.wav'),22000); pause; end

fenge=fenge(1,1:14);

自己编写的子函数

function shibiezm_sz=shibiezm_sz(shuzizimu,xiuzhengzm_sz); [y,x,z]=size(xiuzhengzm_sz);

for k=1:34 sum=0; for i=1:y for j=1:x

if shuzizimu(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-15 ABCDE 16-20FGHIJ 21-25 KLMNP 26-30 QRSTU 31-35 VWXYZ if chepai==11 zm_sz='A'; elseif chepai==12 zm_sz='B'; elseif chepai==13 zm_sz='C'; elseif chepai==14 zm_sz='D'; elseif chepai==15 zm_sz='E'; elseif chepai==16 zm_sz='F'; elseif chepai==17 zm_sz='G'; elseif chepai==18 zm_sz='H'; elseif chepai==19 zm_sz='J'; elseif chepai==20

zm_sz='K'; elseif chepai==21 zm_sz='L'; elseif chepai==22 zm_sz='M'; elseif chepai==23 zm_sz='N'; elseif chepai==24 zm_sz='P'; elseif chepai==25 zm_sz='Q'; elseif chepai==26 zm_sz='R'; elseif chepai==27 zm_sz='S'; elseif chepai==28 zm_sz='T'; elseif chepai==29 zm_sz='U'; elseif chepai==30 zm_sz='V'; elseif chepai==31 zm_sz='W'; elseif chepai==32 zm_sz='X'; elseif chepai==33 zm_sz='Y'; elseif chepai==34

zm_sz='Z'; end end

shibiezm_sz=zm_sz;

自己编写的子函数

function shibiezm_sz=shibiezm_sz(shuzizimu,xiuzhengzm_sz); [y,x,z]=size(xiuzhengzm_sz);

for k=1:34 sum=0; for i=1:y for j=1:x

if shuzizimu(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-15 ABCDE 16-20FGHIJ 21-25 KLMNP 26-30 QRSTU 31-35 VWXYZ if chepai==11 zm_sz='A'; elseif chepai==12 zm_sz='B'; elseif chepai==13 zm_sz='C'; elseif chepai==14 zm_sz='D'; elseif chepai==15 zm_sz='E'; elseif chepai==16 zm_sz='F'; elseif chepai==17 zm_sz='G'; elseif chepai==18 zm_sz='H'; elseif chepai==19 zm_sz='J'; elseif chepai==20

zm_sz='K'; elseif chepai==21 zm_sz='L'; elseif chepai==22 zm_sz='M'; elseif chepai==23 zm_sz='N'; elseif chepai==24 zm_sz='P'; elseif chepai==25 zm_sz='Q'; elseif chepai==26 zm_sz='R'; elseif chepai==27 zm_sz='S'; elseif chepai==28 zm_sz='T'; elseif chepai==29 zm_sz='U'; elseif chepai==30 zm_sz='V'; elseif chepai==31 zm_sz='W'; elseif chepai==32 zm_sz='X'; elseif chepai==33 zm_sz='Y'; elseif chepai==34

zm_sz='Z'; end end

shibiezm_sz=zm_sz;

自己编写的子函数

function shibiezimu=shibiezimu(zimu,xiuzhengzimu); [y,x,z]=size(xiuzhengzimu); for k=1:24 sum=0; for i=1:y for j=1:x

if zimu(i,j,k)==xiuzhengzimu(i,j)%统计黑白 sum=sum+1; end end end

baifenbi(1,k)=sum/(x*y); end

chepai= find(baifenbi>=max(baifenbi));

shibiezimu=chepai;%在数字中,从0开始所以要减一。这里不用 if shibiezimu==1 shibiezimu='A'; elseif shibiezimu==2 shibiezimu='B'; elseif shibiezimu==3 shibiezimu='C'; elseif shibiezimu==4 shibiezimu='D'; elseif shibiezimu==5 shibiezimu='E'; elseif shibiezimu==6 shibiezimu='F'; elseif shibiezimu==7 shibiezimu='G'; elseif shibiezimu==8 shibiezimu='H'; elseif shibiezimu==9 shibiezimu='J'; elseif shibiezimu==10 shibiezimu='K'; elseif shibiezimu==11 shibiezimu='L'; elseif shibiezimu==12 shibiezimu='M'; elseif shibiezimu==13 shibiezimu='N'; elseif shibiezimu==14 shibiezimu='P';

elseif shibiezimu==15 shibiezimu='Q'; elseif shibiezimu==16 shibiezimu='R'; elseif shibiezimu==17 shibiezimu='S'; elseif shibiezimu==18 shibiezimu='T'; elseif shibiezimu==19 shibiezimu='U'; elseif shibiezimu==20 shibiezimu='V'; elseif shibiezimu==21 shibiezimu='W'; elseif shibiezimu==22 shibiezimu='X'; elseif shibiezimu==23 shibiezimu='Y'; elseif shibiezimu==24 shibiezimu='Z';

end

自己编写的子函数

function shibieshuzi=shibieshuzi(shuzi,xiuzhengshuzi_1); [y,x,z]=size(xiuzhengshuzi_1);

for k=1:10 sum=0; for i=1:y for j=1:x

if shuzi(i,j,k)==xiuzhengshuzi_1(i,j)%统计黑白 sum=sum+1; end end end

baifenbi(1,k)=sum/(x*y); end

chepai= find(baifenbi>=max(baifenbi)); shibieshuzi=chepai-1;

shibieshuzi=num2str(shibieshuzi);

自己编写的子函数

function shibiehanzi=shibiehanzi(hanzi,xiuzhenghanzi); [y,x,z]=size(xiuzhenghanzi); for k=1:5 sum=0; for i=1:y for j=1:x

if hanzi(i,j,k)==xiuzhenghanzi(i,j)%统计黑白 sum=sum+1; end end end

baifenbi(1,k)=sum/(x*y); end

chepai= find(baifenbi>=max(baifenbi));

shibiehanzi=chepai;%在数字中,从0开始所以要减一。这里不用 if shibiehanzi==1 shibiehanzi='桂'; elseif shibiehanzi==2 shibiehanzi='贵'; elseif shibiehanzi==3 shibiehanzi='京'; elseif shibiehanzi==4 shibiehanzi='苏'; elseif shibiehanzi==5 shibiehanzi='粤'; end

自己编写的子函数

function [PY2,PY1,PX2,PX1,threshold]=SEC_xiuzheng(PY2,PY1,PX2,PX1)

S=(PY2-PY1)*(PX2-PX1) if S<=25000 threshold=50; Y_secrectify=3; X_secrectify=3;

elseif S>25000&&S<=45000 threshold=100; Y_secrectify=-3; X_secrectify=3;

elseif S>45000&&S<=80000 threshold=200; Y_secrectify=-3; X_secrectify=3;

elseif S>80000&&S<=150000 threshold=300; Y_secrectify=-10; X_secrectify=-10;

elseif S>150000&&S<=400000 threshold=600; Y_secrectify=-10; X_secrectify=-10; else

threshold=1800; Y_secrectify=-10; X_secrectify=-10; end

PY1=PY1-Y_secrectify;%对车牌区域的进一步修正 PY2=PY2+Y_secrectify;%对车牌区域的进一步修正 PX1=PX1;%-X_secrectify;%对车牌区域的进一步修正 PX2=PX2;%+X_secrectify;%对车牌区域的进一步修正

自己编写的子函数

function qingxiejiao=rando_bianhuan(I) I=edge(I);%figure,imshow(I); % I = zeros(100,100); % I(25:75, 25:75) = 1; theta = 1:180;

[R,xp] = radon(I,theta);

%figure,imagesc(theta,xp,R);colormap(hot);%title('R_{\\theta} (X\\prime)')%%imshow(theta,xp,R,[],'n')

[I,J] = find(R>=max(max(R)));%J记录了倾斜角 qingxiejiao=90-J; %直线位置

% xlabel('\\theta (degrees)');ylabel('X\\prime');

% % colormap(hot)% colorbar IMAGE(C) displays matrix C as an image. % title('R_{\\theta} (X\\prime)'); % colorbar;

自己编写的子函数

function zimu = duquzimu(s10,s11,s12,s13,s14,s15,s16,s17,s18,s19,... s20,s21,s22,s23,s24,s25,s26,s27,s28,s29,... s30,s31,s32,s33)

%1-5 ABCDE 6-10FGHIJ 11-15 KLMNP 16-20 QRSTU 21-25 VWXYZ

zimu(:,:,1) =imresize(im2bw(s10,graythresh(rgb2gray(s10))),[110 55],'bilinear'); zimu(:,:,2) =imresize(im2bw(s11,graythresh(rgb2gray(s11))),[110 55],'bilinear'); zimu(:,:,3) =imresize(im2bw(s12,graythresh(rgb2gray(s12))),[110 55],'bilinear'); zimu(:,:,4) zimu(:,:,5) zimu(:,:,6) zimu(:,:,7) zimu(:,:,8) zimu(:,:,9) zimu(:,:,10) zimu(:,:,11) zimu(:,:,12) zimu(:,:,13) zimu(:,:,14) zimu(:,:,15) zimu(:,:,16) zimu(:,:,17) zimu(:,:,18) zimu(:,:,19) zimu(:,:,20) zimu(:,:,21) zimu(:,:,22) zimu(:,:,23) zimu(:,:,24)

=imresize(im2bw(s13,graythresh(rgb2gray(s13))),[110 55],'bilinear'); =imresize(im2bw(s14,graythresh(rgb2gray(s14))),[110 55],'bilinear'); =imresize(im2bw(s15,graythresh(rgb2gray(s15))),[110 55],'bilinear'); =imresize(im2bw(s16,graythresh(rgb2gray(s16))),[110 55],'bilinear'); =imresize(im2bw(s17,graythresh(rgb2gray(s17))),[110 55],'bilinear'); =imresize(im2bw(s18,graythresh(rgb2gray(s18))),[110 55],'bilinear'); =imresize(im2bw(s19,graythresh(rgb2gray(s19))),[110 55],'bilinear'); =imresize(im2bw(s20,graythresh(rgb2gray(s20))),[110 55],'bilinear'); =imresize(im2bw(s21,graythresh(rgb2gray(s21))),[110 55],'bilinear'); =imresize(im2bw(s22,graythresh(rgb2gray(s22))),[110 55],'bilinear'); =imresize(im2bw(s23,graythresh(rgb2gray(s23))),[110 55],'bilinear'); =imresize(im2bw(s24,graythresh(rgb2gray(s24))),[110 55],'bilinear'); =imresize(im2bw(s25,graythresh(rgb2gray(s25))),[110 55],'bilinear'); =imresize(im2bw(s26,graythresh(rgb2gray(s26))),[110 55],'bilinear'); =imresize(im2bw(s27,graythresh(rgb2gray(s27))),[110 55],'bilinear'); =imresize(im2bw(s28,graythresh(rgb2gray(s28))),[110 55],'bilinear'); =imresize(im2bw(s29,graythresh(rgb2gray(s29))),[110 55],'bilinear'); =imresize(im2bw(s30,graythresh(rgb2gray(s30))),[110 55],'bilinear'); =imresize(im2bw(s31,graythresh(rgb2gray(s31))),[110 55],'bilinear'); =imresize(im2bw(s32,graythresh(rgb2gray(s32))),[110 55],'bilinear'); =imresize(im2bw(s33,graythresh(rgb2gray(s33))),[110 55],'bilinear'); 自己编写的子函数

function shuzizimu = duquszzm(s1,s2,s3,s4,s5,s6,s7,s8,s9,s10,...

s11,s12,s13,s14,s15,s16,s17,s18,s19,s20,... s21,s22,s23,s24,s25,s26,s27,s28,s29,s30,... s31,s32,s33,s34) %0-9

-15 ABCDE 6-10FGHJK 16-20 LMNPQ 21-25 RSTUV 26-30 WXYZ

shuzizimu(:,:,1) =imresize(im2bw(s1, graythresh(rgb2gray(s1))), [110 55],'bilinear'); shuzizimu(:,:,2) =imresize(im2bw(s2, graythresh(rgb2gray(s2))), [110 55],'bilinear'); shuzizimu(:,:,3) shuzizimu(:,:,4) shuzizimu(:,:,5) shuzizimu(:,:,6) shuzizimu(:,:,7) shuzizimu(:,:,8) shuzizimu(:,:,9) shuzizimu(:,:,10) shuzizimu(:,:,11) shuzizimu(:,:,12) shuzizimu(:,:,13) shuzizimu(:,:,14) shuzizimu(:,:,15) shuzizimu(:,:,16) shuzizimu(:,:,17) shuzizimu(:,:,18) shuzizimu(:,:,19) shuzizimu(:,:,20) shuzizimu(:,:,21) shuzizimu(:,:,22) shuzizimu(:,:,23) shuzizimu(:,:,24) shuzizimu(:,:,25) shuzizimu(:,:,26) shuzizimu(:,:,27) shuzizimu(:,:,28) shuzizimu(:,:,29) shuzizimu(:,:,30) shuzizimu(:,:,31) shuzizimu(:,:,32) shuzizimu(:,:,33) shuzizimu(:,:,34)

=imresize(im2bw(s3, graythresh(rgb2gray(s3))), [110 55],'bilinear'); =imresize(im2bw(s4, graythresh(rgb2gray(s4))), [110 55],'bilinear'); =imresize(im2bw(s5, graythresh(rgb2gray(s5))), [110 55],'bilinear'); =imresize(im2bw(s6, graythresh(rgb2gray(s6))), [110 55],'bilinear'); =imresize(im2bw(s7, graythresh(rgb2gray(s7))), [110 55],'bilinear'); =imresize(im2bw(s8, graythresh(rgb2gray(s8))), [110 55],'bilinear'); =imresize(im2bw(s9, graythresh(rgb2gray(s9))), [110 55],'bilinear'); =imresize(im2bw(s10,graythresh(rgb2gray(s10))),[110 55],'bilinear'); =imresize(im2bw(s11,graythresh(rgb2gray(s11))),[110 55],'bilinear'); =imresize(im2bw(s12,graythresh(rgb2gray(s12))),[110 55],'bilinear'); =imresize(im2bw(s13,graythresh(rgb2gray(s13))),[110 55],'bilinear'); =imresize(im2bw(s14,graythresh(rgb2gray(s14))),[110 55],'bilinear'); =imresize(im2bw(s15,graythresh(rgb2gray(s15))),[110 55],'bilinear'); =imresize(im2bw(s16,graythresh(rgb2gray(s16))),[110 55],'bilinear'); =imresize(im2bw(s17,graythresh(rgb2gray(s17))),[110 55],'bilinear'); =imresize(im2bw(s18,graythresh(rgb2gray(s18))),[110 55],'bilinear'); =imresize(im2bw(s19,graythresh(rgb2gray(s19))),[110 55],'bilinear'); =imresize(im2bw(s20,graythresh(rgb2gray(s20))),[110 55],'bilinear'); =imresize(im2bw(s21,graythresh(rgb2gray(s21))),[110 55],'bilinear'); =imresize(im2bw(s22,graythresh(rgb2gray(s22))),[110 55],'bilinear'); =imresize(im2bw(s23,graythresh(rgb2gray(s23))),[110 55],'bilinear'); =imresize(im2bw(s24,graythresh(rgb2gray(s24))),[110 55],'bilinear'); =imresize(im2bw(s25,graythresh(rgb2gray(s25))),[110 55],'bilinear'); =imresize(im2bw(s26,graythresh(rgb2gray(s26))),[110 55],'bilinear'); =imresize(im2bw(s27,graythresh(rgb2gray(s27))),[110 55],'bilinear'); =imresize(im2bw(s28,graythresh(rgb2gray(s28))),[110 55],'bilinear'); =imresize(im2bw(s29,graythresh(rgb2gray(s29))),[110 55],'bilinear'); =imresize(im2bw(s30,graythresh(rgb2gray(s30))),[110 55],'bilinear'); =imresize(im2bw(s31,graythresh(rgb2gray(s31))),[110 55],'bilinear'); =imresize(im2bw(s32,graythresh(rgb2gray(s32))),[110 55],'bilinear'); =imresize(im2bw(s33,graythresh(rgb2gray(s33))),[110 55],'bilinear'); =imresize(im2bw(s34,graythresh(rgb2gray(s34))),[110 55],'bilinear'); 自己编写的函数

function shuzi=duqushuzi(s0,s1,s2,s3,s4,s5,s6,s7,s8,s9) %=======================彩色转灰度============

shuzi(:,:,1) =imresize(im2bw(rgb2gray(s0),graythresh(rgb2gray(s0))),[110 55],'bilinear'); shuzi(:,:,2) =imresize(im2bw(rgb2gray(s1),graythresh(rgb2gray(s1))),[110 55],'bilinear'); shuzi(:,:,3) =imresize(im2bw(rgb2gray(s2),graythresh(rgb2gray(s2))),[110 55],'bilinear'); shuzi(:,:,4) =imresize(im2bw(rgb2gray(s3),graythresh(rgb2gray(s3))),[110 55],'bilinear'); shuzi(:,:,5) =imresize(im2bw(rgb2gray(s4),graythresh(rgb2gray(s4))),[110 55],'bilinear'); shuzi(:,:,6) =imresize(im2bw(rgb2gray(s5),graythresh(rgb2gray(s5))),[110 55],'bilinear'); shuzi(:,:,7) shuzi(:,:,8) shuzi(:,:,9) shuzi(:,:,10)

=imresize(im2bw(rgb2gray(s6),graythresh(rgb2gray(s6))),[110 55],'bilinear'); =imresize(im2bw(rgb2gray(s7),graythresh(rgb2gray(s7))),[110 55],'bilinear'); =imresize(im2bw(rgb2gray(s8),graythresh(rgb2gray(s8))),[110 55],'bilinear'); =imresize(im2bw(rgb2gray(s9),graythresh(rgb2gray(s9))),[110 55],'bilinear');

PX1 ,PX2

%========================================================= a=PY2-PY1+1;b=PX2-PX1+1; White=0; for i=PY1:PY2

for j=PX1:PX2

if (std([myI(i,j,1) myI(i,j,2)

myI(i,j,3)],1,2)<=22)&&(myI(i,j,1)>=90)&&(myI(i,j,1)<=255)

White= White+1; % 白色象素点统计 end end end

baisebili=White/(a*b) changkuanbi=a/b k=k+1

%===========================蓝色区域不是车牌区域================= elseif (k~=0)

Blue_y(PY1:PY2,1)=0;

[temp MaxY]=max(Blue_y);

if temp<=20 48*1536 照相

msgbox('车牌定位出错','warning');

wavplay(wavread('车牌定位出错.wav'),22000); pause; end

PY1=MaxY;

while ((Blue_y(PY1,1)>=Y_threshlow)&&(PY1>1))%找到图片上边界 %阈值为5 PY1=PY1-1; end

%PY1:存储车牌上边界值 PY2=MaxY;

while ((Blue_y(PY2,1)>=Y_threshlow)&&(PY2

%==============2次寻找X方向===============================

X_threshhigh=(PY2-PY1)/15;%这个数值很重要。决定了提取的彩图的质量,适当提高可抗干扰,但是小图会照成剪裁太多,ganrao

Blue_x=zeros(1,x); % 进一步确定X方向的车牌区域 for j=1:x

for i=PY1:PY2

if((myI(i,j,1)<=45)&&((myI(i,j,2)<=90)&&(myI(i,j,2)>=20))&&((myI(i,j,3)<=160)&&(myI(i,j,3)>=80)))

Blue_x(1,j)= Blue_x(1,j)+1; end end end

%这里修改成了从中间向两边扩展,这个方法不好。因车牌中间某些位置可能出现断层。 %采用增强型两边往中间收缩。

[temp MaxX]=max(Blue_x); PX1=MaxX-6*(PY2-PY1); if PX1<=1 PX1=1; end

while ((Blue_x(1,PX1)<=X_threshhigh)&&(PX1

end %确定出X方向车牌起点 PX2=MaxX+6*(PY2-PY1); if PX2>=x PX2=x; end

while ((Blue_x(1,PX2)<=X_threshhigh)&&(PX2>PX1))%阈值 PX2=PX2-1;

end%确定出X方向车牌终点 % PX1=1;

% while ((Blue_x(1,PX1)<=X_threshhigh)&&(PX1

% while ((Blue_x(1,PX2)PX1))%阈值 % PX2=PX2-1; % end PX1 ,PX2

%========================================================= a=PY2-PY1+1;b=PX2-PX1+1; White=0; for i=PY1:PY2

for j=PX1:PX2

if (std([myI(i,j,1) myI(i,j,2)

myI(i,j,3)],1,2)<=16)&&(myI(i,j,1)>=90)&&(myI(i,j,1)<=255)

White= White+1; % 白色象素点统计 end end end

baisebili=White/(a*b) changkuanbi=a/b

k=k+1 end end

%======================================================== Y_firrectify=fix((PY2-PY1)/5);%适当扩大这个值可以正确旋转 PY1=PY1-Y_firrectify;%对车牌区域的修正,向上 PY2=PY2+Y_firrectify;%对车牌区域的修正,向下 % IY=I(PY1:PY2,:,:);%在Y方向对图片截取 PX1=PX1-X_firrectify;% 对车牌区域的修正 PX2=PX2+X_firrectify;% 对车牌区域的修正,

本文来源:https://www.bwwdw.com/article/84ff.html

Top