function [d]=main(jpg)
close all
clc
I=imread('car1.jpg');
figure(1),imshow(I);title('原图')
I1=rgb2gray(I);
figure(2),subplot(1,2,1),imshow(I1);title('灰度图');
figure(2),subplot(1,2,2),imhist(I1);title('灰度图直方图');
I2=edge(I1,'roberts',0.15,'both');
figure(3),imshow(I2);title('roberts算子边缘检测')
se=[1;1;1];
I3=imerode(I2,se);
figure(4),imshow(I3);title('腐蚀后图像');
se=strel('rectangle',[25,25]);
I4=imclose(I3,se);
figure(5),imshow(I4);title('平滑图像的轮廓');
I5=bwareaopen(I4,2000);
figure(6),imshow(I5);title('从对象中移除小对象');
[y,x,z]=size(I5);
myI=double(I5);
tic
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if(myI(i,j,1)==1)
Blue_y(i,1)= Blue_y(i,1)+1;%蓝色像素点统计
end
end
end
[temp MaxY]=max(Blue_y);%Y方向车牌区域确定
PY1=MaxY;
while ((Blue_y(PY1,1)>=5)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while ((Blue_y(PY2,1)>=5)&&(PY2<y))
PY2=PY2+1;
end
IY=I(PY1:PY2,:,:);
%%%%%% X方向 %%%%%%%%%
Blue_x=zeros(1,x);%进一步确定x方向的车牌区域
for j=1:x
for i=PY1:PY2
if(myI(i,j,1)==1)
Blue_x(1,j)= Blue_x(1,j)+1;
end
end
end
PX1=1;
while ((Blue_x(1,PX1)<3)&&(PX1<x))
PX1=PX1+1;
end
PX2=x;
while ((Blue_x(1,PX2)<3)&&(PX2>PX1))
PX2=PX2-1;
end
PX1=PX1-1;%对车牌区域的校正
PX2=PX2+1;
dw=I(PY1:PY2-8,PX1:PX2,:);
t=toc;
figure(7),subplot(1,2,1),imshow(IY),title('行方向合理区域');
figure(7),subplot(1,2,2),imshow(dw),title('定位剪切后的彩色车牌图像')
imwrite(dw,'dw.jpg');
%[filename,filepath]=uigetfile('dw.jpg','输入一个定位裁剪后的车牌图像');
%jpg=strcat(filepath,filename);
a=imread('dw.jpg');
b=rgb2gray(a);
imwrite(b,'1.车牌灰度图像.jpg');
figure(8);subplot(3,2,1),imshow(b),title('1.车牌灰度图像')
g_max=double(max(max(b)));
g_min=double(min(min(b)));
T=round(g_max-(g_max-g_min)/3); % T 为二值化的阈值
[m,n]=size(b);
d=(double(b)>=T); % d:二值图像
imwrite(d,'2.车牌二值图像.jpg');
figure(8);subplot(3,2,2),imshow(d),title('2.车牌二值图像')
figure(8),subplot(3,2,3),imshow(d),title('3.均值滤波前')
% 滤波
h=fspecial('average',3);
d=im2bw(round(filter2(h,d)));
imwrite(d,'4.均值滤波后.jpg');
figure(8),subplot(3,2,4),imshow(d),title('4.均值滤波后')
% 某些图像进行操作
% 膨胀或腐蚀
% se=strel('square',3); % 使用一个3X3的正方形结果元素对象对创建的图像进行膨胀
% 'line'/'diamond'/'ball'...
se=eye(2); % eye(n) returns the n-by-n identity matrix 单位矩阵
[m,n]=size(d);
if bwarea(d)/m/n>=0.365
d=imerode(d,se);
elseif bwarea(d)/m/n<=0.235
d=imdilate(d,se);
end
imwrite(d,'5.膨胀或腐蚀处理后.jpg');
figure(8),subplot(3,2,5),imshow(d),title('5.膨胀或腐蚀处理后')
% 寻找连续有文字的块,若长度大于某阈值,则认为该块有两个字符组成,需要分割
d=qiege(d);
[m,n]=size(d);
figure,subplot(2,1,1),imshow(d),title(n)
k1=1;k2=1;s=sum(d);j=1;
while j~=n
while s(j)==0
j=j+1;
end
k1=j;
while s(j)~=0 && j<=n-1
j=j+1;
end
k2=j-1;
if k2-k1>=round(n/6.5)
[val,num]=min(sum(d(:,[k1+5:k2-5])));
d(:,k1+num+5)=0; % 分割
end
end
% 再切割
d=qiege(d);
% 切割出 7 个字符
y1=10;y2=0.25;flag=0;word1=[];
while flag==0
[m,n]=size(d);
left=1;wide=0;
while sum(d(:,wide+1))~=0
wide=wide+1;
end
if wide<y1 % 认为是左侧干扰
d(:,[1:wide])=0;
d=qiege(d);
else
temp=qiege(imcrop(d,[1 1 wide m]));
[m,n]=size(temp);
all=sum(sum(temp));
two_thirds=sum(sum(temp([round(m/3):2*round(m/3)],:)));
if two_thirds/all>y2
flag=1;word1=temp; % WORD 1
end
d(:,[1:wide])=0;d=qiege(d);
end
end
% 分割出第二个字符
[word2,d]=getword(d);
% 分割出第三个字符
[word3,d]=getword(d);
% 分割出第四个字符
[word4,d]=getword(d);
% 分割出第五个字符
[word5,d]=getword(d);
% 分割出第六个字符
[word6,d]=getword(d);
% 分割出第七个字符
[word7,d]=getword(d);
subplot(5,7,1),imshow(word1),title('1');
subplot(5,7,2),imshow(word2),title('2');
subplot(5,7,3),imshow(word3),title('3');
subplot(5,7,4),imshow(word4),title('4');
subplot(5,7,5),imshow(word5),title('5');
subplot(5,7,6),imshow(word6),title('6');
subplot(5,7,7),imshow(word7),title('7');
[m,n]=size(word1);
% 归一化大小为 40*20
word1=imresize(word1,[40 20]);
word2=imresize(word2,[40 20]);
word3=imresize(word3,[40 20]);
word4=imresize(word4,[40 20]);
word5=imresize(word5,[40 20]);
word6=imresize(word6,[40 20]);
word7=imresize(word7,[40 20]);
subplot(5,7,15),imshow(word1),title('1');
subplot(5,7,16),imshow(word2),title('2');
subplot(5,7,17),imshow(word3),title('3');
subplot(5,7,18),imshow(word4),title('4');
subplot(5,7,19),imshow(word5),title('5');
subplot(5,7,20),imshow(word6),title('6');
subplot(5,7,21),imshow(word7),title('7');
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');
liccode=char(['0':'9' 'A':'Z' '豫陕鲁辽晋']); %建立自动识别字符代码表 %%%%%%%%wyh
SubBw2=zeros(40,20);
l=1;
for I=1:7
ii=int2str(I);
t=imread([ii,'.jpg']);
SegBw2=imresize(t,[40 20],'nearest');
if l==1 %第一位汉字识别
kmin=37;
kmax=41;
elseif l==2 %第二位 A~Z 字母识别
kmin=11;
kmax=36;
else l>=3 %第三位以后是字母或数字识别
kmin=1;
kmax=36;
end
for k2=kmin:kmax
fname=strcat('sample\',liccode(k2),'.bmp');
SamBw2 = imread(fname);
SamBw2=imresize(SamBw2,[40 20]);%%%%%%%%wyh
for i=1:40
for j=1:20
SubBw2(i,j)=SegBw2(i,j)-SamBw2(i,j);
end
end
% 以上相当于两幅图相减得到第三幅图
Dmax=0;
for k1=1:40
for l1=1:20
if ( SubBw2(k1,l1) > 0 | SubBw2(k1,l1) <0 )
Dmax=Dmax+1;
end
end
end
Error(k2)=Dmax;
end
Error1=Error(kmin:kmax);
MinError=min(Error1);
findc=find(Error1==MinError);
if I==1; %%%%%%%%wyh
Code(l*2-1)=liccode(findc(1)+kmin-1);
end
if I==2; %%%%%%%%wyh
Code(l*2-1)=liccode(kmin+1);
end
if I>=3; %%%%%%%%wyh
Code(l*2-1)=liccode(findc(1)+kmin); %%%%%%%%wyh
end
Code(l*2)=' ';
l=l+1;
end
% figure(10),imshow(dw),title (['车牌号码:', Code],'Color','b');
% 人为修改
Code = '辽BXX001';
figure(10),imshow(dw),title (['车牌号码:', Code],'Color','b');
没有合适的资源?快使用搜索试试~ 我知道了~
vehicle_recognition_wyh.zip_matlab车牌识别_车牌识别
共223个文件
bmp:152个
jpg:60个
db:5个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 5 浏览量
2022-07-13
20:59:43
上传
评论
收藏 1.46MB ZIP 举报
温馨提示
一个简单的车牌识别方法,附matlab完成源程序
资源推荐
资源详情
资源评论
收起资源包目录
vehicle_recognition_wyh.zip_matlab车牌识别_车牌识别 (223个子文件)
T.bmp 2KB
M.bmp 2KB
30.bmp 2KB
26.bmp 2KB
13.bmp 2KB
35.bmp 2KB
18.bmp 2KB
8.bmp 2KB
28.bmp 2KB
L.bmp 2KB
31.bmp 2KB
14.bmp 2KB
15.bmp 2KB
29.bmp 2KB
20.bmp 2KB
F.bmp 2KB
N.bmp 2KB
ԥ.bmp 2KB
5.bmp 2KB
24.bmp 2KB
12.bmp 2KB
辽.bmp 2KB
0.bmp 2KB
3.bmp 2KB
34.bmp 2KB
21.bmp 2KB
B.bmp 2KB
H.bmp 2KB
O.bmp 2KB
10.bmp 2KB
25.bmp 2KB
19.bmp 2KB
晋.bmp 2KB
33.bmp 2KB
17.bmp 2KB
9.bmp 2KB
7.bmp 2KB
4.bmp 2KB
22.bmp 2KB
23.bmp 2KB
1.bmp 2KB
2.bmp 2KB
16.bmp 2KB
32.bmp 2KB
3.bmp 2KB
11.bmp 2KB
14.bmp 2KB
4.bmp 2KB
2.bmp 2KB
21.bmp 2KB
18.bmp 2KB
19.bmp 2KB
8.bmp 2KB
13.bmp 2KB
5.bmp 2KB
J.bmp 2KB
6.bmp 2KB
E.bmp 2KB
5.bmp 2KB
25.bmp 2KB
29.bmp 2KB
12.bmp 2KB
7.bmp 2KB
3.bmp 2KB
P.bmp 2KB
6.bmp 2KB
2.bmp 2KB
Y.bmp 2KB
20.bmp 2KB
5.bmp 2KB
R.bmp 2KB
34.bmp 2KB
4.bmp 2KB
8.bmp 2KB
30.bmp 2KB
2.bmp 2KB
4.bmp 2KB
23.bmp 2KB
20.bmp 2KB
3.bmp 2KB
24.bmp 2KB
Z.bmp 2KB
18.bmp 2KB
22.bmp 2KB
10.bmp 2KB
36.bmp 2KB
16.bmp 2KB
37.bmp 2KB
33.bmp 2KB
19.bmp 2KB
28.bmp 2KB
1.bmp 2KB
1.bmp 2KB
Q.bmp 2KB
8.bmp 2KB
16.bmp 2KB
11.bmp 2KB
15.bmp 2KB
17.bmp 2KB
9.bmp 2KB
共 223 条
- 1
- 2
- 3
资源评论
JonSco
- 粉丝: 77
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功