fix(pose): 修正正面照被误判为1003(solvePnP翻转解)
ITERATIVE 偶发收敛到相机后方(tz<0),roll≈±180° 超阈值, 把正面照误判为非正面。检测到负深度时回退 SQPNP 重解正深度解。 补充回归测试。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -62,3 +62,41 @@ def test_threshold_gating_rejects_when_zeroed():
|
||||
def test_pose_none_is_not_blocked():
|
||||
"""solvePnP 失败(返回 None)时不拦截,check_frontal_face 返回 True。"""
|
||||
assert pose.estimate_head_pose.__doc__ # 占位,确保导入
|
||||
|
||||
|
||||
def test_iterative_flipped_solution_falls_back_to_sqpnp():
|
||||
"""回归:部分正面照上 ITERATIVE 会解出 tz<0、roll≈±180°,应回退 SQPNP。
|
||||
|
||||
像素点取自一张真实正面短发照(720×945);裸跑 ITERATIVE 会得到负深度。
|
||||
"""
|
||||
W, H = 720, 945
|
||||
# 鼻尖 / 下巴 / 左眼外 / 右眼外 / 左嘴角 / 右嘴角(像素)
|
||||
px = [
|
||||
(358.32715988, 600.98652095),
|
||||
(346.83344364, 779.63507116),
|
||||
(242.94779778, 466.76155195),
|
||||
(478.43703747, 480.10321766),
|
||||
(284.13277388, 679.95527387),
|
||||
(422.19510555, 684.31899190),
|
||||
]
|
||||
lm = [_LM(0.5, 0.5) for _ in range(478)]
|
||||
for idx, (u, v) in zip(PNP_INDICES, px):
|
||||
lm[idx] = _LM(u / W, v / H)
|
||||
|
||||
class _Holder:
|
||||
landmark = lm
|
||||
|
||||
holder = _Holder()
|
||||
# 确认裸 ITERATIVE 确实是翻转解(否则本回归失去意义)
|
||||
image_points = np.array(px, dtype=np.float64)
|
||||
cam = np.array([[float(W), 0, W / 2], [0, float(W), H / 2], [0, 0, 1]],
|
||||
dtype=np.float64)
|
||||
ok, rvec, tvec = cv2.solvePnP(
|
||||
_MODEL_POINTS, image_points, cam, np.zeros((4, 1)),
|
||||
flags=cv2.SOLVEPNP_ITERATIVE,
|
||||
)
|
||||
assert ok and float(tvec[2, 0]) < 0
|
||||
|
||||
yaw, pitch, roll = estimate_head_pose(holder, W, H)
|
||||
assert abs(roll) < 30, f"roll 应被纠正,实际 roll={roll}"
|
||||
assert check_frontal_face(holder, W, H) is True
|
||||
|
||||
Reference in New Issue
Block a user