Lets say I have image1
and image2
obtained from a webcam. For taking the image2
, the webcam undergoes a rotation (yaw, pitch, roll) and a translation.
What I want: Remove the rotation from image2
so that only the translation remains (to be precise: my tracked points (x,y)
from image2
will be rotated to the the same values as in image1
so that only the translation component remains).
What I have done/tried so far:
- I tracked corresponding features from
image1
andimage2
. - Calculated the fundamental matrix
F
withRANSAC
to remove outliers. - Calibrated the camera so that I got a
CAM_MATRIX
(fx, fy and so on). - Calculated Essential Matrix from
F
withCAM_Matrix
(E = cam_matrix^t * F * cam_matrix
) - Decomposed the E matrix with OpenCV's SVD function so that I have a rotation matrix and translation vector. -I know that there are 4 combinations and only 1 is the right translation vector/rotation matrix.
So my thought was: I know that the camera movement from image1
to image2
won't be more than lets say about 20°/AXIS so I can eliminate at least 2 possibilities where the angles are too far off.
For the 2 remaining I have to triangulate the points and see which one is the correct one (I have read that I only need 1 , but due possible errors/outliers it should be done with some more to be sure which one is the right). I think I could use the OpenCV's triangulation function for this? Is my thought right so far? Do I need to calculate the projection error?
Let's move on and assume that I finally obtained the right R|t
matrix.
How do I continue? I tried to multiply the normal, as well as transposed rotation matrix which should reverse the rotation (?) (for testing purpose I just tried both possible combinations of R|t, I have not done the triangulation in code yet) with a tracked point in image2
. but the calculated point is way too far off from what it should be. Do I need the calibration matrix here as well?
So how can I invert the rotation applied to image2
? (to be exact, apply the inverse rotation to my std::vector<cv::Point2f>
array which contains the tracked (x,y) points from image2
)
Displaying the de-rotated image would be also nice to have. This is done with warpPerspective
function? Like in this post ?
(I just don't fully understand what the purpose of A1/A2 and dist in the T matrix is or how I can adopt this solution to solve my problem.)