function lpr_loc()
% license plate recognition - car plate location based on color model
% modified by ZHAO Hui, April 30th,2005
I=imread('Car.jpg');
[y,x,z]=size(I);
myI=double(I);
%%%%%%%%%%% RGB to HSI %%%%%%%%
tic % 测定算法执行的时间,开始计时
%%%%%%%%%%% 统计分析 %%%%%%%%%%%%%%%
%%%%%%%% Y 方向 %%%%%%%%%%
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if((myI(i,j,1)<=121)&&myI(i,j,1)>=110&&((myI(i,j,2)<=155)&&(myI(i,j,2)>=141))&&((myI(i,j,3)<=240)&&(myI(i,j,3)>=210)))
% 蓝色RGB的灰度范围
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)<=121)&&myI(i,j,1)>=110&&((myI(i,j,2)<=155)&&(myI(i,j,2)>=141))&&((myI(i,j,3)<=240)&&(myI(i,j,3)>=210)))
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-2; % 对车牌区域的修正
PX2=PX2+2;
Plate=I(PY1:PY2,PX1-2:PX2,:);
t=toc % 读取计时
Plate2=rgb2gray(Plate);%图像灰度化
figure,imshow(I);%显示车
figure,plot(Blue_y);grid%y方向蓝色象素点统计
figure,plot(Blue_x);grid%x方向蓝色象素点统计
figure,imshow(IY);%Y方向截取结
figure,imshow(Plate);% 提取的车牌
figure,imshow(Plate2);%车牌的灰度化
Plate3=im2bw(Plate2,0.7);%将图象二值化,二值化图像函数主要有dither和im2bw函数。 dither 函数通过颜色抖动来达到转换图像的目的。 语法:BW = dither(I)。 Image 是图像矩阵资料,BW 是二值化图像矩阵 ;im2bw 函数通过对灰度值进行阈值判断的方法达到目的。 语法:BinaryImage = im2bw( Image, [Level] )。Image 是输入图像矩阵资料,Level 是二值化程度值,其为介于0到1之间值,BW 是二值化图像矩阵。
figure,imshow(Plate3);
[n,m]=size(Plate3) ;
Plate3x{1}=Plate3(1:n,1:17*m/129);
figure,imshow(Plate3x{1})
Plate3x{2}=Plate3(1:n,17*m/129:35*m/129);
figure,imshow(Plate3x{2})
Plate3x{3}=Plate3(1:n,39*m/129:60*m/129);
figure,imshow(Plate3x{3})
Plate3x{4}=Plate3(1:n,60*m/129:77*m/129);
figure,imshow(~Plate3x{4})
Plate3x{5}=Plate3(1:n,77*m/129:94*m/129);
figure,imshow(Plate3x{5})
Plate3x{6}=Plate3(1:n,94*m/129:111*m/129);
figure,imshow(Plate3x{6})
Plate3x{7}=Plate3(1:n,111*m/129:m);
figure,imshow(Plate3x{7})
% result='';
%%%制作模板
for i=1:36
ii=int2str(i-1);
t=imread(['车牌字符模板\',ii,'.bmp']);
t=rgb2gray(t);
level=graythresh(t);
t=im2bw(t,level);
t=~t;
pattern{i}=imresize(t,[10 6],'nearest');
% figure(8);subplot(4,10,i),imshow(pattern{i});
end
for n=2:7
%%%将字符与模板作比较
DIST=10000; %字符与模板距离
cn(n)=10000;
%%%前三个字符和字母模板比较
Char{n}=imresize(Plate3x{n},[10,6],'nearest');
if n<=3
for pn=10:35
dist=sum(sum( xor(Char{n} , pattern{pn+1})));
if dist<=DIST
DIST=dist;
cn(n)=pn;
end
end
end
%%%后四个字符与数字模板比较
if n>=3
for pn=0:9
dist=sum(sum( xor(Char{n} , pattern{pn+1})));
if dist<=DIST
DIST=dist;
cn(n)=pn;
end
end
end
%根据代号判断字符内容
switch cn(n)
case 0
char=' 0'
case 1
char=' 1'
case 2
char=' 2'
case 3
char=' 3'
case 4
char=' 4'
case 5
char=' 5'
case 6
char=' 6'
case 7
char=' 7'
case 8
char=' 8'
case 9
char=' 9'
case 10
char=' A'
case 11
char=' B'
case 12
char=' C'
case 13
char=' D'
case 14
char=' E'
case 15
char=' F'
case 16
char=' G'
case 17
char=' H'
case 18
char=' I'
case 19
char=' J'
case 20
char=' K'
case 21
char=' L'
case 22
char=' M'
case 23
char=' N'
case 24
char=' O'
case 25
char=' P'
case 26
char=' Q'
case 27
char=' R'
case 28
char=' S'
case 29
char=' T'
case 30
char=' U'
case 31
char=' V'
case 32
char=' W'
case 33
char=' X'
case 34
char=' Y'
case 35
char=' Z'
otherwise
char=' 识别失败'
end
% result=strcat(result,char);
end
% str='Stop'
% figure, imshow(result)
车牌定位及字符识别的MATLAB程序
4星 · 超过85%的资源 需积分: 10 154 浏览量
2009-03-15
21:14:26
上传
评论 2
收藏 151KB RAR 举报
lanyulianying
- 粉丝: 1
- 资源: 2
最新资源
- MyBatis 动态 SQL:灵活而强大的查询构建器.pdf
- com.accordion.prettyo.apk
- 毕业设计:基于SSM的mysql-ssm软件bug管理系统(源码 + 数据库 + 说明文档)
- MTSQL8.0.35windows(64bit)-mysql-installer-community-8.0.35.0
- 人工智能引领音乐创作新时代之Suno AI
- Public-bicycle-usage-forecast-master.zip
- 通道处理过程模拟:从理论到实践.pdf
- 数据库第七次作业E-R图第一题
- 大厂面试真题Java语法基础面试专题及答案
- IMG20240428211124.jpg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
- 3
- 4
- 5
- 6
前往页