人脸实战之角度检测篇

一、角度的定义

三维欧拉角,准确来说应该叫头部姿态,主要分为三个方向:roll、yaw、pitch
在这里插入图片描述
平面角:主要指Roll方向角

二、相关算法

2.1 roll方向角的角度回归算法,可参考PCN

是一个分阶段任务由粗到精的过程,reference:https://link.zhihu.com/?target=https%3A//arxiv.org/pdf/1804.06039.pdf
作者没有放出训练代码,需要自己实现

2.2 欧拉角角度检测

一般分为with keypoint和without keypoint,without keypoint的方法可参考https://github.com/natanielruiz/deep-head-pose。但是训练难收敛需要自己调,也有light版本可应用于端侧。
训练集为300w_LP;测试集为AFLW200、BI
with keypoint的方法,推荐2019年的PFLD。地址:https://arxiv.org/pdf/1902.10859.pdf

最近又发现了一个基于TF的角度检测项目,贴出:https://github.com/yinguobing/head-pose-estimation
感谢开源的作者们,共勉!

  • 0
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
是的,dlib可以实现人脸欧拉角角度检测。欧拉角是描述物体在三维空间中的姿态的一种方式,包括俯仰、偏航和翻滚三个角度。在dlib中,可以使用shape_predictor模型来获取人脸关键点,然后计算人脸的欧拉角。 以下是一个示例代码,可以实现使用dlib检测人脸并计算人脸的欧拉角: ```python import dlib import numpy as np import cv2 def get_head_pose(shape): """ 计算人脸的欧拉角 :param shape: 人脸关键点 :return: 人脸的欧拉角 """ # 计算眼睛中心点 eye_left = (shape.part(36).x, shape.part(36).y) eye_right = (shape.part(45).x, shape.part(45).y) eyes_center = ((eye_left[0] + eye_right[0]) // 2, (eye_left[1] + eye_right[1]) // 2) # 计算鼻子中心点和嘴巴中心点 nose_tip = (shape.part(30).x, shape.part(30).y) mouth_center_top = (shape.part(51).x, shape.part(51).y) mouth_center_bottom = (shape.part(57).x, shape.part(57).y) nose_mouth_center = ((nose_tip[0] + mouth_center_top[0] + mouth_center_bottom[0]) // 3, (nose_tip[1] + mouth_center_top[1] + mouth_center_bottom[1]) // 3) # 计算相机的焦距 focal_length = 500.0 # 计算相机中心点 center = (640 // 2, 480 // 2) # 计算图像中心点和眼睛中心点的距离 distance = np.sqrt((eyes_center[0] - center[0]) ** 2 + (eyes_center[1] - center[1]) ** 2) # 计算俯仰角 pitch = np.arcsin((nose_mouth_center[1] - eyes_center[1]) / distance) * 180 / np.pi # 计算偏航角 yaw = np.arcsin((eyes_center[0] - nose_mouth_center[0]) / distance) * 180 / np.pi # 计算翻滚角 roll = np.arcsin((eye_right[1] - eye_left[1]) / (eye_right[0] - eye_left[0])) * 180 / np.pi return (pitch, yaw, roll) def detect_face(image_path): """ 检测人脸并计算欧拉角 :param image_path: 图像路径 """ # 加载人脸检测器和关键点检测器 detector = dlib.get_frontal_face_detector() predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat") # 加载图像并进行人脸检测和关键点检测 image = cv2.imread(image_path) gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) dets = detector(gray, 1) for i, det in enumerate(dets): shape = predictor(gray, det) # 计算欧拉角 pitch, yaw, roll = get_head_pose(shape) print("第{}张人脸图像的欧拉角为:俯仰角={}度,偏航角={}度,翻滚角={}度".format(i + 1, pitch, yaw, roll)) ``` 您可以将以上代码复制到一个.py文件中,然后调用detect_face函数并传入人脸图像路径即可检测人脸并计算欧拉角。请注意,在运行代码前需要先下载dlib的人脸关键点检测模型文件"shape_predictor_68_face_landmarks.dat"并放置在代码同一目录下。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值