各ライブラリを最新版に変更,mediapipeの仕様変更に対応.

オイラー角計測をmediapipeのFaceLandmarkerで行うように変更し,yaw値バイアス問題を解決
This commit is contained in:
agomizi1cm committed 2026-10-03 23:58:25 +09:00
1 parent 321cbdca20
commit 5d1ecc6883
4 files changed
+57 -18

No files matched your search

+19
View File
@@ -111,3 +111,22 @@ class HeadPoseEstimator:
if math.isfinite(roll):
roll = (roll + 90.0) % 180.0 - 90.0
return float(pitch), float(yaw), float(roll)
@staticmethod
def facial_matrix_to_euler(matrix) -> tuple[float, float, float]:
import cv2
import numpy as np
m = np.asarray(matrix, dtype=np.float64).reshape(4, 4)
rotation = m[:3, :3]
rotation = rotation / np.linalg.norm(rotation, axis=0) # スケール成分を除去
angles = cv2.RQDecomp3x3(rotation)[0]
return float(angles[0]), float(angles[1]), float(angles[2])
def estimate_from_matrix(self, matrix) -> HeadPoseEstimation:
if not self.config.enabled:
return HeadPoseEstimation(False, failure_reason="head_pose_disabled")
try:
angles = self.facial_matrix_to_euler(matrix)
except Exception:
return HeadPoseEstimation(False, failure_reason="facial_matrix_failed")
return self.result_from_angles(angles) # 再投影誤差は無いので棄却判定はスキップされる