【图像识别】基于模板匹配实现蓝色、绿色、黄色车牌识别附matlab代码

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法  神经网络预测 雷达通信  无线传感器

信号处理 图像处理 路径规划 元胞自动机 无人机

⛄ 内容介绍

​车牌识别是智能交通系统的重要部分,主要涉及模式识别、数字图像处理、计算机应用和人工智能等学科。车牌识别过程主要由车牌定位、车牌字符分割和车牌字符识别组成。文中主要对车牌字符识别进行了研究,并在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

% Last Modified by GUIDE v2.5 27-May-2022 18:45:00

% 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

switch (handles.type)

    case 1

        [Plate, ~, Loc] = Pre_Process(handles.Img, [], 0); %0表示不显示预处理结果

    case 2

        [Plate, ~, Loc] = Pre_Process02(handles.Img, [], 0); %0表示不显示预处理结果

    case 3

        [Plate, ~, Loc] = Pre_Process_Yellow(handles.Img, [], 0); %0表示不显示预处理结果

end

axes(handles.axes1); hold on;%使用hold on,可以保持上一幅图当前图可以画在同一个轴上,而不覆盖。

row = Loc.row;

col = Loc.col;

%在原图像中显示小红框

plot([col(1) col(2)], [row(1) row(1)], 'r-', 'LineWidth', 2);

plot([col(1) col(2)], [row(2) row(2)], 'r-', 'LineWidth', 2);

plot([col(1) col(1)], [row(1) row(2)], 'r-', 'LineWidth', 2);

plot([col(2) col(2)], [row(1) row(2)], 'r-', 'LineWidth', 2);

hold off;%新图会把旧图覆盖。hold off 取消保持功能 即取消hold on的作用

%cla reset:删除当前坐标系中所有的对象

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)

if isempty(handles.Plate)

    msgbox('请先进行【车牌定位】操作', '提示信息', 'error'); 

    return;

end

switch (handles.type)

    case 1

       bw = Plate_Process(handles.Plate, 0);%调用Plate_Process函数 

    case 2

        bw = Plate_Process02(handles.Plate, 0);

    case 3

        bw = Plate_Process_Yellow(handles.Plate, 0);

end

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)

if isempty(handles.bw)

    msgbox('请先进行【二值化】操作', '提示信息', 'error'); 

    return;

end

bw = Segmation(handles.bw);%调用Segmation函数,返回裁剪后区域结果

switch (handles.type)

    case 1

        words = Main_Process(bw, 0); %调用Main_Process函数

        axes(handles.axes4); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);

        %显示归一化后(40x20)的车牌字符图像

        %蓝色车牌

        words_display = [words.word1 words.word2 words.word3 words.word4 words.word5 words.word6 words.word7];

    case 2

        words = Main_Process02(bw, 0); %调用Main_Process函数

        axes(handles.axes4); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);

        %绿色车牌

        words_display = [words.word1 words.word2 words.word3 words.word4 words.word5 words.word6 words.word7 words.word8];

    case 3

        words = Main_Process_Yellow(bw, 0); 

        axes(handles.axes4); cla reset; box on; set(gca, 'XTickLabel', [], 'YTickLabel', []);

        %黄色车牌

        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)

if isempty(handles.words)

    msgbox('请先进行【字符分割】操作', '提示信息', 'error'); 

    return;

end

switch (handles.type)

    case 1

        str = Pattern_Recognition(handles.words);%模板匹配

    case 2

        str = Pattern_Recognition02(handles.words);%模板匹配

    case 3

        str = Pattern_Recognition_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电子书和数学建模资料

❤️部分理论引用网络文献,若有侵权联系博主删除

如果您下载了本程序,但是该程序存在问题无法运行,那么您可以选择退款或者寻求我们的帮助(如果找我们帮助的话,是需要追加额外费用的)。另外,您不会使用资源的话(这种情况不支持退款),也可以找我们帮助(需要追加额外费用) MATLAB(Matrix Laboratory)是一款由美国MathWorks公司开发的高性能商业数学软件,它集成了高级技术计算语言、交互式环境以及丰富的工具箱,被广泛应用于工程计算、数据分析、算法开发和科学可视化等领域。MATLAB的核心功能包括: 1. **数值计算**:支持大规模矩阵和数组运算,对线性代数、微积分、概率统计等数学问题提供高效解决方案。 2. **编程环境**:提供了易于使用的脚本编写与函数定义界面,支持面向对象编程,并可通过M文件实现模块化程序设计。 3. **数据可视化**:内置强大的二维和三维图形绘制功能,能够创建高质量的数据图表,便于数据分析和结果展示。 4. **工具箱扩展**:MathWorks为MATLAB提供了众多领域的专业工具箱,如信号处理、图像处理、通信系统、控制系统、机器学习、深度学习、量化金融、优化算法等,极大地扩展了MATLAB的应用范围。 5. **Simulink仿真**:作为MATLAB的重要组成部分,Simulink是一个动态系统建模、仿真和基于模型的设计环境,特别适用于多域物理系统和嵌入式系统的模拟和实时测试。 6. **集成能力**:MATLAB可以与其他编程语言(如C、C++、Java、Python等)及外部应用程序进行数据交换和联合开发,也可以调用硬件接口进行实时实验和控制。 7. **交互式工作空间**:用户可以在命令窗口中直接输入表达式并立即得到结果,这种交互式的特性使得快速原型设计和调试变得极为便利。 总之,MATLAB是科学家、工程师和技术人员进行科研、教育和工业应用不可或缺的强大工具之一,尤其在需要大量数值计算和复杂系统建模的场景下发挥着重要作用。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值