python 封装dlib模型进行人脸识别系统的登录认证
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了python 封装dlib模型进行人脸识别系统的登录认证,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1853字,纯文字阅读大概需要3分钟。
内容图文
![python 封装dlib模型进行人脸识别系统的登录认证](/upload/InfoBanner/zyjiaocheng/801/8220f2f385834d4a9c8e4e6a88dbaac1.jpg)
1、直接上干货
#!/usr/bin/python # -*- coding: utf-8 -*- import time import dlib import numpy as np class faceDiscernModel: def __init__(self): # 加载预训练人脸检测CNN模型 self.cnn_face_model = "./model/mmod_human_face_detector.dat" self.cnn_face_detector = dlib.cnn_face_detection_model_v1(self.cnn_face_model) # 加载人脸特征检测模型 self.predictor_path = "./model/shape_predictor_5_face_landmarks.dat" self.predictor = dlib.shape_predictor(self.predictor_path) # 加载人脸特征提取模型 self.featureModel = "./model/dlib_face_recognition_resnet_model_v1.dat" self.feater = dlib.face_recognition_model_v1(self.featureModel) def get_faces_feature(self,imgPath): # 读取人脸图片 img = dlib.load_rgb_image(imgPath) feat = [] # 检测每个人脸的边界框 dets = self.cnn_face_detector(img, 1) # len(dets) 是检测到的人脸数量 for i, d in enumerate(dets): # print("Detection {}: Left: {} Top: {} Right: {} Bottom: {} Confidence: {}".format( # i, d.rect.left(), d.rect.top(), d.rect.right(), d.rect.bottom(), d.confidence)) # 检测 box i 内的人脸关键点 shape = self.predictor(img, d.rect) # 计算特征向量 face_descriptor = self.feater.compute_face_descriptor(img, shape) feat.append(face_descriptor) return feat def Euclidean_distance_test(self,feature_1,feature_2): return np.sqrt(np.sum((np.array(feature_1)-np.array(feature_2))**2)) def face_compare(self,imgPath_1,imgPath_2,assess=0.6): feature_1 = self.get_faces_feature(imgPath_1) feature_2 = self.get_faces_feature(imgPath_2) score = self.Euclidean_distance_test(feature_1=feature_1,feature_2=feature_2) if score > assess: return False elif 0< score < assess: return True else: return False if __name__ == '__main__': imgPath_1 = "./faceImage/test.jpg" imgPath_2 = "./faceImage/test1.jpg" faceDiscern = faceDiscernModel() st = time.time() result = faceDiscern.face_compare(imgPath_1,imgPath_2) print(time.time()-st) print(result)
2、模型下载地址
内容总结
以上是互联网集市为您收集整理的python 封装dlib模型进行人脸识别系统的登录认证全部内容,希望文章能够帮你解决python 封装dlib模型进行人脸识别系统的登录认证所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。