1 读取拍摄图像—>截取车牌部分—>识别车牌
2 图像预处理:
将图像经过图像灰度化、图像增强、边缘提取、二值化等操作,转换成便于车牌定位的二值化图像;
3 车牌定位:
利用车牌的边缘、形状等特征,再结合Roberts 算子边缘检测、数字图像、形态学等技术对车牌进行定位;
4 字符的分割:
采用的方法是将二值化后的车牌部分进行寻找连续有文字的块,若长度大于设定的阈值则切割,从而完成字符的分割;
5 字符识别:
运用模板匹配算法完成。
思路一:
读取图像::同上
截取车牌::基于HSV色域和SOBEL边缘提取车牌
识别车牌::将截取的车牌图像变换为二值图像, 切割之后与模板库叠加/相减(相同大小20*40)比例最高者就是对应字符
% ******************************************************
%
% time : 2021/05/26 17:12
% tip : 车牌识别
% change:
% *******************************************************
function varargout = CarId(varargin)
% CARID MATLAB code for CarId.fig
% CARID, by itself, creates a new CARID or raises the existing
% singleton*.
%
% H = CARID returns the handle to a new CARID or the handle to
% the existing singleton*.
%
% CARID('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CARID.M with the given input arguments.
%
% CARID('Property','Value',...) creates a new CARID or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before CarId_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to CarId_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 CarId
% Last Modified by GUIDE v2.5 26-May-2021 20:30:44
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @CarId_OpeningFcn, ...
'gui_OutputFcn', @CarId_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 CarId is made visible.
function CarId_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 CarId (see VARARGIN)
% Choose default command line output for CarId
handles.output = hObject;
%隐藏坐标轴
set(handles.axes1,'visible','off');
set(handles.axes2,'visible','off');
set(handles.axes3,'visible','off');
set(handles.axes4,'visible','off');
set(handles.axes5,'visible','off');
set(handles.axes6,'visible','off');
set(handles.axes7,'visible','off');
set(handles.axes8,'visible','off');
set(handles.axes9,'visible','off');
set(handles.axes10,'visible','off');
set(handles.axes11,'visible','off');
set(handles.axes12,'visible','off');
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes CarId wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = CarId_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;
%======================my code========================%
% tip : 被删除的callback自己手动添加一下...55555.....
function openLocal_Callback(hObject,eventdata,handles)
[filename, pathname]=uigetfile({
'*.jpg; *.png; *.bmp; *.tif';'*.png';'All Image Files';'*.*'},'请选择图片路径');
if pathname==0
return;
end
I=imread([pathname filename]);
%显示原图
axes(handles.axes1) %将Tag值为axes1的坐标轴置为当前
imshow(I,[]); %解决图像太大无法显示的问题.why?貌似会自动缩放
title('原图');
handles.I=I; %更新图像
% Update handles structure
guidata(hObject, handles);
function openCamera_Callback(hObject,eventdata,handles)
imaqhwinfo
vid = videoinput('winvideo',1);
usbVidRes1=get(vid,'videoResolution');%获取视频的尺寸
nBands1=get(vid,'NumberOfBands');%采集视频的颜色通道
axes(handles.axes1);
hImage1=imshow(zeros(usbVidRes1(2),usbVidRes1(1),nBands1));
preview(vid,hImage1);
handles.vid=vid;
% Update handles structure
guidata(hObject, handles);
function btnTakePhoto_Callback(hObject,eventdata,handles)
vid=handles.vid;
frame = getsnapshot(vid);
axes(handles.axes1);
imwrite(frame,'I.png');
I=imread('I.png');
axes(handles.axes1) %将Tag值为axes1的坐标轴置为当前
imshow(I,[]); %解决图像太大无法显示的问题.why?貌似会自动缩放
title('拍摄完成');
handles.I=I; %更新原图
% Update handles structure
guidata(hObject, handles);
%下面在使用原图方法: handles.I
% --- Executes on button press in btnGray2.
function btnGray2_Callback(hObject, eventdata, handles)
% hObject handle to btnGray2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.Cut;
I = rgb2gray(I);
axes(handles.axes8) %将Tag值为axes1的坐标轴置为当前
imshow(I,[]); %解决图像太大无法显示的问题.why?貌似会自动缩放
title('灰度处理');
handles.gray2=I; %更新原图
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in btnBalance.
function btnBalance_Callback(hObject, eventdata, handles)
% hObject handle to btnBalance (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.gray2;
I = histeq(I);
axes(handles.axes9) %将Tag值为axes1的坐标轴置为当前
imshow(I,[]); %解决图像太大无法显示的问题.why?貌似会自动缩放
title('直方图均衡化');
handles.balance=I; %更新原图
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in btnDouble.
function btnDouble_Callback(hObject, eventdata, handles)
% hObject handle to btnDouble (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.balance;
I = im2bw(I, 0.76);
axes(handles.axes10) %将Tag值为axes1的坐标轴置为当前
imshow(I,[]); %解决图像太大无法显示的问题.why?貌似会自动缩放
title('图像二值化');
handles.double=I; %更新原图
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in btnMid.
function btnMid_Callback(hObject, eventdata, handles)
% hObject handle to btnMid (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.double;
I = medfilt2(I);
axes(handles.axes11) %将Tag值为axes1的坐标轴置为当前
imshow(I,[]); %解决图像太大无法显示的问题.why?貌似会自动缩放
title('中值滤波');
handles.Mid=I; %更新原图
% Update handles structure
guidata(hObject, handles);
% --- Executes on button press in btnCut2.
function btnCut2_Callback(hObject, eventdata, handles)
% hObject handle to btnCut2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
I=handles.Mid;
I = my_imsplit(I); %切割图像
[m, n] = size(I);
s = sum(I); %sum(x)就是竖向相加,求每列的和,结果是行向量;
j = 1;
k1 = 1;
k2 = 1;
while j ~= n
while s(j) == 0
j = j + 1;
end
k1 = j;
while s(j) ~= 0 && j <= n-1
j = j + 1;
end
k2 = j + 1;
if k2 - k1 > round(n / 6.5)
[val, num] = min(sum(I(:, [k1+5:k2-5])));
I(:, k1+num+5) = 0;
end
end
版本:2014a