ARTICLE DETAIL

资讯详情

深耕网站建设与运营推广的一线实战洞察。

【图像识别】基于PCA+LDA算法人脸识别matlab代码

【图像识别】基于PCA+LDA算法人脸识别matlab代码 1 简介随着社会的进步和科技的发展,生物特征的识别应用越来越多.如海关及公安系统等需要提供准确的身份认证,日常生活中,人们的安全,财产,隐私等都需要利用先进的科技手段进行保护.因此如何能够高效,快速,可靠识别生物身份的系统被人们普遍研究.本文寻求了一种主成分分析(PCA)和线性判别分析(LDA)相结合的方法对人脸进行识别.主成分分析Principal Component Analysis算法简称 PCA是一种有效的特征提取方法算法将人脸图像转换成一个列向量经过变换后可以有效降低其维数又能保留有效的识别信息这些有效信息构成了一组特征图像并且这些信息对人脸的光照、表情、姿态等具有相当的不敏感性。PCA 变换的目的是通过线性变换找到一组最优的单位正交向量基即主成分用线性组合来重构与原样本均方差的误差最小的一种变换方法。数学上PCA 通过求解投影矩阵来获得低维度的特征向量。对于某 K 维向量来说在原有的K 维坐标中它的特征向量在各个维度上的变化均不明显我们可以通过改变其所处的坐标轴来使它的特征向量在某些坐标轴上的变化更加明显。例如在X 轴、Y 轴平面上将一个椭圆倾斜放置在第一象限内X、Y 轴上的投影变化度都不是很大但在将椭圆的长轴作为 X 轴后椭圆在 X 轴的投影范围变得更大方差也更大但在 Y 轴的投影范围变得更小方差也更小。这时我们就可以消除掉 Y 轴的特征信息只保留 X 轴的特征信息这便完成了高维信息向低维的转换。​2 部分代码function varargout faceCore(varargin) % FACECORE M-file for faceCore.fig % FACECORE, by itself, creates a new FACECORE or raises the existing % singleton*. % % H FACECORE returns the handle to a new FACECORE or the handle to % the existing singleton*. % % FACECORE(CALLBACK,hObject,eventData,handles,...) calls the local % function named CALLBACK in FACECORE.M with the given input arguments. % % FACECORE(Property,Value,...) creates a new FACECORE or raises the % existing singleton*. Starting from the left, property value pairs are % applied to the GUI before faceCore_OpeningFunction gets called. An % unrecognized property name or invalid value makes property application % stop. All inputs are passed to faceCore_OpeningFcn via varargin. % % *See GUI Options on GUIDEs Tools menu. Choose GUI allows only one % instance to run (singleton). % % See also: GUIDE, GUIDATA, GUIHANDLES % Copyright % Edit the above text to modify the response to help faceCore % Last Modified by GUIDE v2.5 11-Apr-2021 23:45:58 % Begin initialization code - DO NOT EDIT gui_Singleton 1; gui_State struct(gui_Name, mfilename, ... gui_Singleton, gui_Singleton, ... gui_OpeningFcn, faceCore_OpeningFcn, ... gui_OutputFcn, faceCore_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 faceCore is made visible. function faceCore_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 faceCore (see VARARGIN) % Choose default command line output for faceCore handles.output hObject; % Update handles structure guidata(hObject, handles); % UIWAIT makes faceCore wait for user response (see UIRESUME) % uiwait(handles.figure1); % --- Outputs from this function are returned to the command line. function varargout faceCore_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) global TrainDatabasePath ; TrainDatabasePath uigetdir(strcat(matlabroot,\work), 训练库路径选择... ); % --- 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) global TestDatabasePath; TestDatabasePath uigetdir(strcat(matlabroot,\work), 测试库路径选择...); % --- 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) %[filename,pathname]uigetfile({*.jpg;*.bmp},••••••••); %str[pathname filename]; %imimread(str); %axes(handles.axes1); %imshow(im); % --- 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) global TrainDatabasePath ; global TestDatabasePath; global T; T CreateDatabase(TrainDatabasePath); %[m V_PCA V_Fisher ProjectedImages_Fisher] FisherfaceCore(T); % --- Executes on button press in pushbutton5. function pushbutton9_Callback(hObject, eventdata, handles) % hObject handle to pushbutton5 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global im; [filename,pathname]uigetfile({*.jpg;*.bmp},选择测试图片...); str[pathname filename]; imimread(str); axes(handles.axes1); imshow(im); % --- Executes on button press in pushbutton6. function pushbutton6_Callback(hObject, eventdata, handles) % hObject handle to pushbutton6 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %T CreateDatabase(TrainDatabasePath); global T; global im; global TrainDatabasePath ; [m V_PCA V_Fisher ProjectedImages_Fisher] FisherfaceCore(T); OutputName Recognition(im, m, V_PCA, V_Fisher, ProjectedImages_Fisher); SelectedImage strcat(TrainDatabasePath,\,OutputName); SelectedImage imread(SelectedImage); axes(handles.axes2); imshow(SelectedImage); %title(Equivalent Image); % --- Executes on button press in pushbutton7. function pushbutton7_Callback(hObject, eventdata, handles) % hObject handle to pushbutton7 (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % clear all; % clc % close(gcf); global T; global TrainDatabasePath ; [m V_PCA V_Fisher ProjectedImages_Fisher] FisherfaceCore(T); file_path .\TestDatabase\;% 图像文件夹路径 img_path_list dir(strcat(file_path,*.jpg));%获取该文件夹中所有jpg格式的图像 img_num length(img_path_list);%获取图像总数量 s0;%识别成功个数 if img_num 0 %有满足条件的图像 for j 1:img_num %逐一读取图像 image_name img_path_list(j).name;% 图像名 im imread(strcat(file_path,image_name)); [OutputName,indx] Recognition(im, m, V_PCA, V_Fisher, ProjectedImages_Fisher); if indxj*2-1||indx2*j ss1; end end end shibielvs/img_num*100;%识别率 set(handles.text3,String,[识别率,num2str(shibielv),%]); % --- 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)3 仿真结果4 参考文献[1]樊春玲, and 陈秀霆. 基于PCA和LDA的人脸识别系统设计. 控制工程 19.4(2012):4.部分理论引用网络文献若有侵权联系博主删除。
返回列表