2019/12/17 机器视觉课设第九天,初步完成了用户登录界面、新用户注册界面、模式选择界面、图像处理界面;
基于Matlab的车牌识别
关于GUI设计界面
用户登录界面
function varargout = consumer(varargin)
% CONSUMER MATLAB code for consumer.fig
% CONSUMER, by itself, creates a new CONSUMER or raises the existing
% singleton*.
%
% H = CONSUMER returns the handle to a new CONSUMER or the handle to
% the existing singleton*.
%
% CONSUMER('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in CONSUMER.M with the given input arguments.
%
% CONSUMER('Property','Value',...) creates a new CONSUMER or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before consumer_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to consumer_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 consumer
% Last Modified by GUIDE v2.5 16-Dec-2019 21:32:24
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @consumer_OpeningFcn, ...
'gui_OutputFcn', @consumer_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 consumer is made visible.
function consumer_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 consumer (see VARARGIN)
% Choose default command line output for consumer
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes consumer wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = consumer_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;
warning off all;%关闭所有警告
function username_Callback(hObject, eventdata, handles)
% hObject handle to username (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of username as text
% str2double(get(hObject,'String')) returns contents of username as a double
% --- Executes during object creation, after setting all properties.
function username_CreateFcn(hObject, eventdata, handles)
% hObject handle to username (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function password_Callback(hObject, eventdata, handles)
% hObject handle to password (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of password as text
% str2double(get(hObject,'String')) returns contents of password as a double
% --- Executes during object creation, after setting all properties.
function password_CreateFcn(hObject, eventdata, handles)
% hObject handle to password (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes on button press in enter.
function enter_Callback(hObject, eventdata, handles)
% hObject handle to enter (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
userChar = get( handles.username, 'string' );
passChar = get( handles.password, 'string' );
fid = fopen(userChar,'r');
keyWord=fscanf(fid,'%s'); % \n 换行
fclose(fid);
% % n = find( strcmp(accountNumber, {userChar}) ); % 判断输入的用户名和默认值是否一致。如果一致,则 n 非空
% ~isempty( n ) &&
if strcmp( keyWord,{passChar} )
h = msgbox( '欢迎使用本系统!' );%建立文本框显示 “欢迎”
uiwait( h );
delete( gcf ); % 关闭当前的用户登录界面
inside
% filename; % 完成页面跳转,filename 为新的页面的名字!!!!
else
errordlg( '账号或密码错误!' );%建立错误对话框
end
% --- Executes on button press in close.
function close_Callback(hObject, eventdata, handles)
% hObject handle to close (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
close; %关闭
% --- Executes on button press in applyn.
function applyn_Callback(hObject, eventdata, handles)
% hObject handle to applyn (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
delete( gcf ); % 关闭当前的用户登录界面
apply %切换到apply界面
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
ha=axes('units','normalized','pos',[0 0 1 1]);
uistack(ha,'down');
ii=imread('notwo.jpg');
image(ii);
colormap gray
set(ha,'handlevisibility','off','visible','on');
一开始的设计要求包含用户登录界面的设计,因此在设计构思准备阶段遇到了新用户注册实例,锦上添花
用户注册界面
function varargout = apply(varargin)
% APPLY MATLAB code for apply.fig
% APPLY, by itself, creates a new APPLY or raises the existing
% singleton*.
%
% H = APPLY returns the handle to a new APPLY or the handle to
% the existing singleton*.
%
% APPLY('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in APPLY.M with the given input arguments.
%
% APPLY('Property','Value',...) creates a new APPLY or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before apply_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to apply_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 apply
% Last Modified by GUIDE v2.5 16-Dec-2019 21:34:05
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @apply_OpeningFcn, ...
'gui_OutputFcn', @apply_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 apply is made visible.
function apply_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 apply (see VARARGIN)
% Choose default command line output for apply
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes apply wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = apply_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)
newuserChar = get( handles.newuser, 'string' );
newpassChar = get( handles.newpassword, 'string' );
fid = fopen(newuserChar,'w+');
fprintf(fid,'%s\n',newpassChar); % \n 换行
fclose(fid);
h = msgbox( '注册成功!' );%建立文本框显示 “欢迎”
uiwait( h );
delete( gcf ); % 关闭当前的用户登录界面
consumer
% --- 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)
delete( gcf ); % 关闭当前的用户登录界面
consumer
function newuser_Callback(hObject, eventdata, handles)
% hObject handle to newuser (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes during object creation, after setting all properties.
function newuser_CreateFcn(hObject, eventdata, handles)
% hObject handle to newuser (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
function newpassword_Callback(hObject, eventdata, handles)
% hObject handle to newpassword (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'String') returns contents of newpassword as text
% str2double(get(hObject,'String')) returns contents of newpassword as a double
% --- Executes during object creation, after setting all properties.
function newpassword_CreateFcn(hObject, eventdata, handles)
% hObject handle to newpassword (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
% Hint: edit controls usually have a white background on Windows.
% See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
set(hObject,'BackgroundColor','white');
end
% --- Executes during object creation, after setting all properties.
function figure1_CreateFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles empty - handles not created until after all CreateFcns called
ha=axes('units','normalized','pos',[0 0 1 1]);
uistack(ha,'down');
ii=imread('noone.jpg');
image(ii);
colormap gray
set(ha,'handlevisibility','off','visible','on');