4.14团队开发博客

  昨天在了解到多人脸识别技术的原理后,今天我正式开始在网上学习多人脸识别技术的代码。我打算在网上先学习如何调配别人的项目,我在GIthub上扒了一个项目,在经过半天的折磨之后,我学会了如何调配别人的项目。

  在真正的项目中,大部分人都会有一个requirments.txt文件,这里详细配置了所有库的版本号,用pip指令加上版本号即可。

示例如下:

pyqt5>=5.15.4
opencv-python==4.5.1.48
torch>=1.8.1+cu111
numpy>=1.21.0
pandas>=1.1.5
  我打算先写出来多人脸识别的功能,再写出来不同的课堂走神种类,比如低头玩手机,交头接耳,低头,睡觉等情况。
 今天先给出人脸识别代码:
def get_face_keypoints(face_keypoints):
"""
获取标准化后的人脸关键点坐标
:param face_keypoints: 脸部关键点
:return: 标准化后的人脸关键点坐标,人脸框的位置
"""
face_outline_keypoints = face_keypoints[:27]
face_x1 = torch.min(face_outline_keypoints[:, 0])
face_y1 = torch.min(face_outline_keypoints[:, 1])
face_x2 = torch.max(face_outline_keypoints[:, 0])
face_y2 = torch.max(face_outline_keypoints[:, 1])
# 获取标准化的脸部坐标
face_x1_y1 = torch.tensor([face_x1, face_y1])
face_width = torch.tensor([face_x2 - face_x1, face_y2 - face_y1])
scaled_face_keypoints = (face_keypoints - face_x1_y1) / face_width
return scaled_face_keypoints, (face_x1, face_y1, face_x2, face_y2)


class PnPPoseEstimator:
"""Estimate head pose according to the facial landmarks"""

def __init__(self, img_size=(480, 640)):
self.size = img_size

# 3D model points.
self.model_points = np.array([
(0.0, 0.0, 0.0), # Nose tip
(0.0, -330.0, -65.0), # Chin
(-225.0, 170.0, -135.0), # Left eye left corner
(225.0, 170.0, -135.0), # Right eye right corner
(-150.0, -150.0, -125.0), # Mouth left corner
(150.0, -150.0, -125.0) # Mouth right corner
]) / 4.5

self.model_points_68 = self._get_full_model_points()

self.body_model_points = np.array([ # 18,19,5,6
(0.0, -40.0, 0.0), # neck
(0.0, 240.0, 5), # hip
(-80, 0.0, 0.5), # left shoulder
(+80, 0.0, 0.5), # right shoulder
])

self.neck_model_points = np.array([ # 17,18,5,6
(0.0, -90.0, 5), # head
(0.0, 30.0, 0.0), # neck
(-60, 70.0, 5), # left shoulder
(+60, 70.0, 5), # right shoulder
])

# Camera internals
self.focal_length = self.size[1]
self.camera_center = (self.size[1] / 2, self.size[0] / 2)
self.camera_matrix = np.array(
[[self.focal_length, 0, self.camera_center[0]],
[0, self.focal_length, self.camera_center[1]],
[0, 0, 1]], dtype="double")

# Assuming no lens distortion
self.dist_coeefs = np.zeros((4, 1))

# Rotation vector and translation vector
self.r_vec = np.array([[0.01891013], [0.08560084], [-3.14392813]])
self.t_vec = np.array(
[[-14.97821226], [-10.62040383], [-2053.03596872]])
# self.r_vec = None
# self.t_vec = None
posted @   Joranger  阅读(23)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 使用C#创建一个MCP客户端
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· ollama系列1:轻松3步本地部署deepseek,普通电脑可用
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示