基于matlab的蓝色车牌识别(车牌字符识别)

目录

1 处理流程

2 结果展示

3 核心要点解读

4 matlab代码


整套方案还包括以下博客:

(1)基于matlab的蓝色车牌识别(绪论)

(2)基于matlab的蓝色车牌识别(车牌定位)

(3)基于matlab的蓝色车牌识别(车牌倾斜矫正)

(4)基于matlab的蓝色车牌识别(车牌字符分割)

(5)基于matlab的蓝色车牌识别(车牌字符识别)

转载请注明出处,谢谢!

1 处理流程

基于matlab的蓝色车牌识别(车牌字符识别)_第1张图片

2 结果展示

基于matlab的蓝色车牌识别(车牌字符识别)_第2张图片

3 核心要点解读

模板库:模板库主要分为汉字模板库、字母模板库和数字字母模板库,每个模板库的每个字符都是通过取该字符的多张图片平均值得到的;

模式匹配:将归一化的字符二值图像与模板库中的字符二值化图像逐个进行匹配,采用相似度的方法计算车牌字符与每个模板字符的匹配程度,取最相似的就是匹配结果。

4 matlab代码

clear;clc;
close all;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% 1.读取要识别的车牌字符
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[fn,pn,fi]=uigetfile('矫正后的车牌\*.jpg','选择图片');
char1 = imread(['字符/',fn(1),'.jpg']);
char2 = imread(['字符/',fn(2),'.jpg']);
char3 = imread(['字符/',fn(3),'.jpg']);
char4 = imread(['字符/',fn(4),'.jpg']);
char5 = imread(['字符/',fn(5),'.jpg']);
char6 = imread(['字符/',fn(6),'.jpg']);
char7 = imread(['字符/',fn(7),'.jpg']);
figure(1);subplot(171);imshow(char1);
subplot(172);imshow(char2);subplot(173);imshow(char3);
subplot(174);imshow(char4);subplot(175);imshow(char5);
subplot(176);imshow(char6);subplot(177);imshow(char7);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% 2.加载模板库
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Chinese = LoadChinese();
Letter = LoadLetter();
DigitLetter = LoadDigitLetter();

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% 3.车牌字符与模板库字符进行特征匹配
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
recog1 = identityChinese(Chinese, char1); recognition(1)=recog1;
recog2 = identityLetter(Letter, char2);  recognition(2)=recog2;
recog3 = identityDigitLetter(DigitLetter, char3);  recognition(3)=recog3;
recog4 = identityDigitLetter(DigitLetter, char4);  recognition(4)=recog4;
recog5 = identityDigitLetter(DigitLetter, char5);  recognition(5)=recog5;
recog6 = identityDigitLetter(DigitLetter, char6);  recognition(6)=recog6;
recog7 = identityDigitLetter(DigitLetter, char7);  recognition(7)=recog7;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% 4.显示识别结果,并将其写入数据库
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
disp(recognition)
msgbox({'识别结果';recognition});
fid=fopen('Data.xls','a+');
fprintf(fid,'%s\r\n',recognition,datestr(now));
fclose(fid);


function Chinese = LoadChinese()
Chinese(:,:,1) = imresize(imbinarize(imread('模板库/汉字/沪.bmp')),[32,16],'bilinear');  % 沪
Chinese(:,:,2) = imresize(imbinarize(imread('模板库/汉字/吉.bmp')),[32,16],'bilinear');  % 吉
Chinese(:,:,3) = imresize(imbinarize(imread('模板库/汉字/京.bmp')),[32,16],'bilinear');  % 京
Chinese(:,:,4) = imresize(imbinarize(imread('模板库/汉字/闽.bmp')),[32,16],'bilinear');  % 闽
Chinese(:,:,5) = imresize(imbinarize(imread('模板库/汉字/苏.bmp')),[32,16],'bilinear');  % 苏
Chinese(:,:,6) = imresize(imbinarize(imread('模板库/汉字/粤.bmp')),[32,16],'bilinear');  % 粤
Chinese(:,:,7) = imresize(imbinarize(imread('模板库/汉字/浙.bmp')),[32,16],'bilinear');  % 浙
end

function letter = LoadLetter()
letter(:,:,1)=imresize(imbinarize(imread('模板库/字母/A.bmp')),[32,16],'bilinear');
letter(:,:,2)=imresize(imbinarize(imread('模板库/字母/B.bmp')),[32,16],'bilinear');
letter(:,:,3)=imresize(imbinarize(imread('模板库/字母/C.bmp')),[32,16],'bilinear');
letter(:,:,4)=imresize(imbinarize(imread('模板库/字母/D.bmp')),[32,16],'bilinear');
letter(:,:,5)=imresize(imbinarize(imread('模板库/字母/E.bmp')),[32,16],'bilinear');
letter(:,:,6)=imresize(imbinarize(imread('模板库/字母/F.bmp')),[32,16],'bilinear');
letter(:,:,7)=imresize(imbinarize(imread('模板库/字母/G.bmp')),[32,16],'bilinear');
letter(:,:,8)=imresize(imbinarize(imread('模板库/字母/H.bmp')),[32,16],'bilinear');
letter(:,:,9)=imresize(imbinarize(imread('模板库/字母/I.bmp')),[32,16],'bilinear');
letter(:,:,10)=imresize(imbinarize(imread('模板库/字母/J.bmp')),[32,16],'bilinear');
letter(:,:,11)=imresize(imbinarize(imread('模板库/字母/K.bmp')),[32,16],'bilinear');
letter(:,:,12)=imresize(imbinarize(imread('模板库/字母/L.bmp')),[32,16],'bilinear');
letter(:,:,13)=imresize(imbinarize(imread('模板库/字母/M.bmp')),[32,16],'bilinear');
letter(:,:,14)=imresize(imbinarize(imread('模板库/字母/N.bmp')),[32,16],'bilinear');
letter(:,:,15)=imresize(imbinarize(imread('模板库/字母/O.bmp')),[32,16],'bilinear');
letter(:,:,16)=imresize(imbinarize(imread('模板库/字母/P.bmp')),[32,16],'bilinear');
letter(:,:,17)=imresize(imbinarize(imread('模板库/字母/Q.bmp')),[32,16],'bilinear');
letter(:,:,18)=imresize(imbinarize(imread('模板库/字母/R.bmp')),[32,16],'bilinear');
letter(:,:,19)=imresize(imbinarize(imread('模板库/字母/S.bmp')),[32,16],'bilinear');
letter(:,:,20)=imresize(imbinarize(imread('模板库/字母/T.bmp')),[32,16],'bilinear');
letter(:,:,21)=imresize(imbinarize(imread('模板库/字母/U.bmp')),[32,16],'bilinear');
letter(:,:,22)=imresize(imbinarize(imread('模板库/字母/V.bmp')),[32,16],'bilinear');
letter(:,:,23)=imresize(imbinarize(imread('模板库/字母/W.bmp')),[32,16],'bilinear');
letter(:,:,24)=imresize(imbinarize(imread('模板库/字母/X.bmp')),[32,16],'bilinear');
letter(:,:,25)=imresize(imbinarize(imread('模板库/字母/Y.bmp')),[32,16],'bilinear');
letter(:,:,26)=imresize(imbinarize(imread('模板库/字母/Z.bmp')),[32,16],'bilinear');
end

function DigitLetter = LoadDigitLetter()
digit(:,:,1)=imresize(imbinarize(imread('模板库/数字/0.bmp')),[32,16],'bilinear');
digit(:,:,2)=imresize(imbinarize(imread('模板库/数字/1.bmp')),[32,16],'bilinear');
digit(:,:,3)=imresize(imbinarize(imread('模板库/数字/2.bmp')),[32,16],'bilinear');
digit(:,:,4)=imresize(imbinarize(imread('模板库/数字/3.bmp')),[32,16],'bilinear');
digit(:,:,5)=imresize(imbinarize(imread('模板库/数字/4.bmp')),[32,16],'bilinear');
digit(:,:,6)=imresize(imbinarize(imread('模板库/数字/5.bmp')),[32,16],'bilinear');
digit(:,:,7)=imresize(imbinarize(imread('模板库/数字/6.bmp')),[32,16],'bilinear');
digit(:,:,8)=imresize(imbinarize(imread('模板库/数字/7.bmp')),[32,16],'bilinear');
digit(:,:,9)=imresize(imbinarize(imread('模板库/数字/8.bmp')),[32,16],'bilinear');
digit(:,:,10)=imresize(imbinarize(imread('模板库/数字/9.bmp')),[32,16],'bilinear');
letter = LoadLetter();
DigitLetter = cat(3,digit,letter);
end

function result = identityChinese(Chinese, ch)
[height,width, num] = size(Chinese);
for n=1:num
    sums = 0;
    for h=1:height
        for w=1:width
            if ch(h,w) == Chinese(h,w,n)
                sums = sums + 1;
            end
        end
    end
    ratio(n) = sums/(height*width);
end
result_index=find(ratio>=max(ratio));
c = {'沪','吉','京','闽','苏','粤','浙'};
result = cell2mat(c(result_index));
end

function result = identityLetter(Letter, ch)
[height,width, num] = size(Letter);
for n=1:num
    sums = 0;
    for h=1:height
        for w=1:width
            if ch(h,w) == Letter(h,w,n)
                sums = sums + 1;
            end
        end
    end
    ratio(n) = sums/(height*width);
end
result_index = find(ratio>=max(ratio));
base = 64;
result = char(base + result_index);
end

function result = identityDigitLetter(DigitLetter, ch)
[height,width, num] = size(DigitLetter);
for n=1:num
    sums = 0;
    for h=1:height
        for w=1:width
            if ch(h,w) == DigitLetter(h,w,n)
                sums = sums + 1;
            end
        end
    end
    ratio(n) = sums/(height*width);
end
result_index = find(ratio>=max(ratio));
if result_index<=10
    base = 47;
    result = char(base + result_index);
else
    base = 64;
    result = char(base + result_index);
end
end

 

你可能感兴趣的:(车牌识别)