基于BP神经网络的人脸识别.doc

上传人:laozhun 文档编号:2390509 上传时间:2023-02-17 格式:DOC 页数:8 大小:202.50KB
返回 下载 相关 举报
基于BP神经网络的人脸识别.doc_第1页
第1页 / 共8页
基于BP神经网络的人脸识别.doc_第2页
第2页 / 共8页
基于BP神经网络的人脸识别.doc_第3页
第3页 / 共8页
基于BP神经网络的人脸识别.doc_第4页
第4页 / 共8页
基于BP神经网络的人脸识别.doc_第5页
第5页 / 共8页
点击查看更多>>
资源描述

《基于BP神经网络的人脸识别.doc》由会员分享,可在线阅读,更多相关《基于BP神经网络的人脸识别.doc(8页珍藏版)》请在三一办公上搜索。

1、基于BP神经网络的人脸识别学生:林仙土 学号:S071954 摘要:人脸自动识别技术有着广阔的应用领域,本文提出用主成分分析和BP神经网络进行人脸识别。人脸识别包括两个部分:第一,特征提取;第二,神经网络进行识别。 关键词:BP神经网络 人脸识别 主成分分析 本系统采用20幅图像(4个人每人5幅)作为训练图像,应用主成分分析对训练图像进行二阶相关和降维,提取训练图像的独立基成分构造人脸子空间,并将训练集中的人脸图像向独立基上投影得到的系数输入改进的BP神经网络进行训练。然后将待识别的人脸图像向独立基上投影得到投影系数,再将其输入已训练过的BP神经网络进行识别。此方法对人脸库图像进行测试,识别率

2、达到90%以上。本系统采用MATLAB编程,并运用了其中的GUI编程实现人机交互。 为在不同机子下顺利运行,本系统用uigetdir函数让用户选择训练图像库和待识别图像,使得待识别图像可在不同位置皆可让软件识别。 注意:待识别图像的名字必须是test.jpg。系统界面:程序:function varargout = BP(varargin)gui_Singleton = 1;gui_State = struct(gui_Name, mfilename, . gui_Singleton, gui_Singleton, . gui_OpeningFcn, BP_OpeningFcn, . gui_

3、OutputFcn, BP_OutputFcn, . gui_LayoutFcn, , . gui_Callback, );if nargin & ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);end if nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:);else gui_mainfcn(gui_State, varargin:);endfunction BP_OpeningFcn(hObject, eventdata, handles,

4、 varargin)handles.output = hObject; guidata(hObject, handles); % UIWAIT makes BP wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = BP_OutputFcn(hObject, eventdata, handles) % varargout cell array for re

5、turning 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 structurevarargout1 = handles.output; % - Executes on button pre

6、ss in input.function input_Callback(hObject, eventdata, handles)% hObject handle to input (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)global TestDatabasePathTestDatabasePath=uigetdir(D:, Select test database

7、path);axes(handles.axes1);a=imread(strcat(TestDatabasePath,test.jpg);imshow(a)set(handles.text1,string,image for recognition) % - Executes on button press in recognise.function recognise_Callback(hObject, eventdata, handles)% hObject handle to recognise (see GCBO)% eventdata reserved - to be defined

8、 in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)TrainDatabasePath=uigetdir(D:, Select training database path);global TestDatabasePathvalue=bpnet(TestDatabasePath,TrainDatabasePath)set(handles.text2,string,value)载入选择图像路径载入图像特征提取程序:function icaproject,wica=bpF

9、eatureExtract(imagepath)% 用于训练的图片数量Count=20;%图像格式为.jpg;S=; %用于存储20幅图像的矩阵for i=1:Countstr=strcat(imagepath,int2str(i),.jpg); %把两个字符串连接起来组成图像名eval(img=imread(str););row col=size(img); % 获得一幅图像的行数N1和列数N2temp=reshape(img,row*col,1); %产生一个(N1*N2)x1 matrixS=S temp; %S is a N1*N2xM matrixendsig=double(S);%

10、sig是MxN1*N2 matrix%对sig矩阵去均值处理sigmean=mean(sig);%对每一列取均值,imgsig是20x10304for i=1:size(sig)imgsig(i,:)=sig(i,:)-sigmean;end%对去均值的数据进行白化处理covariancematrix=cov(imgsig,1);%covariancematrix是20x20矩阵E,D=eig(covariancematrix);%E和D是20x20矩阵% 去掉值为0的特征值v=;d=;for i=1:size(E,2)if(D(i,i)0)v=v E(:,i);d=d D(i,i);ende

11、nd%将特征值由大到小排序,特征值对应的特征向量也作相应的排序Dccol=d;Vc=v;%从小到大排序Dcsort Dcindex=sort(Dccol);%Vc的列数DcCols=size(Vc,2);%反序for i=1:DcCols Vcsort(:,i)=Vc(:,Dcindex(DcCols-i+1); Dcsort(i)=Dccol(Dcindex(DcCols-i+1);end%取前k个最大特征值对应的特征向量,保留95的能量,此时k=8Dcsum=sum(Dcsort);Dcsum_extract=0;k=0;while(Dcsum_extract/Dcsum0.95) k=k

12、+1; Dcsum_extract=sum(Dcsort(1:k);end%temp是由前k个最大的非0特征值对应的特征向量组成的i=1;temp=;while(i=k) temp(:,i)=Dcsort(i)(-1/2)*Vcsort(:,i); i=i+1;endwhiteningmatrix=temp;%用于白化数据的白化矩阵,whiteningmatrix是8x20%用快速ICA算法求分离矩阵w(迭代50次)whitesig=whiteningmatrix*imgsig;X=whitesig;%X是8x10304vectorsize,numsamples=size(X);B=zeros

13、(vectorsize);%B是8x8numofic=vectorsize;%numofic是8for r=1:numofic i=1; maxnumiterations=50;%设置最大的迭代次数w=rand(vectorsize,1)-.5;%随机设置初始值w=w/norm(w);%初始化w(0),令其模为1while i0.9 res=This is Edward; elseif result(2,1)0.9 res=This is George;elseif result(3,1)0.9 res=This is Frank;elseif result(4,1)0.9 res=This is Henry;else res=This is strange;end选择训练图像库的路径训练图像训练结果这是图像训练库外的人

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 建筑/施工/环境 > 项目建议


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号