【影象識別】基於BP神經網路求解車牌識別問題matlab程式碼

2022-01-02 18:00:02

​1 簡介

隨著資訊時代的到來,現代智慧交通系統能夠很輕易的識別出汽車牌照,這是智慧交通管理的標誌之一。智慧交通管理系統的牌照識別集合了影象採集和預處理、車牌定位技術、字元分割和字元識別等相關技術。其中,車牌定位、字元分割和字元識別是最關鍵的技術,也是本次畢業設計的難點所在。正確利用好這三種關鍵技術,將有助於牌照識別的實時性和準確性,對於智慧交通系統的實現有著決定性作用。在MATLAB軟體開發環境下,系統首先對影象進行預處理、然後將預處理後的影象進行定位分割,最後識別出相應牌照上的字元,這樣就可以模擬設計出汽車牌照識別系統。本文的影象預處理模組是將影象灰度化和用Canny運算元進行邊緣檢測,汽車牌照定位依據是它的顏色特徵,使用MATLAB中的Radon函數和Imrotate函數來進行車牌矯正;分割字元時,需要先找到連續的文字塊,然後根據長度大小來確定是否分割,假如所找到的連續文字塊的長度大於閾值,那麼就表示可以對此文字塊進行分割。並且為了能對車牌上的字元進行正確的識別,本文將採用BP神經網路演演算法。最後設計GUI介面,使介面更加簡潔明瞭,便於操作。根據實驗得出的結論,這種方式可以對藍色的車牌進行高效、精確的識別,同時,也對光照、旋轉和噪聲表現出很好的魯棒性,定位精度和識別正確率甚至可以超過90%。

2 部分程式碼

function varargout = run(varargin)
% RUN MATLAB code for run.fig
%     RUN, by itself, creates a new RUN or raises the existing
%     singleton*.
%
%     H = RUN returns the handle to a new RUN or the handle to
%     the existing singleton*.
%
%     RUN('CALLBACK',hObject,eventData,handles,...) calls the local
%     function named CALLBACK in RUN.M with the given input arguments.
%
%     RUN('Property','Value',...) creates a new RUN or raises the
%     existing singleton*. Starting from the left, property value pairs are
%     applied to the GUI before run_OpeningFcn gets called. An
%     unrecognized property name or invalid value makes property application
%     stop. All inputs are passed to run_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 run

% Last Modified by GUIDE v2.5 07-May-2016 15:41:22

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                  'gui_Singleton',  gui_Singleton, ...
                  'gui_OpeningFcn', @run_OpeningFcn, ...
                  'gui_OutputFcn',  @run_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 run is made visible.
function run_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 run (see VARARGIN)

% Choose default command line output for run
handles.output = hObject;
handles.cd0 = cd;
handles.Color = 0;
handles.I = [];

axes(handles.axes1);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes2);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

%axes(handles.axes3);
%set(gca,'Xtick',[]);
%set(gca,'Ytick',[]);
%box on;

axes(handles.axes4);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes5);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes6);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes8);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes9);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes12);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;
axes(handles.axes13);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;
axes(handles.axes14);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;
axes(handles.axes15);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;
axes(handles.axes16);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;
axes(handles.axes17);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;


% Update handles structure
guidata(hObject, handles);

% UIWAIT makes run wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = run_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;


% --- 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)
%% 讀圖
[filename, cd1] = uigetfile( ...
  {'*.tif;*.TIF;*.JPG;*.jpg;*.bmp;*.BMP;*.jpeg;*.JPEG;','Image file';...
   '*.*', 'All file (*.*)'},'Pick an Image');
axes(handles.axes1);
cla;
axes(handles.axes2);
cla;
%axes(handles.axes3);
%cla;
axes(handles.axes4);
cla;
if filename

   cd(cd1);
   d = imread(filename);
   cd(handles.cd0);
   handles.I = d;
   axes(handles.axes1);
   imshow(d);
   handles.filename = filename; 

   box on;
   
end

handles.Color = 0;
cd(handles.cd0);
set(handles.text2,'string','');
guidata(hObject, handles);

% --- 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)
image =  handles.I; 
gray = rgb2gray(image);     % 影象灰度化
axes(handles.axes2);
imshow(gray);

% --- 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)
%image = handles.I; 
%gray = rgb2gray(image);
%new_gray = histeq(gray); % 直方圖均衡 ,影象增強
%axes(handles.axes3);
%imshow(new_gray);

% --- 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)
image =  handles.I; 
gray = rgb2gray(image);     
new_gray = histeq(gray);  % 直方圖均衡 ,影象增強
if size(new_gray,1)>1000
   new_gray_1 = imresize(new_gray,0.1);
else
   new_gray_1 =new_gray;
end
bw = edge(new_gray_1,'canny');                    
axes(handles.axes4);
imshow(bw);
guidata(hObject, handles); 
% --- Executes on button press in pushbutton9.
function pushbutton9_Callback(hObject, eventdata, handles)
% hObject   handle to pushbutton9 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
%% 字元識別
images_test_all = handles.testnum;
nnmain;
for i = 1:size(images_test_all,2) 
  images_test = double(images_test_all(:,i));
  pred(i) = predict(Theta1, Theta2, images_test');   
end
chepai = [];
for i = 1:size(pred,2)
   if pred(i)>0 
    chepai = [chepai,Name{pred(i)}];
   end
end
% chepai(1) = '蘇';

set(handles.text2,'string',chepai);

% --- Executes on button press in pushbutton10.
function pushbutton10_Callback(hObject, eventdata, handles)
% hObject   handle to pushbutton10 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles   structure with handles and user data (see GUIDATA)
%% 這個按鈕關閉軟體
close all;
clear;
clc;

3 模擬結果

4 參考文獻

[1]馮知凡. 基於影象處理及BP神經網路的車牌識別技術的研究. Diss. 武漢科技大學, 2011.

部分理論參照網路文獻,若有侵權聯絡博主刪除。

5 MATLAB程式碼與資料下載地址

見部落格主頁頭條