Created
September 2, 2021 02:42
-
-
Save shks/e3cd5fc22ad9f4ddbccd5312a64803c3 to your computer and use it in GitHub Desktop.
opencv rvec, tvec into matrix34 and 44 / opencvの姿勢推定で得たrvec, tvecベクトルをマトリクス表現へ変換する
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
retval, rvec, tvec = aruco.estimatePoseBoard(corners, ids, board, cameraMatrix, distCoeffs, None, None) | |
#rvec, tvec : 3 float vector | |
#ロドリゲス公式で、rvecから回転行列へ変換する | |
Rmatrix, Jacob = cv2.Rodrigues(rvec) | |
# [3 x 4 matrix]で、R|t マトリクスを作成 | |
RTmatrix34_L = np.concatenate([Rmatrix, tvec], axis=1) | |
# [4x4]のマトリクスにしておく | |
tmp = np.array([0,0,0,1]) | |
RTmatrix = np.vstack((RTmatrix34_L, tmp.T)) | |
#test with inverse / 逆行列のテスト | |
inv_RTmatrix = np.linalg.inv(RTmatrix) | |
#単位行列になるはず | |
print(cameraMatrix.dot(RTmatrix34_L)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment