Face Detection
retina face
Github - retinaface: deep learning based cutting-edge facial detector
deepface
Github - deepface: a lightweight face recognition and facial attribute analysis (age, gender, emotion and race) framework
Install:
pip install deepface
Usage:
from deepface import DeepFace
# Detection: 从照片中检测人脸
face_objs = DeepFace.extract_faces(
img_path = "img.jpg",
detector_backend = 'retinaface', # retina face 检测效果较好
align = False,
enforce_detection = False,
)
# Verification: 判断两张图片是否同一个人
result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg")
# 默认会先做 detection,如果是已经提取了人脸的照片可以用
result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg", detector_backend='skip')
# 指定相似度阈值
result = DeepFace.verify(img1_path = "img1.jpg", img2_path = "img2.jpg", threshold=0.5)
# Embedding: 提取人脸 embedding,可以用于后续的对比计算
embedding_objs = DeepFace.represent(img_path = "img.jpg")
# Recognition: 人脸识别,从人脸库中找出最符合的人
dfs = DeepFace.find(
img_path = "img1.jpg",
db_path = "./workspace/my_db",
model_name = "VGG-Face", # 默认模型是 VGG-Face
)
# Analysis:提取脸部特征(年龄、性别、情绪等)
objs = DeepFace.analyze(
img_path = "img4.jpg",
actions = ['age', 'gender', 'race', 'emotion'],
)