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

简介: 【图像识别】基于模板匹配实现蓝色、绿色、黄色车牌识别附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电子书和数学建模资料
❤️部分理论引用网络文献,若有侵权联系博主删除


相关文章
|
5月前
|
算法 定位技术 计算机视觉
【水下图像增强】基于波长补偿与去雾的水下图像增强研究(Matlab代码实现)
【水下图像增强】基于波长补偿与去雾的水下图像增强研究(Matlab代码实现)
388 0
|
5月前
|
算法 机器人 计算机视觉
【图像处理】水下图像增强的颜色平衡与融合技术研究(Matlab代码实现)
【图像处理】水下图像增强的颜色平衡与融合技术研究(Matlab代码实现)
175 0
|
5月前
|
机器学习/深度学习 算法 机器人
使用哈里斯角Harris和SIFT算法来实现局部特征匹配(Matlab代码实现)
使用哈里斯角Harris和SIFT算法来实现局部特征匹配(Matlab代码实现)
256 8
|
5月前
|
机器学习/深度学习 编解码 算法
基于OFDM技术的水下声学通信多径信道图像传输研究(Matlab代码实现)
基于OFDM技术的水下声学通信多径信道图像传输研究(Matlab代码实现)
262 8
|
5月前
|
机器学习/深度学习 人工智能 文字识别
中药材图像识别数据集(100类,9200张)|适用于YOLO系列深度学习分类检测任务
本数据集包含9200张中药材图像,覆盖100种常见品类,已标注并划分为训练集与验证集,支持YOLO等深度学习模型。适用于中药分类、目标检测、AI辅助识别及教学应用,助力中医药智能化发展。
|
12月前
|
机器学习/深度学习 人工智能 算法
基于Python深度学习的【害虫识别】系统~卷积神经网络+TensorFlow+图像识别+人工智能
害虫识别系统,本系统使用Python作为主要开发语言,基于TensorFlow搭建卷积神经网络算法,并收集了12种常见的害虫种类数据集【"蚂蚁(ants)", "蜜蜂(bees)", "甲虫(beetle)", "毛虫(catterpillar)", "蚯蚓(earthworms)", "蜚蠊(earwig)", "蚱蜢(grasshopper)", "飞蛾(moth)", "鼻涕虫(slug)", "蜗牛(snail)", "黄蜂(wasp)", "象鼻虫(weevil)"】 再使用通过搭建的算法模型对数据集进行训练得到一个识别精度较高的模型,然后保存为为本地h5格式文件。最后使用Djan
663 1
基于Python深度学习的【害虫识别】系统~卷积神经网络+TensorFlow+图像识别+人工智能
|
机器学习/深度学习 人工智能 算法
基于Python深度学习的【蘑菇识别】系统~卷积神经网络+TensorFlow+图像识别+人工智能
蘑菇识别系统,本系统使用Python作为主要开发语言,基于TensorFlow搭建卷积神经网络算法,并收集了9种常见的蘑菇种类数据集【"香菇(Agaricus)", "毒鹅膏菌(Amanita)", "牛肝菌(Boletus)", "网状菌(Cortinarius)", "毒镰孢(Entoloma)", "湿孢菌(Hygrocybe)", "乳菇(Lactarius)", "红菇(Russula)", "松茸(Suillus)"】 再使用通过搭建的算法模型对数据集进行训练得到一个识别精度较高的模型,然后保存为为本地h5格式文件。最后使用Django框架搭建了一个Web网页平台可视化操作界面,
1206 11
基于Python深度学习的【蘑菇识别】系统~卷积神经网络+TensorFlow+图像识别+人工智能
|
机器学习/深度学习 人工智能 算法
【宠物识别系统】Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+图像识别
宠物识别系统,本系统使用Python作为主要开发语言,基于TensorFlow搭建卷积神经网络算法,并收集了37种常见的猫狗宠物种类数据集【'阿比西尼亚猫(Abyssinian)', '孟加拉猫(Bengal)', '暹罗猫(Birman)', '孟买猫(Bombay)', '英国短毛猫(British Shorthair)', '埃及猫(Egyptian Mau)', '缅因猫(Maine Coon)', '波斯猫(Persian)', '布偶猫(Ragdoll)', '俄罗斯蓝猫(Russian Blue)', '暹罗猫(Siamese)', '斯芬克斯猫(Sphynx)', '美国斗牛犬
660 29
【宠物识别系统】Python+卷积神经网络算法+深度学习+人工智能+TensorFlow+图像识别
|
机器学习/深度学习 网络架构 计算机视觉
深度学习在图像识别中的应用与挑战
【10月更文挑战第21天】 本文探讨了深度学习技术在图像识别领域的应用,并分析了当前面临的主要挑战。通过研究卷积神经网络(CNN)的结构和原理,本文展示了深度学习如何提高图像识别的准确性和效率。同时,本文也讨论了数据不平衡、过拟合、计算资源限制等问题,并提出了相应的解决策略。
409 19

热门文章

最新文章