我有一个安装在固定位置的云台安全摄像机。摄像机的当前平移和倾斜值可随时(通过API)获知。 我从cv2.solepnp()了解一种特定的平移和倾斜组合的外部矩阵。现在,我想找到一种方法来计算任何平移和倾斜值的相机外部矩阵。我需要矩阵来使用函数cv2.projectPoints()
我有两个解决方法,但是都行不通。
想法1:
r11 r12 r13 p1
r21 r22 r23 p2
r31 r32 r33 p3
0 0 0 1
想法2:
这是2个想法的python实现:
pan = 10 # degree (at the time solvePNP was called)
tilt = 20 # degree (at the time solvePNP was called)
# get extrinsic parameters
(success, rvec_world, tvec_worl) = cv2.solvePnP(objectPoints, imagePoints, camera_matrix, distortion, flags=cv2.SOLVEPNP_ITERATIVE)
# get 4x4 matrix
pose = np.vstack((np.hstack((cv2.Rodrigues(rvec_world)[0], tvec_worl)), [0, 0, 0, 1]))
pose = np.linalg.inv(pose) # This line only for 2. Idea
# calculate initial pose
initial_pose =np.dot(pose,np.linalg.inv(pan_tilt_4x4_matrix(pan,tilt)))
# calculate extrinsic matrix for arbitrary pan and tilt value
arbitrary_pose =np.dot(initial_pose,pan_tilt_4x4_matrix(new_pan,new_tilt))
arbitrary_pose = np.linalg.inv(arbitrary_pose) # This line only for 2. Idea
# now I use the arbitrary_pose matrix with cv2.projectPoints
谢谢。