您的位置:首页 > 编程语言 > Python开发

Python实现识别人脸特征并打印出来

2019-05-12 00:00 901 查看

通过Python的face_recognition模块实现人脸检测功能,首先需要安装好face_recognition包:可通过pycharm直接安装,也可以用pip安装,还可以通过anaconda安装。

示例代码如下:

# -*- coding: utf-8 -*-
# 自动识别人脸特征
# filename : find_facial_features_in_picture.py
from PIL import Image, ImageDraw
import face_recognition
# 将jpg文件加载到numpy 数组中
image = face_recognition.load_image_file("linuxidc.com.jpg")
#查找图像中所有面部的所有面部特征
face_landmarks_list = face_recognition.face_landmarks(image)
print("I found {} face(s) in this photograph.".format(len(face_landmarks_list)))
pil_image = Image.fromarray(image)
d = ImageDraw.Draw(pil_image)
for face_landmarks in face_landmarks_list:
#打印此图像中每个面部特征的位置
facial_features = [
'chin',
'left_eyebrow',
'right_eyebrow',
'nose_bridge',
'nose_tip',
'left_eye',
'right_eye',
'top_lip',
'bottom_lip'
]
for facial_feature in facial_features:
print("The {} in this face has the following points: {}".format(facial_feature, face_landmarks[facial_feature]))
#在图像中画出每个人脸特征!
for facial_feature in facial_features:
d.line(face_landmarks[facial_feature], width=5)
pil_image.show()

自动识别出人脸特征(轮廓),如下图:

更多Python相关信息见Python 专题页面 https://www.linuxidc.com/topicnews.aspx?tid=17

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Python人脸识别