Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Decompose Homography matrix in opencv python

H = K[R|t] where H (3*3) is homographic matrix, R is Rotation matrix, K is matrix of camera's intrinsic parameters and t is translation vector.

I have calculated K using chess board pattern as follows

ret, K, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, chess_gray.shape[::-1],None,None)

Homograpy matrix H is calculated as

pts_src = np.float32(pts_src)
pts_dst = np.float32(pts_dst)
H, status = cv2.findHomography(pts_src, pts_dst)

How to decompose R and t from H and K using

cv2.decomposeHomograpyMat(H,K,....)

How to write other inputs and outputs of above functions?

like image 341
Avi Avatar asked Jul 29 '26 14:07

Avi


1 Answers

Assuming H as homography matrix and K as camera matrix the Python code is:

num, Rs, Ts, Ns  = cv2.decomposeHomographyMat(H, K)

num possible solutions will be returned.

Rs contains a list of the rotation matrix.
Ts contains a list of the translation vector.
Ns contains a list of the normal vector of the plane.

For further informations take a look into the official documentation:
OpenCV 3.4 - decomposeHomographyMat()

like image 200
Nils Avatar answered Aug 01 '26 04:08

Nils



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!