# How to compute camera pose from Homography matrix?

Say I use only one calibrated camera. From this camera, I get images A and B. I know the homography between A and B, computed through OpenCV's findHomography().

I know the pose (rotation matrix R and translation vector t) of image A, and I need the pose of image B. Once I get it, I suppose I'll be able to compute every further poses of following images.

Do you know an implementation of computing B's pose? I found several articles on the web, but I couldn't find an easily implementable solution...

• I'm not sure that I understand how to use your code. I use OpenCV to retrieve the Homography, but when I send that Homography through the algorithm, it always returns this. cameraPose [1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 1, 0] – LeRoss Apr 23 '13 at 21:58

Even if my answer comes too late for you, maybe other people find this useful. I have the codes for an openCV Pose from Homography. I found the method at this really useful website, euclideanspace.

void cameraPoseFromHomography(const Mat& H, Mat& pose)
{
pose = Mat::eye(3, 4, CV_64FC1); //3x4 matrix
float norm1 = (float)norm(H.col(0));
float norm2 = (float)norm(H.col(1));
float tnorm = (norm1 + norm2) / 2.0f;

Mat v1 = H.col(0);
Mat v2 = pose.col(0);

cv::normalize(v1, v2); // Normalize the rotation

v1 = H.col(1);
v2 = pose.col(1);

cv::normalize(v1, v2);

v1 = pose.col(0);
v2 = pose.col(1);

Mat v3 = v1.cross(v2);  //Computes the cross-product of v1 and v2
Mat c2 = pose.col(2);
v3.copyTo(c2);

pose.col(3) = H.col(2) / tnorm; //vector t [R|t]
}


////

• I have used your function in my code.Pose matrix computed using this way is always being [1 0 0 0; 0 1 0 0;0 0 1 0;0 0 0 0] . Do you have any explanation ? – Muhammet Ali Asan Jun 12 '15 at 13:58
• Are you using the pose of A ? It seems that you're only using the input H – Guig Jun 21 '17 at 14:19

I found a nice implementation, using OpenCV: http://nghiaho.com/?p=1298

You can use Homography decomposition method implemented in Opencv 3.0+

decomposeHomographyMat

• Opencv’s function returns set of possible rotations, camera normals and translation matrices.
• You have to select correct set among them by comparing camera normals with camera normal of camera when first image was captured