自动识别出人脸特征
示例四(识别人脸鉴定是哪个人): # filename : recognize_faces_in_pictures.py # -*- conding: utf-8 -*- # 导入face_recogntion模块,可用命令安装 pip install face_recognition import face_recognition #将jpg文件加载到numpy数组中 babe_image = face_recognition.load_image_file("/opt/face/known_people/babe.jpeg") Rong_zhu_er_image = face_recognition.load_image_file("/opt/face/known_people/Rong zhu er.jpg") unknown_image = face_recognition.load_image_file("/opt/face/unknown_pic/babe2.jpg") #获取每个图像文件中每个面部的面部编码 #由于每个图像中可能有多个面,所以返回一个编码列表。 #但是由于我知道每个图像只有一个脸,我只关心每个图像中的第一个编码,所以我取索引0。 babe_face_encoding = face_recognition.face_encodings(babe_image)[0] Rong_zhu_er_face_encoding = face_recognition.face_encodings(Rong_zhu_er_image)[0] unknown_face_encoding = face_recognition.face_encodings(unknown_image)[0] known_faces = [ babe_face_encoding, Rong_zhu_er_face_encoding ] #结果是True/false的数组,未知面孔known_faces阵列中的任何人相匹配的结果 results = face_recognition.compare_faces(known_faces, unknown_face_encoding) print("这个未知面孔是 Babe 吗? {}".format(results[0])) print("这个未知面孔是 容祖儿 吗? {}".format(results[1])) print("这个未知面孔是 我们从未见过的新面孔吗? {}".format(not True in results))显示结果如图
示例五(识别人脸特征并美颜):# filename : digital_makeup.py
#-*- coding: utf-8-*-
#导入pil模块,可用命令安装apt-get install python-Imaging
from PIL importImage,ImageDraw
#导入face_recogntion模块,可用命令安装 pip install face_recognition
import face_recognition
#将jpg文件加载到numpy数组中
image = face_recognition.load_image_file("biden.jpg")
#查找图像中所有面部的所有面部特征
face_landmarks_list = face_recognition.face_landmarks(image)
for face_landmarks in face_landmarks_list:
pil_image =Image.fromarray(image)
d =ImageDraw.Draw(pil_image,'RGBA')
#让眉毛变成了一场噩梦
d.polygon(face_landmarks['left_eyebrow'], fill=(68,54,39,128))