相机旋转矩阵
Camera rotation matrix
我正在尝试对视频进行光线追踪。就此而言,我需要世界坐标中每一帧的相机旋转矩阵。相机在原点。暂无翻译。
我有摄像机的轨迹作为每一帧的旋转变化。
所以对于每一帧,我都有三个值(roll、yaw、pitch)来描述相机从这一帧到下一帧应该旋转多少。这些旋转要在相机坐标系下理解。
如何计算帧的世界坐标旋转矩阵?
我尝试了什么:
def rot_x(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[1,0,0], [0, cosa, -sina], [0, sina, cosa]])
def rot_y(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, 0, sina], [0,1,0], [-sina, 0, cosa]])
def rot_z(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, -sina, 0], [sina, cosa, 0], [0,0,1]])
matrices = [initial_rot]
for pitch, yaw, roll in frames_data:
rx = rot_x(pitch)
ry = rot_y(yaw)
rz = rot_z(roll)
last_matrix = matrices[-1]
matrices.append(last_matrix.T.dot(rx).dot(ry).dot(rz))
(因为last_matrix应该是正交的,所以它的逆应该是转置)。
但是,出现了严重错误,渲染的视频只是在 y 维度上闪烁。我确定这里的数学有问题..
矩阵乘法的顺序很重要。应用另一个旋转应该通过左乘(假设标准约定)来完成。
因为这是简单的复合多次旋转,所以应该不需要反转最后的旋转。
应为第 N 帧计算的完整旋转是:
R_n = R(yaw_n, pitch_n, roll_n) R_{n - 1} R_{n - 2} ... R_1 R_0
与:
R_0: the initial rotation (i.e. initial_rot)
R_n: the complete rotation for the frame N
R(yaw_n, pitch_n, roll_n): the rotation derived from the yaw / pitch / roll values applied between frame N - 1 and N (i.e. rx.dot(ry).dot(rz))
因此代码摘录中的最后一行应该改为:
rotation = rx.dot(ry).dot(rz)
matrices.append(rotation.dot(last_matrix))
我正在尝试对视频进行光线追踪。就此而言,我需要世界坐标中每一帧的相机旋转矩阵。相机在原点。暂无翻译。
我有摄像机的轨迹作为每一帧的旋转变化。 所以对于每一帧,我都有三个值(roll、yaw、pitch)来描述相机从这一帧到下一帧应该旋转多少。这些旋转要在相机坐标系下理解。
如何计算帧的世界坐标旋转矩阵?
我尝试了什么:
def rot_x(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[1,0,0], [0, cosa, -sina], [0, sina, cosa]])
def rot_y(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, 0, sina], [0,1,0], [-sina, 0, cosa]])
def rot_z(angle):
cosa = np.cos(angle)
sina = np.sin(angle)
return np.array([[cosa, -sina, 0], [sina, cosa, 0], [0,0,1]])
matrices = [initial_rot]
for pitch, yaw, roll in frames_data:
rx = rot_x(pitch)
ry = rot_y(yaw)
rz = rot_z(roll)
last_matrix = matrices[-1]
matrices.append(last_matrix.T.dot(rx).dot(ry).dot(rz))
(因为last_matrix应该是正交的,所以它的逆应该是转置)。
但是,出现了严重错误,渲染的视频只是在 y 维度上闪烁。我确定这里的数学有问题..
矩阵乘法的顺序很重要。应用另一个旋转应该通过左乘(假设标准约定)来完成。
因为这是简单的复合多次旋转,所以应该不需要反转最后的旋转。
应为第 N 帧计算的完整旋转是:
R_n = R(yaw_n, pitch_n, roll_n) R_{n - 1} R_{n - 2} ... R_1 R_0
与:
R_0: the initial rotation (i.e. initial_rot)
R_n: the complete rotation for the frame N
R(yaw_n, pitch_n, roll_n): the rotation derived from the yaw / pitch / roll values applied between frame N - 1 and N (i.e. rx.dot(ry).dot(rz))
因此代码摘录中的最后一行应该改为:
rotation = rx.dot(ry).dot(rz)
matrices.append(rotation.dot(last_matrix))