Stereoscopic triangulation (source code)

= Stereoscopic triangulation

<Stereoscopic triangulation> reconstructs a scene point from corresponding image positions and known <camera> geometry. Each image position determines a viewing direction. Two correctly matched views constrain the point to lie on both viewing rays; one view alone leaves its position along a ray undetermined.

For an ideal aligned pair, put the left <camera> at the origin and the right one at $(B,0,0)$ in a <Cartesian coordinate system>, with their axes pointing in the positive $Z$ direction. Assume a common <focal length> $f$, square <pixels>, corrected distortion and image coordinates measured from aligned principal points. Forward <perspective projection> gives
$$
u_L=\frac{fX}{Z},\qquad u_R=\frac{f(X-B)}{Z},\qquad v_L=v_R=\frac{fY}{Z}.
$$
The <stereo disparity> $d=u_L-u_R$ therefore determines all three coordinates:
$$
\boxed{Z=\frac{fB}{d},\qquad X=\frac{Bu_L}{d},\qquad Y=\frac{Bv_L}{d}.}
$$
Here $Z$ is depth along the <camera> axis; the <Euclidean distance> from the left <camera> is instead $\sqrt{X^2+Y^2+Z^2}$. If $f,u_L,v_L,d$ use <pixels> and the <camera baseline> $B$ uses metres, the recovered coordinates use metres. Without a known length scale, the images alone do not determine metric size.<Camera Calibration and 3D Reconstruction by OpenCV>[Detailed Description, camera intrinsic matrix and the distortion-free pinhole projection equations]{ref}

\Image[/rectified-stereo-triangulation.png]
{title=Two viewing directions determine a point in ideal <stereoscopic triangulation>}
{description=Original schematic in a horizontal cross-section, using virtual image planes in front of the pinholes. Each signed image coordinate is measured from its own principal point; the right coordinate is negative in this example.}

Real <cameras> require calibration before these simplified equations apply. <Stereo rectification> transforms the images to an aligned geometry. With noisy measurements, viewing rays need not intersect exactly; minimizing <reprojection error> instead seeks a point whose projected positions agree as closely as possible with the observations. Reconstruction also depends on <stereo correspondence>: a mathematically precise intersection of mismatched viewing directions can still describe the wrong scene point.<What Is Stereo Reconstruction? by MathWorks>[Stereo Camera Calibration; Stereo Image Rectification; Disparity Map Computation; 3-D Scene Reconstruction]{ref}