车牌识别系统MATLAB源代码完整解析 下载本文

内容发布更新时间 : 2024/12/24 1:41:54星期一 下面是文章的全部内容请认真阅读。

case 1

distance(n)=sum(sum(abs(words.word1-pattern(n).feature))); case 2

distance(n)=sum(sum(abs(words.word2-pattern(n).feature))); case 3

distance(n)=sum(sum(abs(words.word3-pattern(n).feature))); case 4

distance(n)=sum(sum(abs(words.word4-pattern(n).feature))); case 5

distance(n)=sum(sum(abs(words.word5-pattern(n).feature))); case 6

distance(n)=sum(sum(abs(words.word6-pattern(n).feature))); case 7

distance(n)=sum(sum(abs(words.word7-pattern(n).feature))); end end

[yvalue,xnumber]=min(distance); filename = files(xnumber, :);

[pathstr, name, ext] = fileparts(filename); result(m) = chepaiword(str2num(name)); end

str = ['识别结果为:' result]; msgbox(str, '车牌识别', 'modal'); str = result;

function result = Plate_Process(plate, id, flag) % 车牌区域处理 % 输入参数:

% plate——车牌区域 % id——车牌序号

% flag——显示图像标记 % 输出参数:

% result——结果图像 if nargin < 3 flag = 1; end

if ndims(plate) == 3

plate1 = rgb2gray(plate); % figure(1)

% imshow(plate1) else

plate1 = plate;

end

Im = Image_Rotate(plate1, id); th = [0.85 0.50 0.85 0.70 0.30 ... 0.40 0.65 0.45 0.45 0.65 ... 0.51 0.80 0.40 0.75 0.60 ... 0.55 0.40 0.40 0.76 0.72];

bw = im2bw(Im, th(id)); % 车牌区域二值化 h = fspecial('average', 2); % 均值滤波模板 bw1 = imfilter(bw, h, 'replicate'); % 均值滤波 % figure(1) % imshow(bw1)

mask = Mask_Process(bw1, id); % 模板处理 bw2 = bw1 .* mask; % 模板滤波 result = bw2; if flag

figure;

subplot(2, 2, 1); imshow(plate); title('车牌区域图像', 'FontWeight', 'Bold'); subplot(2, 2, 2); imshow(Im); title('车牌区域校正图像', 'FontWeight', 'Bold'); subplot(2, 2, 3); imshow(bw1); title('车牌区域二值图像', 'FontWeight', 'Bold'); subplot(2, 2, 4); imshow(bw2); title('滤波二值图像', 'FontWeight', 'Bold'); end

function [Plate, bw, Loc] = Pre_Process(Img, parm, flag) % 车牌图像预处理,提取车牌区域 % 输入参数:

% Img——图像矩阵 % parm——参数向量

% flag——是否显示处理结果 % 输出参数:

% Plate——分割结果 if nargin < 3 flag = 1; end

if nargin < 2 || isempty(parm) if size(Img, 2) > 900

parm = [0.35 0.9 90 0.35 0.7 90 2]; end

if size(Img, 2) > 700 && size(Img, 2) < 900 parm = [0.6 0.9 90 0.6 0.8 90 0.5]; end

if size(Img, 2) > 500 && size(Img, 2) < 700 parm = [0.5 0.54 50 0.6 0.7 50 3]; end

if size(Img, 2) < 500

parm = [0.8 0.9 150 0.8 0.9 150 3]; end end I = Img;

[y, x, z] = size(I); % y方向对应行、x方向对应列、z方向对应深度 % 图像尺寸过大会影响处理效率,所以进行放缩处理 if y > 800

rate = 800/y;

I = imresize(I, rate); end

[y, x, z] = size(I); % y方向对应行、x方向对应列、z方向对应深度

myI = double(I); % 数据类型转换 bw1 = zeros(y, x); bw2 = zeros(y, x); Blue_y = zeros(y, 1);

% 对每一个像素进行分析,统计满足条件的像素所在的行对应的个数 for i = 1 : y for j = 1 : x

rij = myI(i, j, 1)/(myI(i, j, 3)+eps); gij = myI(i, j, 2)/(myI(i, j, 3)+eps); bij = myI(i, j, 3);

% 蓝色RGB的灰度范围

if (rij < parm(1) && gij < parm(2) && bij > parm(3)) ...

|| (gij < parm(1) && rij < parm(2) && bij > parm(3)) Blue_y(i, 1) = Blue_y(i, 1) + 1; % 蓝色象素点统计 bw1(i, j) = 1; end end end

% Y方向车牌区域确定

[temp, MaxY] = max(Blue_y); Th = parm(7);

% 向上追溯,直到车牌区域上边界 PY1 = MaxY;

while ((Blue_y(PY1,1)>Th) && (PY1>1)) PY1 = PY1 - 1; end

% 向下追溯,直到车牌区域下边界 PY2 = MaxY;

while ((Blue_y(PY2,1)>Th) && (PY2

end

% 对车牌区域的修正 PY1 = PY1 - 2; PY2 = PY2 + 2; if PY1 < 1 PY1 = 1; end

if PY2 > y PY2 = y; end

% 得到车牌区域 IY = I(PY1:PY2, :, :);

%%%%%%%% X 方向 %%%%%%%%%% % 进一步确定X方向的车牌区域 Blue_x = zeros(1,x); for j = 1:x

for i = PY1:PY2

rij = myI(i, j, 1)/(myI(i, j, 3)+eps); gij = myI(i, j, 2)/(myI(i, j, 3)+eps); bij = myI(i, j, 3);

% 蓝色RGB的灰度范围

if (rij < parm(4) && gij < parm(5) && bij > parm(6)) ...

|| (gij < parm(4) && rij < parm(5) && bij > parm(6)) Blue_x(1,j) = Blue_x(1,j) + 1; % 蓝色象素点统计 bw2(i, j) = 1; end end end

% 想右追溯,直到找到车牌区域左边界 PX1 = 1;

while (Blue_x(1,PX1)

% 想左追溯,直到找到车牌区域右边界 PX2 = x;

while (Blue_x(1,PX2)PX1) PX2 = PX2 - 1; end

% 对车牌区域的修正 PX1 = PX1 - 2; PX2 = PX2 + 2; if PX1 < 1 PX1 = 1;

end

if PX2 > x PX2 = x; end

% 得到车牌区域 IX = I(:, PX1:PX2, :);

% 分割车牌区域

Plate = I(PY1:PY2, PX1:PX2, :); Loc.row = [PY1 PY2]; Loc.col = [PX1 PX2]; bw = bw1 + bw2; bw = logical(bw); bw(1:PY1, :) = 0; bw(PY2:end, :) = 0; bw(:, 1:PX1) = 0; bw(:, PX2:end) = 0; if flag

figure;

subplot(2, 2, 3); imshow(IY); title('行过滤结果', 'FontWeight', 'Bold'); subplot(2, 2, 1); imshow(IX); title('列过滤结果', 'FontWeight', 'Bold'); subplot(2, 2, 2); imshow(I); title('原图像', 'FontWeight', 'Bold');

subplot(2, 2, 4); imshow(Plate); title('分割结果', 'FontWeight', 'Bold'); end

function e = Segmation(d) % 车牌图像切割 % 输入参数: % d——车牌图像 % 输出参数:

% e——切割后的车牌图像

[m, n] = size(d); % 初始化参数

top = 1; % 矩形框上参数 bottom = m; % 矩形框下参数 left = 1; % 矩形框左参数 right = n; % 矩形框右参数 % 寻找矩形框上参数

while sum(d(top,:))==0 && top<=m top = top + 1;