ImageVerifierCode 换一换
格式:DOC , 页数:18 ,大小:764.04KB ,
资源ID:2631809      下载积分:8 金币
快捷注册下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/2631809.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请

   平台协调中心        【在线客服】        免费申请共赢上传

权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:0574-28810668;投诉电话:18658249818。

注意事项

本文([人脸识别Step]在opencv下作人脸检测.doc)为本站上传会员【精***】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

[人脸识别Step]在opencv下作人脸检测.doc

1、 [人脸识别Step]在opencv下作人脸检测 ———————————————————————————————— 作者: ———————————————————————————————— 日期: 18 个人收集整理 勿做商业用

2、途 [人脸识别Step1]在opencv下作人脸检测 本帖被 admin 设置为精华(2007-08-03) 人脸识别的第一步,就是人脸检测。把人的脸部从一张照片中用计算机自动识别出来,作为下一步人脸识别的基础。 在opencv 中,库中自带了一个利用harr特征的人脸检测训练及检测函数:cvHaarDetectObjects.它利用训练好的检测器,在图片中间检测你想要的 物体,如人脸。opencv自带了很多检测器,在%opencv%data/haarcascades目录下,你可以随意取用。或者你也可以自己用图片训 练自己的检测器,之后拿来使用. 下面是检测人脸的源代码: //

3、DetectFaces.c // // Example code showing how to detect faces using // OpenCV's CvHaarClassifierCascade // // See also, facedetect。c, in the samples directory。 // // Usage: DetectFaces 〈imagefilename〉 #include #include "cv.h" #include "highgui.h" // *** Change this to your

4、install location! *** // ********************************************* #define OPENCV_ROOT  ”C:/Program Files/OpenCV” // ********************************************* void displayDetections(IplImage * pInpImg, CvSeq * pFaceRectSeq, char* FileName); int main(int argc, char** argv) {    

5、// variables     IplImage * pInpImg = 0;     CvHaarClassifierCascade * pCascade = 0;  // the face detector     CvMemStorage * pStorage = 0;        // memory for detector to use     CvSeq * pFaceRectSeq;              // memory-access interface     // usage check     if(argc < 2)     {      

6、   printf(”Missing name of image file!\n”                ”Usage: %s 1) ? cvLoadImage(argv[1], CV_LOAD_IMAGE_COLOR) : 0;     pStorage = cvCreateMemStorage(0);     pCascade = (CvHaarClassifierCa

7、scade *)cvLoad        ((OPENCV_ROOT”/data/haarcascades/haarcascade_frontalface_default。xml”),        0, 0, 0 );     // validate that everything initialized properly     if( !pInpImg || !pStorage || !pCascade )     {         printf("Initialization failed: %s\n",             (!pInpImg)?  "can

8、't load image file" :             (!pCascade)? "can’t load haar—cascade —- ”                          "make sure path is correct" :             "unable to allocate memory for data storage", argv[1]);         exit(-1);     }     // detect faces in image     pFaceRectSeq = cvHaarDetectObjects

9、         (pInpImg, pCascade, pStorage,         1。1,                      // increase search scale by 10% each pass         3,                        // merge groups of three detections         CV_HAAR_DO_CANNY_PRUNING,  // skip regions unlikely to contain a face         cvSize(40,40));         

10、   // smallest size face to detect = 40x40     // display detected faces     displayDetections(pInpImg, pFaceRectSeq, argv[1]);     // clean up and release resources     cvReleaseImage(&pInpImg);     if(pCascade) cvReleaseHaarClassifierCascade(&pCascade);     if(pStorage) cvReleaseMemSto

11、rage(&pStorage);     return 0; } void displayDetections(IplImage * pInpImg, CvSeq * pFaceRectSeq, char* FileName) {     const char * DISPLAY_WINDOW = "Haar Window";     int i;         // create a window to display detected faces     cvNamedWindow(DISPLAY_WINDOW, CV_WINDOW_AUTOSIZE);

12、     // draw a rectangular outline around each detection     for(i=0;i〈(pFaceRectSeq? pFaceRectSeq->total:0); i++ )     {         CvRect* r = (CvRect*)cvGetSeqElem(pFaceRectSeq, i);         CvPoint pt1 = { r->x, r->y };         CvPoint pt2 = { r—〉x + r-〉width, r—>y + r—>height };         cvR

13、ectangle(pInpImg, pt1, pt2, CV_RGB(0,255,0), 3, 4, 0);         cvSetImageROI(pInpImg, *r);         //char* FileName = argv[1];         IplImage* dst = cvCreateImage( cvSize(92,112), pInpImg—>depth, pInpImg—〉nChannels);         cvResize(pInpImg, dst, CV_INTER_LINEAR);         strcat(FileName,”.p

14、gm");         cvSaveImage(FileName, dst);     }     // display face detections     cvShowImage(DISPLAY_WINDOW, pInpImg);     cvWaitKey(0);     cvDestroyWindow(DISPLAY_WINDOW); } 程序会将人脸检测出来,显示在屏幕上,并存回原来的文件将其覆盖。 在window xp, devcpp  4。9。9.2 下编译通过。本文为互联网收集,请勿用作商业用途文档为个人收集整理,来源于网络 人脸识别Step

15、2]对人脸图片作PCA降维 本帖被 admin 设置为精华(2007—08—03) 在上一篇文章中,我们将人脸从图片中检测了出来,并存回了同名的文件。下一步,就要进行识别了。 对 一幅图片而言,我们可以将它看成是一个二位数组,每个元素表达一个像素的特征,如颜色等。那么,对一幅我们处理好的大小为92*112的黑白单通道图片, 就需要一个长度为10304的浮点箱量来表示.这么高维度的数据,处理起来计算代价很大,因为它将所有像素一视同仁,效果也不一定好. 所以,我们对于人脸数据,采用了主成分分析 ( Principal Component Analysis , PCA ) 方法来做数据

16、降维。那么,什么是PCA呢? 主 成分分析 ( Principal Component Analysis , PCA ) 是一种掌握事物主要矛盾的统计分析方法,它可以从多元事物中解析出主要影响因素,揭示事物的本质,简化复杂的问题。计算主成分的目的是将高维数据投影到较 低维空间。给定 n 个变量的 m 个观察值,形成一个 n ′ m 的数据矩阵, n 通常比较大。对于一个由多个变量描述的复杂事物,人们难以认识,那么是否可以抓住事物主要方面进行重点分析呢?如果事物的主要方面刚好体现在几个主要变量 上,我们只需要将这几个变量分离出来,进行详细分析.但是,在一般情况下,并不能直接找出这样的关键变量。

17、这时我们可以用原有变量的线性组合来表示事物的 主要方面, PCA 就是这样一种分析方法。 PCA 的目标是寻找 r ( r

18、Face。txt,测试人脸图片 的PCA结果输出到TestFace.txt中,以备以后调用别的学习算法(如SVM等)使用。在程序中,直接使用欧式距离或余弦距离(需要在源代码中手 动更改编译)度量测试人脸和各训练人脸的相似度并输出,以供作简单的观察。 以下是源程序: // eigenface.c, by Robin Hewitt, 2007 // edited by Xin QIao, AUG 2007 // // Example program showing how to implement eigenface with OpenCV // Usage: // /

19、/ First, you need some face images。 I used the ORL face database. // You can download it for free at //    www.cl.cam。ac.uk/research/dtg/attarchive/facedatabase。html // // List the training and test face images you want to use in the // input files train.txt and test。txt。 (Example input files a

20、re provided // in the download.) To use these input files exactly as provided, unzip // the ORL face database, and place train。txt, test。txt, and eigenface.exe // at the root of the unzipped database. // // To run the learning phase of eigenface, enter //    eigenface train // at the command

21、prompt. To run the recognition phase, enter //    eigenface test #include 〈stdio.h〉 #include 〈string.h〉 #include #include ”cv.h” #include ”cvaux.h” #include ”highgui。h" //// Global variables IplImage ** faceImgArr        = 0; // array of face images CvMat    *  personNumT

22、ruthMat = 0; // array of person numbers int nTrainFaces              = 0; // the number of training images int nEigens                  = 0; // the number of eigenvalues IplImage * pAvgTrainImg      = 0; // the average image IplImage ** eigenVectArr      = 0; // eigenvectors CvMat * eigenValMat

23、          = 0; // eigenvalues CvMat * projectedTrainFaceMat = 0; // projected training faces //// Function prototypes void learn(); void recognize(); void doPCA(); void storeTrainingData(); int  loadTrainingData(CvMat ** pTrainPersonNumMat); double * findNearestNeighbor(float * projected

24、TestFace); int  loadFaceImgArray(char * filename); void printUsage(); ////////////////////////////////// // main() // int main( int argc, char** argv ) {     // validate that an input was specified     if( argc != 2 )     {         printUsage();         return -1;     }     if( !

25、strcmp(argv[1], "train”) ) learn();     else if( !strcmp(argv[1], ”test") ) recognize();     else     {         printf(”Unknown command: %s\n", argv[1]);         printUsage();     }     return 0; } ////////////////////////////////// // learn() // void learn() {     int i, j, k, off

26、set;     // load training data     nTrainFaces = loadFaceImgArray(”train.txt");     if( nTrainFaces 〈 2 )     {         fprintf(stderr,                "Need 2 or more training faces\n"                ”Input file contains only %d\n", nTrainFaces);         return;     }     // do PCA

27、on the training faces     doPCA();     // project the training images onto the PCA subspace     projectedTrainFaceMat = cvCreateMat( nTrainFaces, nEigens, CV_32FC1 );     offset = projectedTrainFaceMat-〉step / sizeof(float);     for(i=0; i〈nTrainFaces; i++)     {         //int offset = i *

28、nEigens;         cvEigenDecomposite(             faceImgArr,             nEigens,             eigenVectArr,             0, 0,             pAvgTrainImg,             //projectedTrainFaceMat—〉data.fl + i*nEigens);             projectedTrainFaceMat->data.fl + i*offset);     }         // stor

29、e the projectedTrainFaceMat as TrainFace。txt     FILE * TrainfaceFile = 0;     if( TrainfaceFile = fopen(”TrainFace。txt”, ”w”) )     {         for(j = 0 ; j 〈 nTrainFaces ; j++){               fprintf(TrainfaceFile,"%d    ", j);               for(k = 0; k 〈 nEigens ; k++){                  

30、fprintf(TrainfaceFile, ” %d : %f ", k, (projectedTrainFaceMat->data.fl + j*offset)[k] );                }               fprintf(TrainfaceFile,” -1 : ? \n”);         }     }     // store the recognition data as an xml file     storeTrainingData(); } //////////////////////////////////

31、 // recognize() // void recognize() {     int i, j, nTestFaces  = 0;        // the number of test images     CvMat * trainPersonNumMat = 0;  // the person numbers during training     float * projectedTestFace = 0;     // load test images and ground truth for person number     nTestFaces =

32、 loadFaceImgArray(”test.txt”);     printf(”%d test faces loaded\n", nTestFaces);     // load the saved training data     if( !loadTrainingData( &trainPersonNumMat ) ) return;     // project the test images onto the PCA subspace     projectedTestFace = (float *)cvAlloc( nEigens*sizeof(float)

33、 );         double * sim = (double *)cvAlloc( nEigens*sizeof(double) );;     for(i=0; i〈nTestFaces; i++)     {         int iNearest, k;         //int star[nTrainFaces];         // project the test image onto the PCA subspace                 cvEigenDecomposite(             faceImgArr,

34、             nEigens,             eigenVectArr,             0, 0,             pAvgTrainImg,             projectedTestFace);                     // store the projectedTestFace as TestFace。txt         FILE * TestfaceFile = 0;         if( TestfaceFile = fopen(”TestFace。txt", ”w”) )        { 

35、                    fprintf(TestfaceFile,"%d    ", 0);               for(k = 0; k < nEigens ; k++){                   fprintf(TestfaceFile, ” %d : %f ”, k, projectedTestFace[k] );                }               fprintf(TestfaceFile,” —1 : ? \n");         }         sim = findNearestNeig

36、hbor(projectedTestFace);         //truth    = personNumTruthMat-〉data.i;         //nearest  = trainPersonNumMat->data。i[iNearest]; /*         //sort         int order[nTrainFaces];         order[0] = iNearest;         double temp[nTrainFaces];         for ( j = 0; j <  nTrainFaces; j++){

37、             temp[j] = sim[j];         }                             for ( k = 0; k 〈  nTrainFaces; k++){             //记录temp中最小元素的index             int result=0;                         double leastSim = DBL_MAX;                         //找到temp中最小元素的index,记录入result             for

38、 ( j = 0; j <  nTrainFaces; j++){                                  if( temp[j] 〈 leastSim ){                     leastSim = temp[j];                    result = j;                 }                            }                                     order = result;                        

39、//将temp中找到的最小元素置为无穷大             temp[result] = DBL_MAX;         //}              */                        printf("%d test image : \n”,i+1);                 for ( k = 0; k <  nTrainFaces; k++)             printf(”star : %d, simility : %f\n”, k, sim[ k ]);         //printf("nearest

40、 %d, Truth = %d\n\n", nearest, truth);         } } ////////////////////////////////// // loadTrainingData() // int loadTrainingData(CvMat ** pTrainPersonNumMat) {     CvFileStorage * fileStorage;     int i;     // create a file-storage interface     fileStorage = cvOpenFileStorage(

41、 "。/data/facedata。xml", 0, CV_STORAGE_READ );     if( !fileStorage )     {         fprintf(stderr, ”Can’t open facedata.xml\n”);         return 0;     }     nEigens = cvReadIntByName(fileStorage, 0, "nEigens", 0);     nTrainFaces = cvReadIntByName(fileStorage, 0, ”nTrainFaces", 0);     *pT

42、rainPersonNumMat = (CvMat *)cvReadByName(fileStorage, 0, ”trainPersonNumMat", 0);     eigenValMat  = (CvMat *)cvReadByName(fileStorage, 0, ”eigenValMat”, 0);     projectedTrainFaceMat = (CvMat *)cvReadByName(fileStorage, 0, "projectedTrainFaceMat", 0);     pAvgTrainImg = (IplImage *)cvReadByName(

43、fileStorage, 0, ”avgTrainImg”, 0);     eigenVectArr = (IplImage **)cvAlloc(nTrainFaces*sizeof(IplImage *));     for(i=0; i〈nEigens; i++)     {         char varname[200];         sprintf( varname, "eigenVect_%d”, i );         eigenVectArr = (IplImage *)cvReadByName(fileStorage, 0, varname, 0);

44、     }     // release the file-storage interface     cvReleaseFileStorage( &fileStorage );     return 1; } ////////////////////////////////// // storeTrainingData() // void storeTrainingData() {     CvFileStorage * fileStorage;     int i;     // create a file—storage interface

45、     fileStorage = cvOpenFileStorage( ”./data/facedata.xml", 0, CV_STORAGE_WRITE );     // store all the data     cvWriteInt( fileStorage, "nEigens", nEigens );     cvWriteInt( fileStorage, ”nTrainFaces", nTrainFaces );     cvWrite(fileStorage, "trainPersonNumMat", personNumTruthMat, cvAttrLis

46、t(0,0));     cvWrite(fileStorage, "eigenValMat”, eigenValMat, cvAttrList(0,0));     cvWrite(fileStorage, "projectedTrainFaceMat”, projectedTrainFaceMat, cvAttrList(0,0));     cvWrite(fileStorage, "avgTrainImg", pAvgTrainImg, cvAttrList(0,0));     for(i=0; i〈nEigens; i++)     {         char var

47、name[200];         sprintf( varname, "eigenVect_%d", i );         cvWrite(fileStorage, varname, eigenVectArr, cvAttrList(0,0));     }     // release the file-storage interface     cvReleaseFileStorage( &fileStorage ); } ////////////////////////////////// // findNearestNeighbor() // d

48、ouble * findNearestNeighbor(float * projectedTestFace) {     //double leastDistSq = 1e12;     double leastDistSq = DBL_MAX;     int i, iTrain, iNearest = 0;     double * sim = (double *)malloc(nTrainFaces * sizeof(double));     for(iTrain=0; iTrain〈nTrainFaces; iTrain++)     {         dou

49、ble distSq=0;                 long double distSx=0;         long double distSy=0;         for(i=0; i〈nEigens; i++)         {                           float d_i =                 projectedTestFace -                 projectedTrainFaceMat—>data.fl[iTrain*nEigens + i];             //distS

50、q += d_i*d_i / eigenValMat—>data.fl;  // Mahalanobis             distSq += d_i*d_i; // Euclidean                         /*             /////////////////////////////////////////////////////////////////              double d_i =                 projectedTestFace *                 projectedTr

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2026 宁波自信网络信息技术有限公司  版权所有

客服电话:0574-28810668  投诉电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服