人脸识别源码分享.docx

上传人:b****1 文档编号:394967 上传时间:2022-10-09 格式:DOCX 页数:8 大小:17.41KB
下载 相关 举报
人脸识别源码分享.docx_第1页
第1页 / 共8页
人脸识别源码分享.docx_第2页
第2页 / 共8页
人脸识别源码分享.docx_第3页
第3页 / 共8页
人脸识别源码分享.docx_第4页
第4页 / 共8页
人脸识别源码分享.docx_第5页
第5页 / 共8页
点击查看更多>>
下载资源
资源描述

人脸识别源码分享.docx

《人脸识别源码分享.docx》由会员分享,可在线阅读,更多相关《人脸识别源码分享.docx(8页珍藏版)》请在冰豆网上搜索。

人脸识别源码分享.docx

人脸识别源码分享

计划实现了一个基于PCA的人脸识别方法,我称之为“特征点方法”,所有的功能简单而且实用。

   下面,我使用一个简单的MATLAB脚本说明它的用法。

   一般情况,你应该按照以下这个顺序执行这个方法:

   1. 选择实际测试和参照组人脸图像数据库的路径;

   2. 选择实际测试人脸图像的路径;

   3. 运行“CreateDatabase”函数来创建所有参照组人脸图像的二维矩阵;

   4. 运行“eigenfacecore"函数产生基础人脸图像空间;

   5. 运行“识别”功能得到参照组人脸图像数据库中等价图像的名称。

   为了您的方便,我准备了实际测试和参照组人脸图像数据库,其中部分来自“Face94”埃塞克斯人脸数据库。

   你只需要复制上述功能,指定实际测试和参照组人脸图像数据库的路径(比如Matlab工作路径)。

   然后按照对话框提示输入图片编号,实例将运行实现。

   希望您能喜欢它!

 

   

引用:

[1]P.N.Belhumeur,J.Hespanha,andD.J.Kriegman.Eigenfacesvs.Fisherfaces:

Recognition 

  usingclassspecificlinearprojection.InECCV

(1),pages45--58,1996.

[2]Availableat:

  

以下为源代码文件:

----------------------------------------------------------------------------------------------------------------------

CreateDatabase.m

functionT=CreateDatabase(TrainDatabasePath)

%Alignasetoffaceimages(thetrainingsetT1,T2,...,TM)

%

%Description:

Thisfunctionreshapesall2Dimagesofthetrainingdatabase

%into1Dcolumnvectors.Then,itputsthese1Dcolumnvectorsinarowto 

%construct2Dmatrix'T'.

%

%Argument:

  TrainDatabasePath   -Pathofthetrainingdatabase

%

%Returns:

   T           -A2Dmatrix,containingall1Dimagevectors.

%                    SupposeallPimagesinthetrainingdatabase 

%                    havethesamesizeofMxN.Sothelengthof1D 

%                    columnvectorsisMNand'T'willbeaMNxP2Dmatrix.

%

%Seealso:

STRCMP,STRCAT,RESHAPE

%OriginalversionbyAmirHosseinOmidvarnia,October2007

%          Email:

***************.ac.ir         

%%%%%%%%%%%%%%%%%%%%%%%%

TrainFiles=dir(TrainDatabasePath);

Train_Number=0;

fori=1:

size(Train)

  ifnot(strcmp(TrainFiles(i).name,'.')|strcmp(TrainFiles(i).name,'..')|strcmp(TrainFiles(i).name,'Thumbs.db'))

    Train_Number=Train_Number+1;%Numberofallimagesinthetrainingdatabase

  end

end

%%%%%%%%%%%%%%%%%%%%%%%%Constructionof2Dmatrixfrom1Dimagevectors

T=[];

fori=1:

Train_Number

   

  %Ihavechosenthenameofeachimageindatabasesasacorresponding

  %number.However,itisnotmandatory!

  str=int2str(i);

  str=strcat('\',str,'.jpg');

  str=strcat(TrainDatabasePath,str);

   

  img=imread(str);

  img=rgb2gray(img);

   

  [irowicol]=size(img);

  

  temp=reshape(img',irow*icol,1); %Reshaping2Dimagesinto1Dimagevectors

  T=[Ttemp];%'T'growsaftereachturn          

end

---------------------------------------------------------------------------------------------------------------------------

EigenfaceCore.m

function[m,A,Eigenfaces]=EigenfaceCore(T)

%UsePrincipleComponentAnalysis(PCA)todeterminethemost 

%discriminatingfeaturesbetweenimagesoffaces.

%

%Description:

Thisfunctiongetsa2Dmatrix,containingalltrainingimagevectors

%andreturns3outputswhichareextractedfromtrainingdatabase.

%

%Argument:

   T           -A2Dmatrix,containingall1Dimagevectors.

%                    SupposeallPimagesinthetrainingdatabase 

%                    havethesamesizeofMxN.Sothelengthof1D 

%                    columnvectorsisM*Nand'T'willbeaMNxP2Dmatrix.

%Returns:

   m           -(M*Nx1)Meanofthetrainingdatabase

%        Eigenfaces      -(M*Nx(P-1))Eigenvectorsofthecovariancematrixofthetrainingdatabase

%        A           -(M*NxP)Matrixofcenteredimagevectors

%

%Seealso:

EIG

 

%OriginalversionbyAmirHosseinOmidvarnia,October2007

%          Email:

***************.ac.ir         

 

%%%%%%%%%%%%%%%%%%%%%%%%Calculatingthemeanimage 

m=mean(T,2);%Computingtheaveragefaceimagem=(1/P)*sum(Tj's)  (j=1:

P)

Train_Number=size(T,2);

%%%%%%%%%%%%%%%%%%%%%%%%Calculatingthedeviationofeachimagefrommeanimage

A=[]; 

fori=1:

Train_Number

  temp=double(T(:

i))-m;%ComputingthedifferenceimageforeachimageinthetrainingsetAi=Ti-m

  A=[Atemp];%Mergingallcenteredimages

end

%%%%%%%%%%%%%%%%%%%%%%%%SnapshotmethodofEigenfacemethos

%WeknowfromlinearalgebratheorythatforaPxQmatrix,themaximum

%numberofnon-zeroeigenvaluesthatthematrixcanhaveismin(P-1,Q-1).

%Sincethenumberoftrainingimages(P)isusuallylessthanthenumber

%ofpixels(M*N),themostnon-zeroeigenvaluesthatcanbefoundareequal

%toP-1.SowecancalculateeigenvaluesofA'*A(aPxPmatrix)insteadof

%A*A'(aM*NxM*Nmatrix).ItisclearthatthedimensionsofA*A'ismuch

%largerthatA'*A.Sothedimensionalitywilldecrease.

L=A'*A;%Listhesurrogateof

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

当前位置:首页 > 高中教育 > 语文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1