close all
clc
I=imread('G:\项目\汽车牌照\code\version1\car7.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
% I2=edge(I1,'roberts',0.15,'both');
% figure(3),subplot(2,2,1),imshow(I2);title('robert算子边缘检测')
% I2=edge(I1,'prewitt',0.04);
% figure(3),subplot(2,2,2),imshow(I2);title('prewitt算子边缘检测')
I2=edge(I1,'canny',0.2);
% figure(3),imshow(I2);title('canny算子边缘检测')
%% 计算跳变点
%% HIS颜色判别 得到I3
I3=I2;
I_size=size(I);
for i=1:I_size(1)
for j=1:I_size(2)
if (I3(i,j)==1)
Ihsi=I(i-1:i+1,j-1:j+1,:);
flag=hsi_decision(2,2,Ihsi);
if (flag<0.5)
I3(i,j)=0;
end
end
end
end
% figure(4),imshow(I3);title('his颜色判别')
%%
% 检测横向间距
% pj=1;k=0;
% for i=1:10;for j=1:10;if (j<2)pj=1;end
% if (I7(i,j)==1);k=k+1;s(k)=j-pj;pj=j;end
% end;end
% hist(s);
I4=I3;
%% 积分图像计算 用I4得到积分图像I5
s_line=zeros(I_size(1),I_size(2));
I5=s_line;
s_line(1,1)=I4(1,1);
I5(1,1)=I4(1,1);
for i=2:I_size(1) %计算初始行
s_line(i,1)=I4(i,1);
I5(i,1)=I5(i-1)+I4(i,1);
end
for i=2:I_size(2)
I5(1,i)=I5(1,i-1)+I4(1,i);
end
for i=2:I_size(1)
for j=2:I_size(2)
s_line(i,j)=s_line(i,j-1)+I4(i,j);
I5(i,j)=I5(i-1,j)+s_line(i,j);
end
end
%% 矩形框窗口分析
loc=zeros(100,2);
wlength=200;whigh=50;
loc(1,1:2)=[-whigh/2,-wlength/2]; kwindow=1;
for i=whigh/2:I_size(1)-whigh/2;
for j=wlength:I_size(2)-wlength;
winflag=0;
if (I4(i,j)==1)
for k=1:kwindow
if (abs(j-loc(k,2))<wlength*2&&abs(i-loc(k,1))<whigh*2)
winflag=1;
break;
end
end
if(winflag<1&&(I5(i+whigh/2,j+wlength/2)+I5(i-whigh/2,j-wlength/2)-I5(i+whigh/2,j-wlength/2)-I5(i-whigh/2,j+wlength/2))>200*50*0.05)
kwindow=kwindow+1;
loc(kwindow,1:2)=[i,j];
end
end
end
end
%% 利用水平投影求取车牌的高度
whigh=whigh*3;
nIsize=[whigh+1,wlength+1];
horizonsum=zeros(nIsize(1),1);
sumall=0;
% for k=1:kwindow-1
k=1;
Itemp=I3(loc(k+1,1)-0.4*whigh:loc(k+1,1)+0.6*whigh,loc(k+1,2)-0.48*wlength:loc(k+1,2)+0.52*wlength);%可删
figure(6);imshow(Itemp);%可删
for i=loc(k+1,1)-0.4*whigh:loc(k+1,1)+0.6*whigh
for j=loc(k+1,2)-0.48*wlength:loc(k+1,2)+0.52*wlength
if(I3(i,j)==1) horizonsum(i-loc(k+1,1)+0.4*whigh+1)=horizonsum(i-loc(k+1,1)+0.4*whigh+1)+1;
sumall=sumall+1;
end
end
end
sumall=0.6*sumall/nIsize(1);
for i=loc(k+1,1):-1:loc(k+1,1)-0.4*whigh
if horizonsum(i-loc(k+1,1)+0.4*whigh+1)<sumall
upsize=i; break;
end
end
for i=loc(k+1,1):loc(k+1,1)+0.6*whigh
if horizonsum(i-loc(k+1,1)+0.4*whigh+1)<sumall
downsize=i; break;
end
end
dd=downsize
uu=upsize
paihigh=ceil(downsize-upsize);
pailength=ceil(paihigh*440/140);
pailoch=floor(1/2*(downsize+upsize)); %边框与字的高度比为4:7
%% 车牌倾斜矫正
qingxiew=I2(ceil(pailoch-paihigh*7.5/7):ceil(pailoch+paihigh*7.5/7),ceil(loc(k+1,2)-pailength*0.55):ceil(loc(k+1,2)+0.65*pailength));
imshow(qingxiew);
theta=65:115;
% qingxiew 表示需要变换的图像,theta 表示变换的角度
% 返回值 r 表示的列中包含了对应于 theta中每一个角度的 Radon 变换结果
% 向量 xp 包含相应的沿 x轴的坐标
[r,xp]=radon(qingxiew,theta); %进行Radon变换
[maxr,rloc]=max(r(:)); %矩阵中的最大值坐标
[yr,xr]=ind2sub(size(r),rloc); %转化成二维坐标,x是点的横坐标,y是点的纵坐标 得到非零值从大到小的(x,y)坐标排序
angle=90-(xr+64); %旋转角度
I6=I(pailoch-ceil(paihigh*7.5/7):pailoch+ceil(paihigh*7.5/7),loc(k+1,2)-ceil(pailength*1):loc(k+1,2)+ceil(pailength*1),:);
Itemp=I6;
I6=imrotate(I6,angle); % 旋转图像
[m,n,l]=size(I6);
I6_temp=I6((m+1)/2-ceil(paihigh*4.5/7):(m+1)/2+ceil(paihigh*4.5/7),(n+1)/2-pailength:(n+1)/2+pailength,:)
I7=rgb2gray(I6_temp);
I8=edge(I7,'canny',0.2);
figure(8);
imshow(I8); %显示校正后的图像
colorbar; %显示色彩条
title('校正后的图像');
[m,n]=size(I8);
%% 车牌精确定位 输入I8
horizonsum=zeros(n,1);
for i=1:m
for j=1:n
if(I8(i,j)==1) horizonsum(i)=horizonsum(i)+1;
sumall=sumall+1;
end
end
end
sumall=0.6*sumall/m;
for i=(m+1)/2:-1:1
if horizonsum(i)<sumall
upsize=i+1;break;
end
end
for i=(m+1)/2:m
if horizonsum(i)<sumall
downsize=i-1;break;
end
end
I9=I6_temp(upsize:downsize,:,:);
imshow(I9)
b=rgb2gray(I9);
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.膨胀或腐蚀处理后')
% end
%% 寻找连续有文字的块,若长度大于某阈值,则认为该块有两个字符组成,需要分割
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');
没有合适的资源?快使用搜索试试~ 我知道了~
license-plate-recognition.rar_SVM 字符识别_SVM字符识别_车牌字符分割_车牌检测 matla
共34个文件
jpg:25个
bmp:4个
m:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
1 下载量 164 浏览量
2022-07-14
02:40:54
上传
评论
收藏 5.05MB RAR 举报
温馨提示
车牌识别在matlab环境下的实现,利用canny边缘检测、字符分割、SVM字符识别从而进行车牌检测
资源详情
资源评论
资源推荐
收起资源包目录
license-plate-recognition.rar (34个子文件)
license plate recognition1
main.m 9KB
test.jpg 2KB
1.车牌灰度图像.jpg 4KB
hsi_blue.bmp 186B
flagtest.bmp 134B
2.jpg 805B
1.jpg 873B
6.jpg 797B
car2.jpg 58KB
5.膨胀或腐蚀处理后.jpg 6KB
car3.jpg 1001KB
3.jpg 891B
4.均值滤波后.jpg 6KB
5.jpg 880B
hsi_bw.jpg 741B
qingxie3.jpg 11KB
hsi_blue.jpg 690B
qingxie1.jpg 8KB
rgb2hsi.m 1KB
车牌横向距离直方图.fig 5KB
car6.jpg 455KB
hsi_blue2.bmp 182B
car1.JPG 3.43MB
4.jpg 853B
2.车牌二值图像.jpg 6KB
carpai1.JPG 44KB
main_radon.m 2KB
carpai2.jpg 2KB
hsi_decision.m 2KB
hsi_bw.bmp 306B
hsi_white.jpg 663B
qingxie2.jpg 10KB
car7.jpg 37KB
7.jpg 614B
共 34 条
- 1
朱moyimi
- 粉丝: 61
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0