找回密码
 注册
关于网站域名变更的通知
查看: 680|回复: 4
打印 上一主题 下一主题

基于matlab银行监控系统人脸识别

[复制链接]
  • TA的每日心情

    2019-11-20 15:22
  • 签到天数: 2 天

    [LV.1]初来乍到

    跳转到指定楼层
    1#
    发表于 2021-6-9 14:17 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式

    EDA365欢迎您登录!

    您需要 登录 才可以下载或查看,没有帐号?注册

    x
    一、简介6 l9 C" w: F* c1 X! V) d6 h0 n
    用matlab做的多人场景的人脸识别。先预处理,人脸定位,分割,训练,PCA降维求出协方差矩阵,人脸特征值,然后每个测试的人脸分别进行矩阵求列,作差对比,结果最小的就是目标人脸,输出识别结果,这个设计有可视化GUI用户操作界面。" C/ _0 A  ^" x9 r

    # `" [9 {2 Z# ~- _3 ?- _二、源代码7 j% q. v* Q4 X

    3 Z- i+ a) l& C/ z
    • function varargout = Main(varargin)
    • % MAIN MATLAB code for Main.fig
    • %      MAIN, by itself, creates a new MAIN or raises the existing
    • %      singleton*.
    • %
    • %      H = MAIN returns the handle to a new MAIN or the handle to
    • %      the existing singleton*.
    • %
    • %      MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
    • %      function named CALLBACK in MAIN.M with the given input arguments.
    • %
    • %      MAIN('Property','Value',...) creates a new MAIN or raises the
    • %      existing singleton*.  Starting from the left, property value pairs are
    • %      applied to the GUI before Main_OpeningFcn gets called.  An
    • %      unrecognized property name or invalid value makes property application
    • %      stop.  All inputs are passed to 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 Main
    • % Last Modified by GUIDE v2.5 21-Nev-2020 01:12:36
    • % Begin initialization code - DO NOT EDIT
    • gui_Singleton = 1;
    • gui_State = struct('gui_Name',       mfilename, ...
    •                    'gui_Singleton',  gui_Singleton, ...
    •                    'gui_OpeningFcn', @Main_OpeningFcn, ...
    •                    'gui_OutputFcn',  @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 Main is made visible.
    • function 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 Main (see VARARGIN)
    • % Choose default command line output for Main
    • handles.output = hObject;
    • % Update handles structure
    • guidata(hObject, handles);
    • % UIWAIT makes Main wait for user response (see UIRESUME)
    • % uiwait(handles.figure1);
    • % --- Outputs from this function are returned to the command line.
    • function varargout = 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;
    • function edit1_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit1 (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 edit1 as text
    • %        str2double(get(hObject,'String')) returns contents of edit1 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit1_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit1 (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 edit2_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit2 (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 edit2 as text
    • %        str2double(get(hObject,'String')) returns contents of edit2 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit2_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit2 (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 edit3_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit3 (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 edit3 as text
    • %        str2double(get(hObject,'String')) returns contents of edit3 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit3_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit3 (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 edit4_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit4 (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 edit4 as text
    • %        str2double(get(hObject,'String')) returns contents of edit4 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit4_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit4 (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 pushbutton1.
    • function pushbutton1_Callback(hObject, eventdata, handles)
    • set(handles.edit1,'string','思路:提前制作好合影中人员的人脸库,进行训练好')
    • % --- Executes on button press in pushbuttonfacedetect.
    • function pushbuttonfacedetect_Callback(hObject, eventdata, handles)
    • % hObject    handle to pushbuttonfacedetect (see GCBO)
    • % eventdata  reserved - to be defined in a future version of MATLAB
    • % handles    structure with handles and user data (see GUIDATA)
    • %如果还没载入图像
    • if(~isfield(handles,'I'))
    •      str = sprintf('你还未载入图像!');
    •     set(handles.reporttext,'string',str);
    •     return
    • end
    • I = handles.I;
    • [faceI,box] = facedetect(I);
    • if(~isempty(faceI)) %如果检测出人脸
    •     axes(handles.axes1)
    •     rectangle('Position',box,'EdgeColor','r');%原图圈起来
    •     axes(handles.axes2)
    •     imshow(faceI)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • handles.faceI = faceI;
    • % Update handles structure
    • guidata(hObject, 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 button press in pushbutton2.
    • function pushbutton2_Callback(hObject, eventdata, handles)
    •    set(handles.edit2,'string','思路:从合影中,定位到人脸,并且分割到对应框里面显示')
    • % --- Executes on button press in pushbuttonfacedetect.
    • function pushbuttonfacedetect_Callback(hObject, eventdata, handles)
    • % hObject    handle to pushbuttonfacedetect (see GCBO)
    • % eventdata  reserved - to be defined in a future version of MATLAB
    • % handles    structure with handles and user data (see GUIDATA)
    • %如果还没载入图像
    • if(~isfield(handles,'I'))
    •      str = sprintf('你还未载入图像!');
    •     set(handles.reporttext,'string',str);
    •     return
    • end
    • I = handles.I;
    • [faceI,box] = facedetect(I);
    • if(~isempty(faceI)) %如果检测出人脸
    •     axes(handles.axes1)
    •     rectangle('Position',box,'EdgeColor','r');%原图圈起来
    •     axes(handles.axes2)
    •     imshow(faceI)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • handles.faceI = faceI;
    • % Update handles structure
    • guidata(hObject, 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)
    • % --- Executes on button press in pushbutton3.
    • function pushbutton3_Callback(hObject, eventdata, handles)
    • set(handles.edit3,'string','思路:分别对每个人脸进行识别出是谁')
    • % --- Executes on button press in pushbuttonfacedetect.
    • function pushbuttonfacedetect_Callback(hObject, eventdata, handles)
    • % hObject    handle to pushbuttonfacedetect (see GCBO)
    • % eventdata  reserved - to be defined in a future version of MATLAB
    • % handles    structure with handles and user data (see GUIDATA)
    • %如果还没载入图像
    • if(~isfield(handles,'I'))
    •      str = sprintf('你还未载入图像!');
    •     set(handles.reporttext,'string',str);
    •     return
    • end
    • I = handles.I;
    • [faceI,box] = facedetect(I);
    • if(~isempty(faceI)) %如果检测出人脸
    •     axes(handles.axes1)
    •     rectangle('Position',box,'EdgeColor','r');%原图圈起来
    •     axes(handles.axes2)
    •     imshow(faceI)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • handles.faceI = faceI;
    • % Update handles structure
    • guidata(hObject, 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)
    • % --- Executes on button press in pushbutton4.
    • function pushbutton4_Callback(hObject, eventdata, handles)
    • set(handles.edit4,'string','拓展:应用场景可换为教室考勤,宿舍考勤,动车站等公共场所')
    • % 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)
    • function edit5_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit5 (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 edit5 as text
    • %        str2double(get(hObject,'String')) returns contents of edit5 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit5_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit5 (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 edit6_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit6 (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 edit6 as text
    • %        str2double(get(hObject,'String')) returns contents of edit6 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit6_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit6 (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 edit7_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit7 (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 edit7 as text
    • %        str2double(get(hObject,'String')) returns contents of edit7 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit7_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit7 (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 edit8_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit8 (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 edit8 as text
    • %        str2double(get(hObject,'String')) returns contents of edit8 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit8_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit8 (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 pushbutton9.
    • function pushbutton9_Callback(hObject, eventdata, handles)
    • I = imread('5.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit5,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, 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)
    • % --- Executes on button press in pushbutton10.
    • function pushbutton10_Callback(hObject, eventdata, handles)
    • I = imread('6.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, 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)
    • % --- Executes on button press in pushbutton11.
    • function pushbutton11_Callback(hObject, eventdata, handles)
    • I = imread('7.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton11 (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 pushbutton12.
    • function pushbutton12_Callback(hObject, eventdata, handles)
    • I = imread('8.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton12 (see GCBO)
    • % eventdata  reserved - to be defined in a future version of MATLAB
    • % handles    structure with handles and user data (see GUIDATA)
    • function edit9_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit9 (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 edit9 as text
    • %        str2double(get(hObject,'String')) returns contents of edit9 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit9_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit9 (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 edit10_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit10 (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 edit10 as text
    • %        str2double(get(hObject,'String')) returns contents of edit10 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit10_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit10 (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 edit11_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit11 (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 edit11 as text
    • %        str2double(get(hObject,'String')) returns contents of edit11 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit11_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit11 (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 edit12_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit12 (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 edit12 as text
    • %        str2double(get(hObject,'String')) returns contents of edit12 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit12_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit12 (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 pushbutton13.
    • function pushbutton13_Callback(hObject, eventdata, handles)
    • I = imread('9.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton13 (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 pushbutton14.
    • function pushbutton14_Callback(hObject, eventdata, handles)
    • I = imread('10.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton14 (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 pushbutton15.
    • function pushbutton15_Callback(hObject, eventdata, handles)
    • I = imread('11.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton15 (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 pushbutton16.
    • function pushbutton16_Callback(hObject, eventdata, handles)
    • I = imread('12.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton16 (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 pushbutton17.
    • function pushbutton17_Callback(hObject, eventdata, handles)
    • [filename, pathname] = uigetfile( ...
    • {'*.jpg;*.png;*.jpeg', 'Image Files (*.bmp;*.jpg;*.png;*.jpeg)'; ...
    • '*.*', 'All Files (*.*)'}, ...
    • 'Pick an image');
    • if isequal(filename,0) || isequal(pathname,0),
    • return;
    • end
    • fpath=[pathname filename];      %将文件名和目录名组合成一个完整的路径
    • img=imread(fpath);
    • axes(handles.axes1)
    • imshow(img)
    • title('合影图片')
    • msgbox('感兴趣,可加Q讨论,1183814288')
    • % hObject    handle to pushbutton17 (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 pushbutton18.
    • function pushbutton18_Callback(hObject, eventdata, handles)
    • msgbox('数数部分思路:定位器实现')
    • set(handles.reporttext,'string','课题定制,Q:1183814288')
    • % hObject    handle to pushbutton18 (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 pushbutton19.
    • function pushbutton19_Callback(hObject, eventdata, handles)
    • ax2=(handles.axes2);cla(ax2,'reset')
    • ax3=(handles.axes3);cla(ax3,'reset')
    • ax4=(handles.axes4);cla(ax4,'reset')
    • ax5=(handles.axes5);cla(ax5,'reset')
    • % hObject    handle to pushbutton19 (see GCBO)
    • % eventdata  reserved - to be defined in a future version of MATLAB
    • % handles    structure with handles and user data (see GUIDATA)
    • function edit13_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit13 (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 edit13 as text
    • %        str2double(get(hObject,'String')) returns contents of edit13 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit13_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit13 (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 reporttext_Callback(hObject, eventdata, handles)
    • % hObject    handle to reporttext (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 reporttext as text
    • %        str2double(get(hObject,'String')) returns contents of reporttext as a double
    • % --- Executes during object creation, after setting all properties.
    • function reporttext_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to reporttext (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 edit15_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit15 (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 edit15 as text
    • %        str2double(get(hObject,'String')) returns contents of edit15 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit15_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit15 (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 edit16_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit16 (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 edit16 as text
    • %        str2double(get(hObject,'String')) returns contents of edit16 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit16_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit16 (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 edit17_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit17 (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 edit17 as text
    • %        str2double(get(hObject,'String')) returns contents of edit17 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit17_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit17 (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 edit18_Callback(hObject, eventdata, handles)
    • % hObject    handle to edit18 (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 edit18 as text
    • %        str2double(get(hObject,'String')) returns contents of edit18 as a double
    • % --- Executes during object creation, after setting all properties.
    • function edit18_CreateFcn(hObject, eventdata, handles)
    • % hObject    handle to edit18 (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 pushbutton20.
    • function pushbutton20_Callback(hObject, eventdata, handles)
    • I = imread('10.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton14 (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 pushbutton15.
    • function pushbutton15_Callback(hObject, eventdata, handles)
    • I = imread('13.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton20 (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 pushbutton21.
    • function pushbutton21_Callback(hObject, eventdata, handles)
    • I = imread('10.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton14 (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 pushbutton15.
    • function pushbutton15_Callback(hObject, eventdata, handles)
    • I = imread('14.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton21 (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 pushbutton22.
    • function pushbutton22_Callback(hObject, eventdata, handles)
    • I = imread('10.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton14 (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 pushbutton15.
    • function pushbutton15_Callback(hObject, eventdata, handles)
    • I = imread('15.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    •     %axes(handles.axes1)
    •     %imshow(faceI)
    •     strtitle = sprintf('识别结果第%d人',classlabel);
    •     title(strtitle)
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton22 (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 pushbutton23.
    • function pushbutton23_Callback(hObject, eventdata, handles)
    • I = imread('10.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton14 (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 pushbutton15.
    • function pushbutton15_Callback(hObject, eventdata, handles)
    • I = imread('16.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton23 (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 pushbutton24.
    • function pushbutton24_Callback(hObject, eventdata, handles)
    • I = imread('10.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    •     classlabel = trainlabel(minindex);%测出的类别序号
    •     %str = sprintf('识别完成,识别此照片为第%d人。',classlabel);
    •     set(handles.edit4,'string',classlabel);
    •     drawnow
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton14 (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 pushbutton15.
    • function pushbutton15_Callback(hObject, eventdata, handles)
    • I = imread('11.bmp');%读取图片
    • %存入到handles内,以便被别的函数调用
    • handles.I = I;
    • handles.faceI = I;
    • % Update handles structure
    • load trainresult.mat
    • if(isfield(handles,'faceI') && ~isempty(handles.faceI)) %如果检测出人脸
    •     faceI = handles.faceI;
    •     [M,N,color] = size(faceI);%获取图片的大小,以及色彩类型
    •     if color == 3%如果是彩色图片
    •         I = rgb2gray(faceI);%转为灰度图片
    •     else
    •         I = faceI;
    •     end
    •     % I1= imadjust(I1,stretchlim(I1));%灰度变换,图像增强
    •     if (isequal([M,N],goalsize) == 0)%如果不是64*64的
    •         I = imresize(I,goalsize);%转为固定的64*64的
    •     end
    •     samplesnum = size(PCAfeatures,1);%训练样本个数
    •     I1 = I(:);%图像转为1列矩阵
    •     I1 = double(I1');
    •     Z=(I1-mA);%减去均值
    •     feature1 = Z*V;%降维得到PCA特征
    •     dd = zeros(1,samplesnum);
    •     for j = 1:samplesnum%遍历训练样本
    •         feature2 = PCAfeatures(j,:);%取出一个特征
    •         d = mydist(feature1,feature2);%计算特征之间的距离
    •         dd(j) = d;%距离存起来 用于排序
    •     end
    •     [value,minindex] = min(dd);%最小值,以及所在位置
    • else
    •    set(handles.reporttext,'string','没有检测到人脸,无法识别!');
    • end
    • guidata(hObject, handles);
    • % hObject    handle to pushbutton24 (see GCBO)
    • % eventdata  reserved - to be defined in a future version of MATLAB
    • % handles    structure with handles and user data (see GUIDATA)

    • : G' A' R- M$ x5 Y& T  z; v

    ; s! V; D: m# T! j+ m. M: @0 l3 n8 E% L

    # q* @+ ~# R+ i% S/ S二、运行4 r$ E  p2 O) y# Q/ ]( A
    ) K. _, Y/ P7 y# A0 r

    . J9 q0 ]# T2 r

    该用户从未签到

    2#
    发表于 2021-6-9 15:04 | 只看该作者
    基于matlab银行监控系统人脸识别

    该用户从未签到

    3#
    发表于 2021-6-9 15:05 | 只看该作者
    基于matlab银行监控系统人脸识别

    该用户从未签到

    4#
    发表于 2021-6-9 15:06 | 只看该作者
    基于matlab银行监控系统人脸识别

    该用户从未签到

    5#
    发表于 2021-6-10 18:25 | 只看该作者
    基于matlab银行监控系统人脸识别
    您需要登录后才可以回帖 登录 | 注册

    本版积分规则

    关闭

    推荐内容上一条 /1 下一条

    EDA365公众号

    关于我们|手机版|EDA365电子论坛网 ( 粤ICP备18020198号-1 )

    GMT+8, 2025-6-17 19:27 , Processed in 0.109375 second(s), 26 queries , Gzip On.

    深圳市墨知创新科技有限公司

    地址:深圳市南山区科技生态园2栋A座805 电话:19926409050

    快速回复 返回顶部 返回列表