MATLAB File Help: cv.stereoRectify | Index |
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, ...)
[w,h]
.[x,y,w,h]
. If Alpha=0
, the ROIs cover
the whole images. Otherwise, they are likely to be smaller.Alpha=0
means that the rectified images are zoomed
and shifted so that only valid pixels are visible (no black areas
after rectification). Alpha=1
means that the rectified image is
decimated and shifted so that all the pixels from the original iamges
from the cameras are retained in the rectified images (no source image
pixels are lost). Obviously, any intermediate value yields an
intermediate result between those two extreme cases. default -1imageSize
. Setting it to larger
value can help you preserve details in the original image, especially
when there is a big radial distortion.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:
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.
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 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.