%%%打开图像
clc
[filename, pathname]=uigetfile('*.jpg', 'File Selector');
I=imread([pathname '\' filename]);%括号括起来就是把这个看成一个路径
handles.I=I;
figure(1)
imshow(I);title('原图');
%%灰度,腐蚀
YuanShi=handles.I;
YuanShiHuiDu=rgb2gray(YuanShi);%转化为灰度图像
figure(2)
imshow(YuanShiHuiDu);
title('灰度图')
BianYuan=edge(YuanShiHuiDu,'canny',0.2);%Canny算子边缘检测
%BianYuan=edge(YuanShiHuiDu,'roberts',0.2,'both');
figure(3)
imshow(BianYuan);
title('边缘')
handles.BianYuan=BianYuan;
%%%%腐蚀
BianYuan=handles.BianYuan
se1=[1;1;1]; %线型结构元素
FuShi=imerode(BianYuan,se1); %腐蚀图像
figure(4)
imshow(FuShi);
title('腐蚀')
handles.FuShi=FuShi;mainfc;
se2=strel('rectangle',[25,25]); %矩形结构元素
TianChong=imclose(FuShi,se2);%图像聚类、填充图像
YuanShiLvBo=bwareaopen(TianChong,2000);%从对象中移除面积小于2000的小对象
figure(5)
imshow(YuanShiLvBo);
title('去除干扰')
handles.YuanShiLvBo=YuanShiLvBo
%%%%%%定位
YuanShiLvBo=handles.YuanShiLvBo
[y,x]=size(YuanShiLvBo);%size函数将数组的行数返回到第一个输出变量,将数组的列数返回到第二个输出变量
YuCuDingWei=double(YuanShiLvBo);
%%%%%%%%%2.确定行的起始位置和终止位置%%%%%%%%%%%
Y1=zeros(y,1);%产生y行全零数组
for i=1:y
for j=1:x
if(YuCuDingWei(i,j)==1)
Y1(i,1)= Y1(i,1)+1;%白色像素点统计
end
end
end
[temp,MaxY]=max(Y1);%Y方向车牌区域确定。返回行向量temp和MaxY,temp向量记录Y1的每列的最大值,MaxY向量记录Y1每列最大值的行号
PY1=MaxY;
while ((Y1(PY1,1)>=50)&&(PY1>1))%从最高点开始向两侧找边界
PY1=PY1-1;
end
PY2=MaxY;
while ((Y1(PY2,1)>=50)&&(PY2<y))
PY2=PY2+1;
end
YuanShi=handles.I
IY=YuanShi(PY1:PY2,:,:);
%%%%%%%%%%车牌粗定位之二确定列的起始位置和终止位置%%%%%%%%%%%
%%%%%%%%%%和列分割不同这个是从两边向中间找%%%%%%%%%%%%%%
X1=zeros(1,x);%产生1行x列全零数组
for j=1:x
for i=PY1:PY2
if(YuCuDingWei(i,j,1)==1)
X1(1,j)= X1(1,j)+1;
end
end
end
PX1=1;
while ((X1(1,PX1)<3)&&(PX1<x))
PX1=PX1+1;
end
PX3=x;
while ((X1(1,PX3)<3)&&(PX3>PX1))
PX3=PX3-1;
end
CuDingWei=YuanShi(PY1:PY2,PX1+10:PX3-10,:);%待定
figure(6)
imshow(CuDingWei);
title('定位图')
%%%%%%%%%%2.3、车牌精定位之一预处理%%%%%%%%%%%
CuDingWeiHuiDu=rgb2gray(CuDingWei); %将RGB图像转化为灰度图像
figure(7)
imshow(CuDingWeiHuiDu);
title('车牌灰度图')
c_max=double(max(max(CuDingWeiHuiDu)));
c_min=double(min(min(CuDingWeiHuiDu)));
T=round(c_max-(c_max-c_min)/3); %T为二值化的阈值
CuDingWeiErZhi=im2bw(CuDingWeiHuiDu,T/256);
figure(8)
imshow(CuDingWeiErZhi);
title('车牌二值图')
CuDingWeiErZhi=bwareaopen(CuDingWeiErZhi,20);
CuDingWeiErZhi(: ,PX3)=0;
CuDingWeiErZhi=bwareaopen(CuDingWeiErZhi,100);
CuDingWeiErZhi=lvbo(CuDingWeiErZhi);
handles.CuDingWeiErZhi=CuDingWeiErZhi
%%%定位
CuDingWeiErZhi=handles.CuDingWeiErZhi
ChePaiLvBo=CuDingWeiErZhi;%logical()
BianYuan=handles.BianYuan
ChePaiYuFenGe=double(ChePaiLvBo);
[p,q]=size(ChePaiYuFenGe);
X3=zeros(1,q);%产生1行q列全零数组
for j=1:q
for i=1:p
if(ChePaiYuFenGe(i,j)==1)
X3(1,j)=X3(1,j)+1;
end
end
end
%%%%%%%%%%3.2、字符分割%%%%%%%%%%%p高q宽,倒序分割
Px0=q;%字符右侧限
Px1=q;%字符左侧限
for i=1:6
while((X3(1,Px0)<3)&&(Px0>0))
Px0=Px0-1;
end
Px1=Px0;
while( ( (X3(1,Px1) >=3) ) && (Px1>0) || ((Px0-Px1)<25) )%要求一个字符大于15个像素
Px1=Px1-1;
end
ChePaiFenGe=ChePaiLvBo(:,Px1:Px0,:);%得到一个第一个字符(右侧)
ii=int2str(8-i);%命名
imwrite(ChePaiFenGe,strcat(ii,'.jpg'));%strcat连接字符串。保存字符图像。
Px0=Px1;
end
PX3=Px1;%字符1右侧限
while((X3(1,PX3)<3)&&(PX3>0))
PX3=PX3-1;
end
ZiFu1DingWei=ChePaiYuFenGe(:,1:PX3,:);
%subplot(1,7,1);imshow(ZiFu1DingWei);
imwrite(ZiFu1DingWei,'1.jpg');
%%%%%%%%%%%%%%读取分割完成的字符%%%%%%%%%%%%%%%%%%%%%%%%
ZiFu1=imresize(im2bw(imread('1.jpg'),graythresh(imread('1.jpg'))), [40 20],'bilinear');
ZiFu2=imresize(im2bw(imread('2.jpg'),graythresh(imread('2.jpg'))), [40 20],'bilinear');
ZiFu3=imresize(im2bw(imread('3.jpg'),graythresh(imread('3.jpg'))), [40 20],'bilinear');
ZiFu4=imresize(im2bw(imread('4.jpg'),graythresh(imread('4.jpg'))), [40 20],'bilinear');
ZiFu5=imresize(im2bw(imread('5.jpg'),graythresh(imread('5.jpg'))), [40 20],'bilinear');
ZiFu6=imresize(im2bw(imread('6.jpg'),graythresh(imread('6.jpg'))), [40 20],'bilinear');
ZiFu7=imresize(im2bw(imread('7.jpg'),graythresh(imread('7.jpg'))), [40 20],'bilinear');
figure(9)
subplot(171)
imshow(ZiFu1);
subplot(172)
imshow(ZiFu2);
subplot(173)
imshow(ZiFu3);
subplot(174)
imshow(ZiFu4);
subplot(175)
imshow(ZiFu5);
subplot(176);
imshow(ZiFu6);
subplot(177);
imshow(ZiFu7);
handles.ZiFu1=ZiFu1
handles.ZiFu2=ZiFu2
handles.ZiFu3=ZiFu3
handles.ZiFu4=ZiFu4
handles.ZiFu5=ZiFu5
handles.ZiFu6=ZiFu6
handles.ZiFu7=ZiFu7
%%%%%%%识别
ZiFu1=handles.ZiFu1
ZiFu2=handles.ZiFu2
ZiFu3=handles.ZiFu3
ZiFu4=handles.ZiFu4
ZiFu5=handles.ZiFu5
ZiFu6=handles.ZiFu6
ZiFu7=handles.ZiFu7
%%%%%%%%%%%把0-9,A-Z以及省份简称的数据存储方便访问%%%%%%%%%%%
HanZi=ReadCharacter(imread('Chinesecharacter\藏.jpg'),imread('Chinesecharacter\川.jpg'),imread('Chinesecharacter\鄂.jpg'),...
imread('Chinesecharacter\贵.jpg'),imread('Chinesecharacter\黑.jpg'), imread('Chinesecharacter\吉.jpg'),...
imread('Chinesecharacter\冀.jpg'),imread('Chinesecharacter\津.jpg'),imread('Chinesecharacter\晋.jpg'),...
imread('Chinesecharacter\京.jpg'),imread('Chinesecharacter\辽.jpg'),imread('Chinesecharacter\鲁.jpg'),...
imread('Chinesecharacter\闽.jpg'),imread('Chinesecharacter\琼.jpg'),imread('Chinesecharacter\陕.jpg'),...
imread('Chinesecharacter\苏.jpg'),imread('Chinesecharacter\皖.jpg'),imread('Chinesecharacter\湘.jpg'),...
imread('Chinesecharacter\豫.jpg'),imread('Chinesecharacter\粤.jpg'),imread('Chinesecharacter\云.jpg'),...
imread('Chinesecharacter\浙.jpg'));
ShuZiZiMu=ReadStringNumber(imread('E and N character\0.jpg'),imread('E and N character\1.jpg'),imread('E and N character\2.jpg'),...
imread('E and N character\3.jpg'),imread('E and N character\4.jpg'),imread('E and N character\5.jpg'),...
imread('E and N character\6.jpg'),imread('E and N character\7.jpg'),imread('E and N character\8.jpg'),...
imread('E and N character\9.jpg'),imread('E and N character\A.jpg'),imread('E and N character\B.jpg'),...
imread('E and N character\C.jpg'),imread('E and N character\D.jpg'),imread('E and N character\E.jpg'),...
imread('E and N character\F.jpg'),imread('E and N character\G.jpg'),imread('E and N character\H.jpg'),...
imread('E and N character\J.jpg'),imread('E and N character\K.jpg'),imread('E and N character\L.jpg'),...
imread('E and N character\M.jpg'),imread('E and N character\N.jpg'),imread('E and N character\P.jpg'),...
imread('E and N character\Q.jpg'),imread('E and N character\R.jpg'),imread('E and N character\S.jpg'),...
imread('E and N character\T.jpg'),imread('E and N character\U.jpg'),imread('E and N character\V.jpg'),...
imread('E and N character\W.jpg'),imread('E and N character\X.jpg'),imread('E and N character\Y.jpg'),...
imread('E and N character\Z.jpg'));
%%%%%%%%%%%4.3、车牌字符识别%%%%%%%%%%%
%%%%%%%%%%%第一位一定为汉字,两个矩阵相减%%%%%%%%%%%
store1=strcat('藏','川','鄂','贵','黑','吉','冀','津','京','晋','辽','鲁','闽','琼','陕','苏','皖','湘','豫','粤','云','浙'); %创建汉字识别模板库
ShiBieJieGuo=[];
for j=1:22
Im=ZiFu1;
Template= HanZi(:,:,j);
Differ=Im-Template;
Compare(j)=sum(sum(abs(Differ)));
end
index=find(Compare==(min(Compare)));
index;
ShiBieJieGuo=[ShiBieJieGuo store1(index)];
store2=strcat('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z'); %创建字母与数字识别模板库
for j=1:34
Im=ZiFu2;
Template=ShuZiZiMu(:,:,j);
Differ=Im-Template;
Compare(j)=sum(sum(abs(Differ)));
end
index=find(C
没有合适的资源?快使用搜索试试~ 我知道了~
基于MATLAB车牌识别程序技术实现【带界面GUI】.zip
共106个文件
jpg:100个
m:5个
p:1个
需积分: 5 0 下载量 108 浏览量
2024-11-04
19:35:17
上传
评论
收藏 203KB ZIP 举报
温馨提示
matlab
资源推荐
资源详情
资源评论
收起资源包目录
基于MATLAB车牌识别程序技术实现【带界面GUI】.zip (106个子文件)
测试.jpg 85KB
2.jpg 2KB
N.jpg 2KB
R.jpg 2KB
B.jpg 2KB
P.jpg 2KB
0.jpg 2KB
A.jpg 2KB
8.jpg 2KB
D.jpg 2KB
Q.jpg 2KB
7.jpg 2KB
4.jpg 2KB
N.jpg 2KB
R.jpg 2KB
B.jpg 2KB
P.jpg 2KB
A.jpg 2KB
D.jpg 2KB
Q.jpg 2KB
辽.jpg 2KB
粤.jpg 2KB
鄂.jpg 2KB
津.jpg 2KB
闽.jpg 2KB
云.jpg 2KB
陕.jpg 2KB
吉.jpg 2KB
鲁.jpg 2KB
豫.jpg 2KB
2.jpg 2KB
0.jpg 2KB
8.jpg 2KB
7.jpg 2KB
4.jpg 2KB
6.jpg 2KB
2.jpg 1KB
S.jpg 1KB
S.jpg 1KB
3.jpg 1KB
3.jpg 1KB
W.jpg 1KB
W.jpg 1KB
9.jpg 1KB
9.jpg 1KB
X.jpg 1KB
X.jpg 1KB
1.jpg 1KB
5.jpg 1KB
5.jpg 1KB
4.jpg 1KB
G.jpg 1KB
G.jpg 1KB
3.jpg 1KB
6.jpg 1KB
6.jpg 1KB
川.jpg 1KB
V.jpg 1KB
V.jpg 1KB
C.jpg 1KB
C.jpg 1KB
K.jpg 1KB
K.jpg 1KB
7.jpg 1KB
Z.jpg 1KB
Z.jpg 1KB
藏.jpg 1KB
琼.jpg 1KB
湘.jpg 1KB
贵.jpg 1KB
黑.jpg 1KB
冀.jpg 1KB
晋.jpg 1KB
京.jpg 1KB
Y.jpg 1KB
Y.jpg 1KB
M.jpg 1KB
M.jpg 1KB
浙.jpg 1KB
苏.jpg 1KB
皖.jpg 1022B
U.jpg 998B
U.jpg 998B
E.jpg 967B
E.jpg 967B
5.jpg 965B
J.jpg 957B
J.jpg 957B
F.jpg 940B
F.jpg 940B
aaa.jpg 824B
z.jpg 824B
T.jpg 804B
T.jpg 804B
L.jpg 796B
L.jpg 796B
H.jpg 787B
H.jpg 787B
1.jpg 638B
1.jpg 535B
共 106 条
- 1
- 2
资源评论
远望清一色
- 粉丝: 234
- 资源: 28
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功