cv.stereoRectify - MATLAB File Help
cv.stereoRectify

Computes rectification transforms for each head of a calibrated stereo camera

S = cv.stereoRectify(cameraMatrix1, distCoeffs1, cameraMatrix2, distCoeffs2, imageSize, R, T)
[...] = cv.stereoRectify(..., 'OptionName', optionValue, ...)

Input

Output

Options

The function computes the rotation matrices for each camera that (virtually) make both camera image planes the same plane. Consequently, this makes all the epipolar lines parallel and thus simplifies the dense stereo correspondence problem. The function takes the matrices computed by cv.stereoCalibrate as input. As output, it provides two rotation matrices and also two projection matrices in the new coordinates. The function distinguishes the following two cases:

  1. Horizontal stereo: the first and the second camera views are shifted relative to each other mainly along the x axis (with possible small vertical shift). In the rectified images, the corresponding epipolar lines in the left and right cameras are horizontal and have the same y-coordinate. P1 and P2 look like:

    P1 = [f 0 cx1 0;
          0 f cy  0;
          0 0 1   0]
    
    P2 = [f 0 cx2 Tx*f;
          0 f cy     0;
          0 0 1      0]
    

    where Tx is a horizontal shift between the cameras and cx1=cx2 if ZeroDisparity is set.

  2. Vertical stereo: the first and the second camera views are shifted relative to each other mainly in vertical direction (and probably a bit in the horizontal direction too). The epipolar lines in the rectified images are vertical and have the same x-coordinate. P1 and P2 look like:

    P1 = [f 0 cx  0;
          0 f cy1 0;
          0 0 1   0]
    
    P2 = [f 0 cx     0;
          0 f cy2 Ty*f;
          0 0 1      0]
    

    where Ty is a vertical shift between the cameras and cy1=cy2 if ZeroDisparity is set.

As you can see, the first three columns of P1 and P2 will effectively be the new "rectified" camera matrices. The matrices, together with R1 and R2, can then be passed to cv.initUndistortRectifyMap to initialize the rectification map for each camera.

See the output of the stereo_calibration_demo.m sample. Some red horizontal lines pass through the corresponding image regions. This means that the images are well rectified, which is what most stereo correspondence algorithms rely on. The green rectangles are roi1 and roi2. You see that their interiors are all valid pixels.

See also