模块:face_recognition
import face_recognitio
官方描述:
face_recognition是一个强大、简单、易上手的人脸识别开源项目,并且配备了完整的开发文档和应用案例,特别是兼容树莓派系统。
本项目是世界上最简洁的人脸识别库,你可以使用Python和命令行工具提取、识别、操作人脸。
本项目的人脸识别是基于业内领先的C++开源库 dlib中的深度学习模型,用Labeled Faces in the Wild人脸数据集进行测试,有高达99.38%的准确率。
但对小孩和亚洲人脸的识别准确率尚待提升。
简单用法:
import face_recognition import cv2 # 读取图像数据 image = face_recognition.load_image_file(‘。。。’) # 获取图像中所有人脸的五官坐标 face_locations = face_recognition.face_landmarks(image) print(‘face_locations‘, face_locations) # 人脸检测 face_locations = face_recognition.face_locations(image, model="cnn") y_min, x_max, y_max, x_min = face_locations[0] cv2.rectangle(image, (x_min, y_min), (x_max, y_max), (0, 0, 255), 2) # 摄像头五官检测 names = [‘left_eyebrow‘, ‘right_eyebrow‘, ‘nose_bridge‘, ‘nose_tip‘, ‘top_lip‘, ‘bottom_lip‘, ‘left_eye‘, ‘right_eye‘] cap = cv2.VideoCapture(0) while True: ret, frame = cap.read() # 获取图像中所有人脸的五官坐标 face_locations = face_recognition.face_landmarks(frame) points = face_locations[0] for name in names: for point in points[name]: cv2.circle(frame, point, 1, (0, 0, 255), -1) if cv2.waitKey(1) == 27: break cv2.imshow(‘Test camera‘, frame)
原文:https://www.cnblogs.com/leafchen/p/14074155.html