I would like to determine the relative camera pose given two RGB camera frames. I assume there's overlap in field of view between the two cameras, what I am looking for ultimately is the rotation and translation between two cameras. I understand how to do this in theory, and am looking for existing openCV implementations in python. An existing one for matlab can be found here: https://www.mathworks.com/help/vision/ref/relativecamerapose.html#inputarg_inlierPoints1. But so far as I can tell I see no openCV API in python.


If you understand how relative pose estimation works in theory, it should be quite trivial to translate it into OpenCV code. First, you can pick any feature detection/description approach you like (say SIFT and brute force matching) and obtain a list of matches. But here, you need to be absolutely sure there is overlap between the images: because without feature matches, relative pose estimation would not work.

Once you have access to these matches (pairs of features visible in both images), you can then use the findEssentialMat() function in OpenCV, where you will have to provide the intrinsics data from the camera as well as those matching pairs you obtained in the first step. This function, using a RANSAC scheme will compute the essential matrix that encodes the transformation between the scenes. Once you obtain the matrix $E$, you can use another OpenCV function recoverPose() and pass the $E$ matrix to it, which will calculate the relative rotation (as a Rodrigues vector, if I remember right) and the relative translation up to scale.

These functions are available in C++ as well as Python. To put you on the right path about how to go about coding it in python, here is a tutorial on how to compute the fundamental matrix through feature matches in OpenCV: this can be easily extended to the essential matrix and subsequently the relative pose.



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.