人脸地标估计应用
在检测到图像中的人脸后,如先前的“人脸检测应用程序”中所述,我们将执行人脸界标估计。人脸界标估计是指识别人脸的关键点,例如鼻尖和眼中心。
基于面部界标点的数量,存在不同的估计模型。5点模型是最简单的模型,它仅检测每只眼睛的边缘和鼻子的底部。
5分面界标模型
其他模型包括68个点的地标模型,该模型可检测到脸上的68个不同点,包括眼睛,鼻子,嘴唇和脸部形状。
68分地标模型
人脸界标估计有助于构建用于应用数字化妆或小部件的应用程序。
构建用于估计面部特征的应用程序
我们将为我们的应用程序使用通过'dlib'库构建的face_recognition模型。'dlib'主要是C ++库,但是,我们可以将其许多工具用于python应用程序。face_recognition是一种
深度学习模型,准确性为99.38%。
有关更多详细信息和参考,请访问:
https://pypi.org/project/face_recognition/
http://dlib.net/python/index.html
face_recognition内置了执行面部检测,识别和识别任务的功能。首先,我们将图像加载到NumPy数组中并应用face_landmarks函数。face_landmarks函数返回图像中所有面孔的列表。对于该面部的所有面部特征,每个面部还具有“名称”和“点列表”。使用每个面部特征(眼睛,鼻子,嘴唇等)的界标,我们将在面部特征周围绘制红色线条。
注意: 以下代码需要三个Python外部库枕头,face_recognition和dlib。
#import external libraries
import PIL.Image
import PIL.ImageDraw
import face_recognition
# Load the jpg file into a numpy array
image = face_recognition.load_image_file("people.jpg")
# Find all facial features in all the faces in the image
face_landmarks_list = face_recognition.face_landmarks(image)
number_of_faces = len(face_landmarks_list)
print("I found {} face(s) in this photograph.".format(number_of_faces))
# Load the image into a Python Image Library object so that we can draw on top of it and display it
pil_image = PIL.Image.fromarray(image)
# Create a PIL drawing object to be able to draw lines later
draw = PIL.ImageDraw.Draw(pil_image)
# Loop over each face
for face_landmarks in face_landmarks_list:
# Loop over each facial feature (eye
for name
# Print the location of each facial feature in this image
print("The {} in this face has the following points: {}".format(name
# Let's trace out each facial feature in the image with a line!
draw.line(list_of_points
pil_image.show()
以下是上述代码在不同图像上的输出。
如上图所示,面部特征标记非常精确。我们可以进一步扩展应用程序,以应用数字化妆,小部件(眼镜,面具等)等。
1