Skip to content

Instantly share code, notes, and snippets.

@shks
shks / opencv_rvec_tvec_to_matrix.py
Created September 2, 2021 02:42
opencv rvec, tvec into matrix34 and 44 / opencvの姿勢推定で得たrvec, tvecベクトルをマトリクス表現へ変換する
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)
@shks
shks / projectPoints_with_matrix.py
Created September 2, 2021 02:52
projectPoints with matrix / 投影計算をマトリクスで行う
# カメラ内部パラメータ(内部パラメータ行列)
# ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)
# -----reading camera intrinsic matrix
cameraMatrix = np.loadtxt("calib/cameraMatrix.csv",delimiter=",")
distCoeffs = np.loadtxt("calib/distCoeffs.csv",delimiter=",")
# 外部パラメータ行列
# https://gist.github.com/shks/e3cd5fc22ad9f4ddbccd5312a64803c3