function varargout = chepaishibiegui(varargin)
% CHEPAISHIBIEGUI MATLAB code for chepaishibiegui.fig
% CHEPAISHIBIEGUI, by itself, creates a new CHEPAISHIBIEGUI or raises the existing
% singleton*.
%
% H = CHEPAISHIBIEGUI returns the handle to a new CHEPAISHIBIEGUI or the handle to
% the existing singleton*.
%
% CHEPAISHIBIEGUI('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CHEPAISHIBIEGUI.M with the given input arguments.
%
% CHEPAISHIBIEGUI('Property','Value',...) creates a new CHEPAISHIBIEGUI or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before chepaishibiegui_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to chepaishibiegui_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 chepaishibiegui
% Last Modified by GUIDE v2.5 01-Feb-2020 17:50:29
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @chepaishibiegui_OpeningFcn, ...
'gui_OutputFcn', @chepaishibiegui_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 chepaishibiegui is made visible.
function chepaishibiegui_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 chepaishibiegui (see VARARGIN)
% Choose default command line output for chepaishibiegui
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes chepaishibiegui wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = chepaishibiegui_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)
[fname,pname,index] = uigetfile({'*.jpg';'*.bmp'},'选择图片');
if index
str = [pname fname];
c = imread(str);
axes(handles.chepai);
imshow(c);
I = c;
title('测试图像');
I1=rgb2gray(I);
I2=edge(I1,'roberts',0.18,'both');
se=[1;1;1];
I3=imerode(I2,se);
se=strel('rectangle',[25,25]);
I4=imclose(I3,se);
[n1, n2] = size(I4);
I4(1:round(n1/3), 1:n2) = 0;
r = floor(n1/10);
c = floor(n2/10);
I4(1:r,:)=0;
I4((9*r):n1,:)=0;
I4(:,1:c)=0;
I4(:,(c*9):n2)=0;
I5=bwareaopen(I4,200);
[y,x,z]=size(I5);
myI = double(I5);
tic
Blue_y=zeros(y,1);
for i=1:y
for j=1:x
if(myI(i,j,1)==1)
Blue_y(i,1)=Blue_y(i,1)+1;
end
end
end
[temp MaxY] = max(Blue_y);
PY1=MaxY;
while((Blue_y(PY1,1)>=5)&&(PY1>1))
PY1=PY1-1;
end
PY2=MaxY;
while ((Blue_y(PY2,1)>=5)&&(PY2<y))
PY2=PY2+1;
end
IY=I(PY1:PY2,:,:);
% figure,imshow(IY);
Blue_x=zeros(1,x);
for j=1:x
for i=PY1:PY2
if(myI(i,j,1)==1)
Blue_x(1,j)=Blue_x(1,j)+1;
end
end
end
% [tempx MaxX] = max(Blue_x);
PX1=1;
[Irow,Icol,Idisanwei] = size(I);
while((Blue_x(1,PX1)<3)&&(PX1<x))
PX1=PX1+1;
end
PX2=x;
while ((Blue_x(1,PX2)<3)&&(PX2>PX1))
PX2=PX2-1;
end
PX1=PX1-1;
PX2=PX2;
% dw=I(PY1:(PY2-8),PX1:PX2,:);
dw=I((PY1):(PY2),PX1:PX2,:);
t=toc;
if ((PX2-PX1)/(PY2-PY1))>4.6
PX1=1;
[Irow,Icol,Idisanwei] = size(I);
while((Blue_x(1,PX1)<11)&&(PX1<x))
PX1=PX1+1;
end
PX2=x;
while ((Blue_x(1,PX2)<11)&&(PX2>PX1))
PX2=PX2-1;
end
PX1=PX1-1;
PX2=PX2;
dw=I((PY1):(PY2),PX1:PX2,:);
end
imwrite(dw,'dw.jpg');
a=imread('dw.jpg');
axes(handles.chepaijieguo)
imshow(a)
title('车牌分割结果')
b=rgb2gray(a);
imwrite(b,'gray licence plate.jpg');
g_max=double(max(max(b)));
g_min=double(min(min(b)));
T=round(g_max-(g_max-g_min)/3);
[m,n]=size(b);
d=(double(b)>=T);
imwrite(d,'binary licence plate.jpg');
h=fspecial('average',3);
d=im2bw(round(filter2(h,d)));
imwrite(d,'after average licence plate.jpg');
se=eye(2);
[m,n]=size(d);
if bwarea(d)/m/n>=0.365
d=imerode(d,se);
elseif bwarea(d)/m/n<=0.235
d=imdilate(d,se);
end
imwrite(d,'expansion or corrosion the licence plate.jpg');
[dw1,dw2,dw3]=size(dw);
fanwei = round(0.0026*dw1*dw2);
d=bwareaopen(d,fanwei);
d=qiege(d);
[m,n]=size(d);
if (n/m)<4
row = m-(n/(4.1));
d = d(round(row):m,1:n);
end
k1=1;
k2=1;
s=sum(d);
j=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(d(:,[k1+5:k2-5])));%
d(:,k1+num+5)=0; %
end
end
% 再切割
d=qiege(d);
y1=10;y2=0.25;flag=0;word1=[];
while flag==0
[m,n]=size(d);
left=1;wide=0;
while sum(d(:,wide+1))~=0
wide=wide+1;
end
if (wide<5)&&(sum(d(:,wide+1))<(10/m))
d(:,[1:wide])=0;
d=qiege(d);
else
temp=qiege(imcrop(d,[1 1 wide m]));
[m,n]=size(temp);
all=sum(sum(temp));
two_thirds=sum(sum(temp([round(m/3):2*round(m/3)],:)));
if two_thirds/all>y2
flag=1;word1=temp; % WORD 1
end
d(:,[1:wide])=0;d=qiege(d);
end
end
[word2,d]=getword(d);
[word2row,word2col] = size(word2);
whitesizeofword2 = round(word2row*word2col/12)+1;
word2=bwareaopen(word2,whitesizeofword2);
word2=qiege(word2);
% 分割出第三个字符
[word3,d]=getword(d);
% 分割出第四个字符
[word4,d]=getword(d);
% 分割出第五个字符
[word5,d]=getword(d);
% 分割出第六个字符
[word6,d]=getword(d);
[word6row,word6col] = size(word6);
whitesizeofword6 = round(word6row*word6col/12)+1;
word6=bwareaopen(word6,whitesizeofword6);
word6=qiege(word6);
% 分割出第七个字符
[word7,d]=getword(d);
[m,n]=size(word1);
word1=imresize(word1,[32 16]);
word2=wordprocess(word2);
word3=wordprocess(word3);
word4=wordprocess(word4);
word5=wordprocess(word5);
word6=wordprocess(word6);
word7=wordprocess(word7);
axes(handles.zifu1);
imshow(word1);
title('1')
axes(handles.zifu2);
评论0