MATLAB File Help: cv.reprojectImageTo3D | Index |
Reprojects a disparity image to 3D space
im3d = cv.reprojectImageTo3D(disparity, Q)
[...] = cv.reprojectImageTo3D(..., 'OptionName', optionValue, ...)
im3d(x,y,ch)
contains 3D coordinates of
the point (x,y)
computed from the disparity map.HandleMissingValues=true
, then pixels with the minimal
disparity that corresponds to the outliers (see cv.StereoBM.compute)
are transformed to 3D points with a very large Z value (currently set
to 10000). default false.single
depth. Depth
can be set to one of:The function transforms a single-channel disparity map to a 3-channel image
representing a 3D surface. That is, for each pixel (x,y)
and the
corresponding disparity d=disparity(x,y)
, it computes:
[X, Y, Z, W]^T = Q * [x, y, disparity(x,y), 1]^T
im3d(x,y,:) = [X/W, Y/W, Z/W]
The matrix Q
can be an arbitrary 4x4 matrix (for example, the one computed
by cv.stereoRectify). To reproject a sparse set of points {(x,y,d),...}
to 3D space, use cv.perspectiveTransform.
The function is similar to the following simplified MATLAB code:
function XYZ = my_reprojectImageTo3D(D, Q)
[h,w] = size(D);
XYZ = zeros([h,w,3], 'single');
for x=1:h
for y=1:w
v = Q * [x; y; double(D(x,y)); 1];
XYZ(x,y,:) = v(1:3) ./ v(4);
end
end
end