千锋扣丁学堂Python培训

上传人:壹****1 文档编号:551079428 上传时间:2022-08-22 格式:DOCX 页数:17 大小:147.10KB
返回 下载 相关 举报
千锋扣丁学堂Python培训_第1页
第1页 / 共17页
千锋扣丁学堂Python培训_第2页
第2页 / 共17页
千锋扣丁学堂Python培训_第3页
第3页 / 共17页
千锋扣丁学堂Python培训_第4页
第4页 / 共17页
千锋扣丁学堂Python培训_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《千锋扣丁学堂Python培训》由会员分享,可在线阅读,更多相关《千锋扣丁学堂Python培训(17页珍藏版)》请在金锄头文库上搜索。

1、千锋扣丁学堂 Python 培训之学习人脸识别技术 Dlib+OpenCV 示例源码在现如今生活中,时时刻刻都在使用智能机器,今天千锋扣丁学堂Pytho n培训老师给大家 介绍一下关于Dlib+Ope nCV深度学习人脸识别的方法示例,文中通过示例代码介绍的非 常详细,下面我们一起来看一下吧。人脸识别在LWF(LabeledFacesi ntheWild)数据集上人脸识别率现在已经99.7%以上,这 个识别率确实非常高了,但是真实的环境中的准确率有多少呢?我没有这方面的数据,但是 可以确信的是真实环境中的识别率并没有那么乐观。现在虽然有一些商业应用如员工人脸识 别管理系统、海关身份验证系统、甚

2、至是银行人脸识别功能,但是我们可以仔细想想员工人 脸识别管理,海关身份证系统的应用场景对身份的验证功能。在这个系统中我预先存储了下面几位明星的正面头像的128D人脸特征,当然你可以存储和 导入更多的人脸。然后经过人脸检测、人脸图像处理,和人脸识别等步骤识别出相应的人脸 信息,识别效果如下(怕大家被丑至I所以用了明星的图片,没有用真实的人脸-没有做活体 检测):S3OttfCtttrtFace_Recogftrse出 fjjct.ftflcogriiw当然这只是一个简单的应用,真正用到生产的系统,还需运用活体检测等技术,防止运用照 片或是手机视频等方式欺骗过人脸识别系统,安全级别要求更高的应用领

3、域例如支付、转账 等系统活体检测可能仍不够安全,这时还可以通过人脸识别+验证密码等方式加强安全性人脸数据库导入人脸数据导入,也就是说我在系统启动之初,需要导入我的人脸数据库,也就是前面的那些 明星的正面照。装载的开始阶段,因为要检测静态人脸图片的人脸部位,首先需要用dlib 的人脸检测器,用get_fro ntal_face_detector()获得。然后需要将68点人脸标记模型导入 shape_predictorsp,目的就是要对其人脸到一个标准的姿势,接着就是装载DNN模型。然后取每张人脸照片的特征,并将特征和姓名等相关的信息放入FACE_DESC结构中,最后 将每张人脸信息结构放入fac

4、e_desc_vec容器中,这里我只装载了 9个明星的人脸信息。int FACE RECOGNITION:load db faces(void)intrc = -1;longhFile = 0;struct_finddata_tfileinfo;frontal face detectordetector =get frontal face detector();/ We will also use a face landmarking model to align faces to a standard pos e: (see face landmark detection excpp for

5、 an introduction)deserialize(shape_predictor_68_face_landmarksdat) sp;/ And finally we load the DNN responsible for face recognitiondeserialize(dlib_face_recognition_resnet_model_vdat) net;if (hFile =findfirst(faces*jpg, &fileinfo) != -1)I doif (fileinfoattrib & A ARCH)if (strcmp(fileinfoname,) != 0

6、 & strcmp(fileinfoname,) != 0)if (!strcmp(strstr(fileinfoname,) + 1 , jpg)cout This file is an image file! fileinfoname endl;matriximg;charpath260;sprintf_s(path,faces%s,fileinfoname);load image(img,path);image windowwin(img);for (autoface :detector(img)autoshape =sp(img,face); matrixface_chip;extra

7、ct.image_chip(img,get_face_chip_details(shape, 150, 25),face _chip);/Record the all this faces informationFACE DESCsigle face;sigle_faceface_chip =face_chip;sigle_facename =fileinfoname;std:vectormatrixface_chip_vec;std:vectormatrixface all;face_chip_vecpush_back(move(face_chip);/Asks the DNN to con

8、vert each face image in faces into a 128D ve ctorface_all =net(face_chip_vec);/Get the feature of this personstd:vectormatrix:iteratoriter begin = face allbe gin(),iter end =face allend();if (face allsize() 1)break;sigle_faceface_feature = *iter_begin;/all the person description into vector face_des

9、c_vecpush_back(sigle_face);winadd overlay(face);elsecout This file is not image file! fileinfoname endl;else/filespush_back(passign(path)append()append(fileinfoname); while (findnext(hFile, &fileinfo) = 0);findclose(hFile);returnrc;人脸检测人脸检测在人脸识别的应用系统中我认为是至关重要的一环因为人脸检测的好坏直接影响 最终的识别率,如果在人脸检测阶段能做到尽量好的话

10、,系统的识别率会有一个比较大的提 升。下面的是人脸检测的具体代码实现(很简陋莫怪),尝试了用Dlib人脸检测,OpenCV 人脸检测,还有于仕琪的libfacedetection,比较发现于仕琪的libfacedetection是做人 脸检测最好的一个,速度快,并且检测图像效果也很好。Matgray;Matface;intrc =-1;if (frame.empty() | !frame.data)return -1;cvtColor(frame,gray,CV_BGR2GRAY);int *pResults =NULL;unsignedchar *pBuffer = (unsignedcha

11、r *)malloc(DETECT_BUFFER_SIZE);if (!pBuffer)fprintf(stderr,Can not alloc buffer.n);return -1;/pResults = facedetect_frontal_tmp(unsigned char*)(gray.ptr(0), gray.cols, gray.rows, gray.step,/1.2f, 5, 24);pResults =facedetect_multiview_reinforce(pBuffer, (unsignedchar*)(gray.ptr(0),gray.cols,gray.rows

12、, (int)gray.step,1.2f, 2, 48, 0, 1);/printf(%d faces detected.n, (pResults ? *pResults : 0);/重复运行/print the detection results匚if (pResults !=NULL)for (inti = 0;i face rect =Rect float(x,y,w, h);face =fr ameface _rect);printf(face rect=%d, %d, %d, %d, neighbors=%dn,x,y, w,h,neighbors);Pointleft(x,y);

13、Pointright(x +w,y + h);cv:rectanglef rame,left,right, Scalar(230, 255, 0), 4);/imshow(frame, frame);if (face.empty() | face.data)face detect count = 0;return -1;if (face detect count+ 30)imshow(face,face);out =face.clone();return 0;else匚/face is moving, and reset the detect count人脸识别通过人脸检测函数capture_

14、face()经过处理之后临时保存在工程目录下的cap.jpg,用 get_face_chip_details()函数将检测到的目标图片标准化为150*150像素大小,并对人脸 进行旋转居中,用extract_image_chip()取得图像的一个拷贝,然后将其存储到自己的图 片face_chip中,把的到face_chip放入vect_faces容器中,传送给深度神经网络net,得 到捕捉到人脸图片的128D向量特征。最后在事先导入的人脸数据库中遍历与此特征最相近 的人脸即可识别出相应的人脸信息。这种模式的应用,也就是我们所说的1 : N应用,1对N是比较考验系统运算能力的,举个 例子,现在支付宝账户应该已经是上亿级别的用户,如果你在就餐的时候选择使用支付宝人 脸支付,也许在半个小时内服务器也没有找

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 学术论文 > 其它学术论文

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号