end
% 寻找矩形框下参数
while sum(d(bottom,:))==0 && bottom>=1 bottom = bottom - 1; end
% 寻找矩形框左参数
while sum(d(:,left))==0 && left<=n left = left + 1; end
% 寻找矩形框右参数
while sum(d(:,right))==0 && right>=1 right = right - 1; end
dd = right - left; % 矩形框长 hh = bottom - top; % 矩形框宽
e = imcrop(d, [left top dd hh]); % 车牌图像矩形框裁剪
function [word, result] = Word_Segmation(d) % 提取字符 % 输入参数: % d——车牌图像 % 输出参数:
% word——字符图像 % result——处理结果
word = []; flag = 0;
[m, n] = size(d);
wideTol = round(n/20); % 区域宽度最小约束 rateTol = 0.25; % 中心区域比值约束 while flag == 0
[m, n] = size(d); wide = 0;
while sum(d(:,wide+1)) ~= 0 && wide <= n-2 wide = wide + 1; end
temp = Segmation(imcrop(d, [1 1 wide m])); [m1,n1] = size(temp);
if wide
d = Segmation(d); % 切割出最小范围 else
word = []; flag = 1; end else
word = Segmation(imcrop(d, [1 1 wide m])); d(:, 1:wide) = 0; if sum(sum(d)) ~= 0; d = Segmation(d); flag = 1; else
d = []; end end end
result = d;
function Write_Mask(words, id) % 写出到模板库 % 输入参数:
% words——字符图像集合 % id——序号
imwrite(words.word1, sprintf('模板库\\\\%d_字符%d.jpg', id, 1)); imwrite(words.word2, sprintf('模板库\\\\%d_字符%d.jpg', id, 2)); imwrite(words.word3, sprintf('模板库\\\\%d_字符%d.jpg', id, 3)); imwrite(words.word4, sprintf('模板库\\\\%d_字符%d.jpg', id, 4)); imwrite(words.word5, sprintf('模板库\\\\%d_字符%d.jpg', id, 5)); imwrite(words.word6, sprintf('模板库\\\\%d_字符%d.jpg', id, 6)); imwrite(words.word7, sprintf('模板库\\\\%d_字符%d.jpg', id, 7));
% imwrite(words.word1, sprintf('模板库\\\\%d.jpg', (id-1)*7+1)); % imwrite(words.word2, sprintf('模板库\\\\%d.jpg', (id-1)*7+2)); % imwrite(words.word3, sprintf('模板库\\\\%d.jpg', (id-1)*7+3)); % imwrite(words.word4, sprintf('模板库\\\\%d.jpg', (id-1)*7+4)); % imwrite(words.word5, sprintf('模板库\\\\%d.jpg', (id-1)*7+5)); % imwrite(words.word6, sprintf('模板库\\\\%d.jpg', (id-1)*7+6)); % imwrite(words.word7, sprintf('模板库\\\\%d.jpg', (id-1)*7+7));