相机参数
- 针孔模型的相机有两套参数,内参(intrinsic)和外参(extrinsic),参见机器视觉中3D到2D的映射
相机内参
相机外参 ^camera-extrinsic
- 对相机的位姿进行估计:通过solvePnP解决
- 例程
solvePnP得出的是被测量物体所在的坐标系原点相对于相机坐标系的变换,即因此要得到相机在世界坐标系中的位置,需要求一次逆矩阵
## a realsense camera
k = np.array([[898.194, 0., 635.698, 0., 898.194, 351.514, 0., 0., 1.]])
distort = np.array([.0]*5)
## object is a 140x60 mm rectangle, center at (345, 0, 200)
objPoints = np.array([[0.345,0.07,0.23], [0.345,-0.07,0.23], [0.345,-0.07,0.17], [0.345,0.07,0.17]], dtype = np.float32).reshape((4,3))
## obtain by clicking on the image
imagePoints = np.array([[561., 253.], [857., 254.], [850., 371.], [569., 368.]])
valid, rvec, tvec = cv2.solvePnP(objPoints, imagePoints, np.reshape(k, (3,3)), np.array(distort))
if valid:
ht = np.identity(4)
rot = cv2.Rodrigues(rvec)[0]
ht[:3, 3] = tvec.reshape(3)
ht[:3, :3] = rot
ht_inv = np.linalg.inv(ht) ## ht use camera cooridnate from, inverse gives the camera pose under the world frame.
print(ht_inv)结果为:
[[ 0.10882072 -0.38271898 0.9174335 -0.06719953]
[-0.99352716 -0.01162035 0.11299894 -0.01532151]
[-0.03258593 -0.92379173 -0.38150623 0.35066292]
[ 0. 0. 0. 1. ]]