我想计算我的相机在世界坐标中的位置。这应该相当容易,但我没有得到我期望的结果。我相信我已经阅读了有关此主题的所有内容,但我的代码无法正常工作。这就是我所做的:
我有一个相机正在观察一个区域。
1) 我画了一张该地区的地图。
2) 我通过将 4 个图像点与地图上的 4 个点匹配来计算单应性cv2.getPerspectiveTransform
3)H单应性将每个世界坐标转换为相机坐标;这工作正常
4)为了计算相机矩阵,我遵循了这个:
translation = np.zeros((3,1))
translation[:,0] = homography[:,2]
rotation = np.zeros((3,3))
rotation[:,0] = homography[:,0]
rotation[:,1] = homography[:,1]
rotation[:,2] = np.cross(homography[0:3,0],homography[0:3,1])
cameraMatrix = np.zeros((3,4))
cameraMatrix[:,0:3] = rotation
cameraMatrix[:,3] = homography[:,2]
cameraMatrix = cameraMatrix/cameraMatrix[2][3] #normalize the matrix
5)据此,相机的位置应该这样计算:
x,y,z = np.dot(-np.transpose(rotation),translation)
我得到的坐标完全错误。我猜问题应该出在第 4 步或第 5 步中。我的方法有什么问题?