lib.align.aligned_face.pose - Add pitch and yaw attributes

This commit is contained in:
torzdf 2021-02-22 12:27:07 +00:00
parent 7f6ee925f9
commit 7c746fa18e

View File

@ -479,6 +479,7 @@ class PoseEstimate():
self._camera_matrix = self._get_camera_matrix()
self._rotation, self._translation = self._solve_pnp(landmarks)
self._offset = self._get_offset()
self._pitch_yaw = None
@property
def xyz_2d(self):
@ -500,6 +501,28 @@ class PoseEstimate():
rather than the nose area. """
return self._offset
@property
def pitch(self):
""" float: The pitch of the aligned face in eular angles """
if not self._pitch_yaw:
self._get_pitch_yaw()
return self._pitch_yaw[0]
@property
def yaw(self):
""" float: The yaw of the aligned face in eular angles """
if not self._pitch_yaw:
self._get_pitch_yaw()
return self._pitch_yaw[1]
def _get_pitch_yaw(self):
""" Obtain the yaw and pitch from the :attr:`_rotation` in eular angles. """
proj_matrix = np.zeros((3, 4), dtype="float32")
proj_matrix[:3, :3] = cv2.Rodrigues(self._rotation)[0]
euler = cv2.decomposeProjectionMatrix(proj_matrix)[-1]
self._pitch_yaw = (euler[0][0], euler[1][0])
logger.trace("yaw_pitch: %s", self._pitch_yaw)
@classmethod
def _get_camera_matrix(cls):
""" Obtain an estimate of the camera matrix based off the original frame dimensions.