欢迎来到天天文库
浏览记录
ID:31264429
大小:58.70 KB
页数:21页
时间:2019-01-07
《基于pca的人脸识别opencv代码》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、基于PCA的人脸识别opencv代码#inelude〃StdAfx.H〃#include#inelude#include"CV・H〃#include〃cvaux・H〃#inelude"highgui.H〃H#inelude"time.#include"iostreanTUsingthenamespaceCV;UsingnamespaceSTD.//defineseveralimportantglobalvariablesIplImage**fdcelmgArr=0;//Pointerstotrainingf
2、acesandtestfaces(pointstodifferentlearningandrecognitionstages)CvMat*personNumTruthMat=0;//theIDofthefaceimageIntnTrainFaces=0;//thenumberoftrainingimagesIntnEigens二0;//thenumberofmajoreigenvaluesthatyoutakeIp1Image*pAvgTrainlmg二0;//theaverageoftrainingfacedataIp1Image*eigen
3、VectArr=0;//projectionmatrix,whichisthemaineigenvectorCvMat*eigenValMat二0;//eigenvalueCvMat*projectedTrainFaceMat二0;//theprojectionofthetrainingimage//functionprototypeVoidlearn();Voidrecognize();VoiddoPCA();VoidstoreTrainingData();IntloadTrainingData(CvMat*pTrainPersonNumMa
4、t);Afloat*projectedTestFace;IntloadFacelmgArray(char*filename);VoidprintUsage();//themainfunction,whichconsistsoflearningandidentifyingtwophases,needstoberuntwice,separatedbytheparameterspassedbythecommandlineIntmain(){//learn();Recognize();}//thelearningphasecodeVoidlearn()
5、{Cout<<<<<<<<<<<<<">>//starttimeClock_tstartandfinish;Doubleduration;Start二clock();IntI,offset;//loadtrainingimagesNTrainFaces二loadFacelmgArray(“train.TXT“);If(nTrainFaces<2){Fprintf(stderr,"Need2ormoretrainingfaces〃"Inputfilecontainsonly%drT,nTrainFaces);Thereturn;}//the
6、maincomponentanalysisDoPCA();//thetrainingatlasisprojectedintothesubspaceProjectedTrainFaceMat二cvCreateMat(nTrainFaces,nEigens,CV_32FC1);Offset二projectedtrainfacemat->step/sizeof(float);For(I=0;I7、EigenVectArr,0,0,PAvgTrainlmg,//projectedtrainfacemat->data・f1+I*nEigens・Projectedtrainfacemat->data・fl.}//theeigenvaluesofthetrainingphase,theprojectionmatrix,etcarestoredas.xmlfilesforthetestStoreTrainingData();//endtimeFinish二clock();Duration二(double)(finishstart)/CLOCKS_8、PER_SEC;Cout<<"duration<<<<<<<<<<"<<<<<<<<<<<〈〈〈〈〃〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈
7、EigenVectArr,0,0,PAvgTrainlmg,//projectedtrainfacemat->data・f1+I*nEigens・Projectedtrainfacemat->data・fl.}//theeigenvaluesofthetrainingphase,theprojectionmatrix,etcarestoredas.xmlfilesforthetestStoreTrainingData();//endtimeFinish二clock();Duration二(double)(finishstart)/CLOCKS_
8、PER_SEC;Cout<<"duration<<<<<<<<<<"<<<<<<<<<<<〈〈〈〈〃〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈〈
此文档下载收益归作者所有