资源简介

本程序是基于MATLAB做的车牌识别的源代码,车牌识别效果还挺不错的。

资源截图

代码片段和文件信息

close all
clc
[fnpnfi]=uigetfile(‘ChePaiKu\*.jpg‘‘选择图片‘);
YuanShi=imread([pn fn]);%输入原始图像
figure(1);subplot(321)imshow(YuanShi)title(‘原始图像‘);
%%%%%%%%%%1、图像预处理%%%%%%%%%%%
YuanShiHuiDu=rgb2gray(YuanShi);%转化为灰度图像
subplot(322)imshow(YuanShiHuiDu)title(‘灰度图像‘);

BianYuan=edge(YuanShiHuiDu‘canny‘0.5);%Canny算子边缘检测
subplot(323)imshow(BianYuan)title(‘Canny算子边缘检测后图像‘);

se1=[1;1;1]; %线型结构元素 
FuShi=imerode(BianYuanse1);    %腐蚀图像
subplot(324)imshow(FuShi)title(‘腐蚀后边缘图像‘);

se2=strel(‘rectangle‘[2525]); %矩形结构元素
TianChong=imclose(FuShise2);%图像聚类、填充图像
subplot(325)imshow(TianChong)title(‘填充后图像‘);

YuanShiLvBo=bwareaopen(TianChong2000);%从对象中移除面积小于2000的小对象
figure(2);
subplot(221)imshow(YuanShiLvBo)title(‘形态滤波后图像‘);
%%%%%%%%%%2、车牌定位%%%%%%%%%%%
[yx]=size(YuanShiLvBo);%size函数将数组的行数返回到第一个输出变量,将数组的列数返回到第二个输出变量
YuCuDingWei=double(YuanShiLvBo);
%%%%%%%%%%2.1、车牌粗定位之一确定行的起始位置和终止位置%%%%%%%%%%%
Y1=zeros(y1);%产生y行1列全零数组
for i=1:y
    for j=1:x
        if(YuCuDingWei(ij)==1)
            Y1(i1)= Y1(i1)+1;%白色像素点统计
        end
    end
end
[tempMaxY]=max(Y1);%Y方向车牌区域确定。返回行向量temp和MaxY,temp向量记录Y1的每列的最大值,MaxY向量记录Y1每列最大值的行号
subplot(222)plot(0:y-1Y1)title(‘原图行方向像素点值累计和‘)xlabel(‘行值‘)ylabel(‘像素‘); 
PY1=MaxY;
while ((Y1(PY11)>=50)&&(PY1>1))
        PY1=PY1-1;
end
PY2=MaxY;
while ((Y1(PY21)>=50)&&(PY2        PY2=PY2+1;
end
IY=YuanShi(PY1:PY2::);
%%%%%%%%%%2.2、车牌粗定位之二确定列的起始位置和终止位置%%%%%%%%%%%
X1=zeros(1x);%产生1行x列全零数组
for j=1:x
    for i=PY1:PY2
        if(YuCuDingWei(ij1)==1)
                X1(1j)= X1(1j)+1;               
         end  
    end       
end
subplot(224)plot(0:x-1X1)title(‘原图列方向像素点值累计和‘)xlabel(‘列值‘)ylabel(‘像数‘);
PX1=1;
while ((X1(1PX1)<3)&&(PX1       PX1=PX1+1;
end    
PX3=x;
while ((X1(1PX3)<3)&&(PX3>PX1))
        PX3=PX3-1;
end
CuDingWei=YuanShi(PY1:PY2PX1:PX3:);
subplot(223)imshow(CuDingWei)title(‘粗定位后的彩色车牌图像‘)
%%%%%%%%%%2.3、车牌精定位之一预处理%%%%%%%%%%%
CuDingWeiHuiDu=rgb2gray(CuDingWei); %将RGB图像转化为灰度图像
c_max=double(max(max(CuDingWeiHuiDu)));
c_min=double(min(min(CuDingWeiHuiDu)));
T=round(c_max-(c_max-c_min)/3); %T为二值化的阈值
CuDingWeiErZhi=im2bw(CuDingWeiHuiDuT/256);
figure(3);
subplot(221)imshow(CuDingWeiErZhi)title(‘粗定位的二值车牌图像‘)%DingWei
%%%%%%%%%%2.4、车牌精定位之二去除边框干扰%%%%%%%%%%%
[rs]=size(CuDingWeiErZhi);%size函数将数组的行数返回到第一个输出变量,将数组的列数返回到第二个输出变量
YuJingDingWei=double(CuDingWeiErZhi);%;CuDingWeiErZhi
X2=zeros(1s);%产生1行s列全零数组
for i=1:r
    for j=1:s
        if(YuJingDingWei(ij)==1)
            X2(1j)= X2(1j)+1;%白色像素点统计
        end
    end
end
[tempMaxX]=max(X2);
subplot(222)plot(0:s-1X2)title(‘粗定位车牌图像列方向像素点值累计和‘)xlabel(‘列值‘)ylabel(‘像素‘);
%%%%%%%%%%2.4.1、去除左侧边框干扰%%%%%%%%%%%
[gh]=size(YuJingDingWei);
ZuoKuanDu=0;YouKuanDu=0;KuanDuYuZhi=5;
while sum(YuJingDingWei(:ZuoKuanDu+1))~=0
    ZuoKuanDu=ZuoKuanDu+1;
end
if ZuoKuanDu    YuJingDingWei(:[1:ZuoKuanDu])=0;%给图像d中1到KuanDu宽

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\
     文件        1087  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\1.jpg
     文件        1144  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\2.jpg
     文件         950  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\3.jpg
     文件         915  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\4.jpg
     文件        1152  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\5.jpg
     文件        1123  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\6.jpg
     文件        1055  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\7.jpg
     文件        9708  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePai.m
     目录           0  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePaiKu\
     文件      297775  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePaiKu\1 (1).jpg
     文件      193538  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePaiKu\1 (2).jpg
     文件      141053  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePaiKu\1 (3).jpg
     文件       59186  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePaiKu\2 (1).jpg
     文件      282855  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\ChePaiKu\2 (2).jpg
     文件          32  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\Data.xls
     文件         743  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\DuQuHanZi.m
     文件        3368  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\DuQuSZZM.m
     文件        1033  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\DuQuShuZi.m
     文件        2273  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\DuQuZiMu.m
     目录           0  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\
     文件       34710  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\0.BMP
     文件       18630  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\1.BMP
     文件       47574  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\10.BMP
     文件       68934  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\11.BMP
     文件       39114  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\12.BMP
     文件       72762  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\13.BMP
     文件       33342  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\14.BMP
     文件       45198  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\15.BMP
     文件       41502  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\16.BMP
     文件        4278  2013-07-05 12:12  License-Plate-Recognition-by-MATLAB-master\MuBanKu\17.BMP
............此处省略38个文件信息

评论

共有 条评论