基于BP神经网络的人脸识别_第1页
基于BP神经网络的人脸识别_第2页
基于BP神经网络的人脸识别_第3页
基于BP神经网络的人脸识别_第4页
基于BP神经网络的人脸识别_第5页
已阅读5页,还剩3页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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(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

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论