【发布时间】:2021-02-17 03:22:33
【问题描述】:
我正在尝试估计主要遵循本指南的单个图像的头部姿势: https://towardsdatascience.com/real-time-head-pose-estimation-in-python-e52db1bc606a
面部检测工作正常 - 如果我绘制图像和检测到的地标,它们可以很好地排列。
我正在根据图像估计相机矩阵,并假设没有镜头失真:
size = image.shape
focal_length = size[1]
center = (size[1]/2, size[0]/2)
camera_matrix = np.array([[focal_length, 0, center[0]],
[0, focal_length, center[1]],
[0, 0, 1]], dtype="double")
dist_coeffs = np.zeros((4, 1)) # Assuming no lens distortion
我正在尝试通过使用 solvePNP 将图像中的点与 3D 模型中的点进行匹配来获得头部姿势:
# 3D-model points to which the points extracted from an image are matched:
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 corner
(225.0, 170.0, -135.0), # Right eye corner
(-150.0, -150.0, -125.0), # Left Mouth corner
(150.0, -150.0, -125.0) # Right mouth corner
])
image_points = np.array([
shape[30], # Nose tip
shape[8], # Chin
shape[36], # Left eye left corner
shape[45], # Right eye right corne
shape[48], # Left Mouth corner
shape[54] # Right mouth corner
], dtype="double")
success, rotation_vec, translation_vec) = \
cv2.solvePnP(model_points, image_points, camera_matrix, dist_coeffs)
最后,我从旋转中得到欧拉角:
rotation_mat, _ = cv2.Rodrigues(rotation_vec)
pose_mat = cv2.hconcat((rotation_mat, translation_vec))
_, _, _, _, _, _, angles = cv2.decomposeProjectionMatrix(pose_mat)
现在方位角是我所期望的 - 如果我向左看,它是负数,中间是零,向右看是正数。
然而,海拔很奇怪 - 如果我看中间,它有一个恒定值但符号是随机的 - 从一个图像到另一个图像变化(值在 170 左右)。
当我查找符号为正时,值越查找越小, 当我向下看时,符号为负,并且值越低越低。
有人可以向我解释一下这个输出吗?
【问题讨论】:
标签: python-3.x opencv face-detection opencv-python pose-estimation