Hi,
I don't know if you have the book, but the process is explained on pages 91 - 93.
The function is being used when we are trying to decompose the essential matrix of a camera into translational and rotational components, `trans` and `rot`, respectively.
However, this decomposition (based on SVD) actually has four possible solutions (using either +/- `u_3` with either matrix `W` or `Wt`), only one of which is the valid camera matrix. The four solutions are due to a rotational ambiguity (called the bas-relief ambiguity) and a discrete mirror ambiguity (called Necker reversal). What we can do to find the only valid solution is to iterate through all four solutions, and choose the one that geometrically corresponds to the situation where a reconstructed points lies in front of both cameras (scenario a in the figure below):
In order to do this, we need to project the 2D image coordinates of all keypoints to homogeneous coordinates. This is where the function _in_front_of_both_cameras() comes in.
Testing whether any given 3D point, derived from a point correspondence in both images, is in front of both cameras for one of the four possible rotation and translation combinations, is a bit tricky. This is because you initially only have the point's projection in each image but lack the point's depth. Assuming X, X' is a 3d point imaged in the first and second cameras coordinate system respectively, and (ũ,ṽ), (ũ', ṽ') the corresponding projection in normalized image coordinates, in the first and second camera images respectively, we can use a rotation translation pair to estimate the 3D points depth in each camera coordinate system:
where r1 .. r3 are the rows of the rotation matrix R and translation t. This is what the following code is doing to get z (`first_z` in the code) and X (`first_3d_point` in the code):
The two points then lie in front of both cameras if both points have a positive z coordinate, in which case the function returns True (else False).
The source of this transformation is here:
You can find more information on epipolar geometry in Hartley & Zisserman (2004). The relevant transformations are explained in Section 9.6, available here:
Best,
Michael