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

本文涉及的产品
视觉智能开放平台,图像通用资源包5000点
视觉智能开放平台,分割抠图1万点
视觉智能开放平台,视频通用资源包5000点
简介: 【图像识别】基于模板匹配实现蓝色、绿色、黄色车牌识别附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电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除


相关文章
|
7天前
|
存储 编解码 算法
【多光谱滤波器阵列设计的最优球体填充】使用MSFA设计方法进行各种重建算法时,图像质量可以提高至多2 dB,并在光谱相似性方面实现了显著提升(Matlab代码实现)
【多光谱滤波器阵列设计的最优球体填充】使用MSFA设计方法进行各种重建算法时,图像质量可以提高至多2 dB,并在光谱相似性方面实现了显著提升(Matlab代码实现)
|
7天前
|
机器学习/深度学习 传感器 算法
【高创新】基于优化的自适应差分导纳算法的改进最大功率点跟踪研究(Matlab代码实现)
【高创新】基于优化的自适应差分导纳算法的改进最大功率点跟踪研究(Matlab代码实现)
83 14
|
7天前
|
机器学习/深度学习 算法
【概率Copula分类器】实现d维阿基米德Copula相关的函数、HACs相关的函数研究(Matlab代码实现)
【概率Copula分类器】实现d维阿基米德Copula相关的函数、HACs相关的函数研究(Matlab代码实现)
|
8天前
|
算法 计算机视觉
【MPDR & SMI】失配广义夹角随输入信噪比变化趋势、输出信干噪比随输入信噪比变化趋势研究(Matlab代码实现)
【MPDR & SMI】失配广义夹角随输入信噪比变化趋势、输出信干噪比随输入信噪比变化趋势研究(Matlab代码实现)
|
8天前
|
编解码 人工智能 算法
【采用BPSK或GMSK的Turbo码】MSK、GMSK调制二比特差分解调、turbo+BPSK、turbo+GMSK研究(Matlab代码实现)
【采用BPSK或GMSK的Turbo码】MSK、GMSK调制二比特差分解调、turbo+BPSK、turbo+GMSK研究(Matlab代码实现)
|
8天前
|
机器学习/深度学习 编解码 并行计算
【改进引导滤波器】各向异性引导滤波器,利用加权平均来实现最大扩散,同时保持图像中的强边缘,实现强各向异性滤波,同时保持原始引导滤波器的低低计算成本(Matlab代码实现)
【改进引导滤波器】各向异性引导滤波器,利用加权平均来实现最大扩散,同时保持图像中的强边缘,实现强各向异性滤波,同时保持原始引导滤波器的低低计算成本(Matlab代码实现)
|
8天前
|
机器学习/深度学习 传感器 边缘计算
【故障诊断】基于时滞反馈随机共振的增强型旋转电机故障诊断(Matlab代码实现)
【故障诊断】基于时滞反馈随机共振的增强型旋转电机故障诊断(Matlab代码实现)
|
8天前
|
传感器 机器学习/深度学习 算法
【UASNs、AUV】无人机自主水下传感网络中遗传算法的路径规划问题研究(Matlab代码实现)
【UASNs、AUV】无人机自主水下传感网络中遗传算法的路径规划问题研究(Matlab代码实现)
|
8天前
|
运维 算法
【故障诊断】基于最小熵反卷积、最大相关峰度反卷积和最大二阶环平稳盲反卷积等盲反卷积方法在机械故障诊断中的应用研究(Matlab代码实现)
【故障诊断】基于最小熵反卷积、最大相关峰度反卷积和最大二阶环平稳盲反卷积等盲反卷积方法在机械故障诊断中的应用研究(Matlab代码实现)
|
7天前
|
机器学习/深度学习 传感器 算法
【裂纹检测】检测和标记图片中的裂缝(Matlab代码实现)
【裂纹检测】检测和标记图片中的裂缝(Matlab代码实现)