车牌识别是智能交通系统的重要部分,主要涉及模式识别、数字图像处理、计算机应用和人工智能等学科。车牌识别过程主要由车牌定位、车牌字符分割和车牌字符识别组成。文中主要对车牌字符识别进行了研究,并在MATLAB环境下进行了相应的实验。文中在车牌字符识别过程中,主要采用了基于模板匹配的车牌字符识别方法。首先将字符的标准模板存储在电脑中备用,然后将待识别字符进行灰度化和二值化,然后将归一化后的待识别字符与存储在电脑中的标准字符模板进行匹配。文中选择的匹配方法是将待识别字符与标准模板进行逻辑“与”运算。进行运算后会得到一个新的字符模板,再根据预先设计好的判别函数对得到的新字符模板进行判断,从而得出识别结果。我国车牌字符由汉字、字母和数字组成。根据汉字、字母和数字结构的不同,在判别函数部分文中将整个车牌字符分为两部分进行研究。汉字为一部分,数字与字母为另一部分。在汉字识别部分,文中将求取标准模板、待识别字符和新字符模板三者标准差的最小值作为一个判别函数;将求取新字符模板最大值作为另一个判别函数。在数字与字母识别部分,文中将求取标准模板、待识别字符和新字符模板三者的标准差最小值作为一个判别函数;将求取新字符模板与标准模板比值的最大值作为另一个判别函数。
部分代码
function varargout = Gui_Main(varargin)
%%%%%%%%%运行这个即可打开《车牌识别系统》%%%%%%%%
%GUI_MAIN MATLAB code for Gui_Main.fig
% GUI_MAIN, by itself, creates a new GUI_MAIN or raises the existing
% singleton*.
%
% H = GUI_MAIN returns the handle to a new GUI_MAIN or the handle to
% the existing singleton*.
%
% GUI_MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI_MAIN.M with the given input arguments.
%
% GUI_MAIN('Property','Value',...) creates a new GUI_MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before Gui_Main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to Gui_Main_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help Gui_Main
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @Gui_Main_OpeningFcn, ...
'gui_OutputFcn', @Gui_Main_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before Gui_Main is made visible.
function Gui_Main_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to Gui_Main (see VARARGIN)
% Choose default command line output for Gui_Main
clc;
axes(handles.axes1); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
axes(handles.axes2); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
axes(handles.axes3); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
axes(handles.axes4); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
set(handles.text1, 'string', '');
handles.output = hObject;
handles.file = [];
handles.Plate = [];
handles.bw = [];
handles.words = [];
% Update handles structure
handles.type=1;%打开时,默认识别蓝色车牌
guidata(hObject, handles);
% UIWAIT makes Gui_Main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = Gui_Main_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --------------------------------------------------------------------
%工具栏:Save Figure
function uipushtool1_ClickedCallback(hObject, eventdata, handles)
% hObject handle to uipushtool1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uiputfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files' }, '保存结果', ...
'Result\result.jpg');
if isempty(filename)
return;
end
file = fullfile(pathname, filename);
f = getframe(gcf);
f = frame2im(f);
imwrite(f, file);
msgbox('保存结果图像成功!', '提示信息', 'help');
% --------------------------------------------------------------------
%工具栏:Open File
function uipushtool2_ClickedCallback(hObject, eventdata, handles)
% hObject handle to uipushtool2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% 载入车牌图像
axes(handles.axes1); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
axes(handles.axes2); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
axes(handles.axes3); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
axes(handles.axes4); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
set(handles.text1, 'string', '');
handles.file = [];
handles.Plate = [];
handles.bw = [];
handles.words = [];
[filename, pathname, filterindex] = uigetfile({'*.jpg;*.tif;*.png;*.gif','All Image Files';...
'*.*','All Files' }, '选择待处理图像', ...
'images');
if filename == 0
return;
end
file = fullfile(pathname, filename);
Img = imread(file);
[y, ~, ~] = size(Img);
if y > 800
rate = 800/y;
Img1 = imresize(Img, rate);
else
Img1 = Img;
end
axes(handles.axes1);
imshow(Img1); title('原图像', 'FontWeight', 'Bold');
handles.Img = Img;
handles.file = file;
guidata(hObject, handles);
% --- Executes on button press in pushbutton1.
%按钮:标定车牌区域
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
if isempty(handles.file)
msgbox('请载入待识别图像', '提示信息', 'error');
return;
end
row = Loc.row;
col = Loc.col;
axes(handles.axes2); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
imshow(Plate, []); title('车牌定位图像', 'FontWeight', 'Bold');
handles.Plate = Plate;
guidata(hObject, handles);%储存handles
% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over pushbutton1.
function pushbutton1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes1_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes2_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes3_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on mouse press over axes background.
function axes4_ButtonDownFcn(hObject, eventdata, handles)
% hObject handle to axes4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton2.
%按钮:区域二值化
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
axes(handles.axes3); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);
imshow(bw, []); title('车牌二值图像', 'FontWeight', 'Bold');
handles.bw = bw;
guidata(hObject, handles);%储存handles
% --- Executes on button press in pushbutton3.
%按钮:字符分割
function pushbutton3_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch (handles.type)
case 1
%蓝色车牌
words_display = [words.word1 words.word2 words.word3 words.word4 words.word5 words.word6 words.word7];
case 2
%绿色车牌
words_display = [words.word1 words.word2 words.word3 words.word4 words.word5 words.word6 words.word7 words.word8];
case 3
%黄色车牌
words_display = [words.word1 words.word2 words.word3 words.word4 words.word5 words.word6 words.word7];
end
imshow(words_display, []); title('车牌字符图像', 'FontWeight', 'Bold');
handles.words = words;
guidata(hObject, handles);%储存handles
% --- Executes on button press in pushbutton4.
%按钮:车牌识别
function pushbutton4_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton4 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
switch (handles.type)
case 1
str = Pattern_Recog(handles.words);%模板匹配
case 2
str = Pattern_Recog02(handles.words);%模板匹配
case 3
str = Pattern_Recog_Yellow(handles.words);%模板匹配
end
set(handles.text1, 'string', str);
% --- Executes on button press in radiobutton1.
function radiobutton1_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton1
handles.type=1;
guidata(hObject, handles);
% --- Executes on button press in radiobutton2.
function radiobutton2_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton2
handles.type=2;
guidata(hObject, handles);
% --- Executes on button press in radiobutton5.
function radiobutton5_Callback(hObject, eventdata, handles)
% hObject handle to radiobutton5 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hint: get(hObject,'Value') returns toggle state of radiobutton5
handles.type=3;
guidata(hObject, handles);
参考文献
[1]谷秋頔. 基于模板匹配的车牌字符识别及其判别函数的研究[D]. 中北大学.[2]刘忠杰, 宋小波, 何锋,等. 基于MATLAB 的车牌识别系统设计与实现[J]. 微型机与应用, 2011, 30(14):4.❤️ 关注我领取海量matlab电子书和数学建模资料❤️部分理论引用网络文献,若有侵权联系博主删除