首先获得从世界坐标系(此世界坐标系为以车辆后轴中心为原田,右为x,前为y,向上为z)到相机坐标系的旋转矩阵(Rotation Matrix)和平移向量(Translation Vector)。这通常由一个称为RT矩阵(旋转-平移矩阵)来表示。一旦你有RT矩阵,你可以使用旋转矩阵的元素来计算相机的安装角度。
import numpy as np
# 假设你有一个RT矩阵
# 这里只是一个示例,请用你的实际数据替代
R_world_to_camera = np.array([[0.866, -0.5, 0],
[0.5, 0.866, 0],
[0, 0, 1]])
t_world_to_camera = np.array([1, 2, 3])
# 构造RT矩阵
RT_matrix = np.column_stack((R_world_to_camera, t_world_to_camera))
RT_matrix = np.row_stack((RT_matrix, [0, 0, 0, 1]))
# 提取旋转矩阵
R_matrix = RT_matrix[:3, :3]
# 计算旋转矩阵的欧拉角(yaw, pitch, roll)
yaw = np.arctan2(R_matrix[1, 0], R_matrix[0, 0])
pitch = np.arctan2(-R_matrix[2, 0], np.sqrt(R_matrix[2, 1]**2 + R_matrix[2, 2]**2))
roll = np.arctan2(R_matrix[2, 1], R_matrix[2, 2])
# 转换为角度(如果需要)
yaw = np.degrees(yaw)
pitch = np.degrees(pitch)
roll = np.degrees(roll)
print(f"Yaw: {yaw}, Pitch: {pitch}, Roll: {roll}")