face_recognition 人脸识别初始

说到人脸识别,我们肯定会联系到机器学习,机器学习说起来可能遥不可及,在python 当道的今天,如何快速实现人脸识别功能,这是个问题

今天我们来了解下python 的 face_recognition 库,来做一个简单的人脸识别程序。走进机器学习,人工智能的大门

我们使用face_recognition 来识别图片中是否是同一个人。

我们使用到的识别素材2.jpg

# -*- coding:utf-8 -*- import cv2 #画图用 import face_recognition #人脸识别库 import
sys face_image = face_recognition.load_image_file("E://pics/2.jpg") #读取图片
face_encodings = face_recognition.face_encodings(face_image) face_locations =
face_recognition.face_locations(face_image)# 判断图片中出现的人数 n = len(face_encodings)
if n>2 : print("3") sys.exit() try: face1 = face_encodings[0] face2 =
face_encodings[1] except : print("2") sys.exit() results =
face_recognition.compare_faces([face1], face2, tolerance=0.5) if results == [
True]: print("0") name = "PASS" else: print("1") name = "DENIED" #绘图 绘制出图片 for i
in range(len(face_encodings)): face_encoding = face_encodings[(i-1)]
face_location = face_locations[(i-1)] top, right, bottom, left = face_location
cv2.rectangle(face_image, (left, top), (right, bottom), (0, 255, 0), 2)
cv2.putText(face_image, name, (left-10, top-10), cv2.FONT_HERSHEY_SIMPLEX, 0.8,
(255, 0, 0), 2) face_image_rgb = cv2.cvtColor(face_image, cv2.COLOR_BGR2RGB)
cv2.imshow("Output", face_image_rgb) cv2.imwrite(
'C:/Users/Administrator/Desktop/fk_model/face/output/intrest.jpg'
,face_image_rgb,[int(cv2.IMWRITE_JPEG_QUALITY),100]) cv2.waitKey(0)
我们看下识别结果

控制台打印为1 表示不是同一个人
当然大家可以尝试不同的图像,也可以做到工业级应用,这就涉及到图片特征训练,特征提取,比这种简单的识别复杂很多,当然这些都是需要训练自己的模型,在后期不断完善。

友情链接
KaDraw流程图
API参考文档
OK工具箱
云服务器优惠
阿里云优惠券
腾讯云优惠券
华为云优惠券
站点信息
问题反馈
邮箱:ixiaoyang8@qq.com
QQ群:637538335
关注微信