1. face_recognition使用世界上最简单的人脸识别工具,它使用dlib最先进的人脸识别技术构建而成,并且具有深度学习功能。
代码实现
import face_recognition
import cv2
import matplotlib.pyplot as plt
def show_image(image, title):
plt.title(title)
plt.imshow(image)
plt.axis("off")
def show_landmarks(image, landmarks):
for landmarks_dict in landmarks:
for landmarks_key in landmarks_dict.keys():
for point in landmarks_dict[landmarks_key]:
cv2.circle(image, point, 1, (0, 0, 255), -1)
return image
def main():
image = cv2.imread("2.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
face_marks = face_recognition.face_landmarks(gray, None, "large")
img_result = show_landmarks(image.copy(), face_marks)
plt.figure(figsize=(9, 6))
plt.suptitle("face landmarks with face_recognition", fontsize=14, fontweight="bold")
show_image(img_result, "face landmarks")
plt.show()
if __name__ == '__main__':
main()
运行结果