Python 人脸检测、面部五官关键点检测等


模块:face_recognition

import face_recognitio
官方描述:

face_recognition是一个强大、简单、易上手的人脸识别开源项目,并且配备了完整的开发文档和应用案例,特别是兼容树莓派系统。
本项目是世界上最简洁的人脸识别库,你可以使用Python和命令行工具提取、识别、操作人脸。
本项目的人脸识别是基于业内领先的C++开源库 dlib中的深度学习模型,用Labeled Faces in the Wild人脸数据集进行测试,有高达99.38%的准确率。
但对小孩和亚洲人脸的识别准确率尚待提升。

 依赖项

1. pip install cmake

2. pip install boost

3. pip install dlib

 

简单用法:

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)

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM