transformation. This is because the transformation requires division by the final dimension (usually 𝑍; see
Chapter 11) and thus loses a dimension in the process.
As with affine transformations, image operations (dense transformations) are handled by different functions
than transformations on point sets (sparse transformations).
cv::warpPerspective(), Dense perspective transform
The dense perspective transform uses an OpenCV function that is analogous to the one provided for dense
affine transformations. Specifically, cv::warpPerspective() has all of the same arguments as
cv::warpAffine(), except with the small, but crucial, distinction that the map matrix must now be 3-
by-3.
void cv::warpPerspective(
cv::InputArray src, // Input Image
cv::OutputArray dst, // Result image
cv::InputArray M, // 3-by-3 transformation matrix
cv::Size dsize, // Destination image size
int flags = cv::INTER_LINEAR, // Interpolation, and inverse
int borderMode = cv::BORDER_CONSTANT, // Pixel extrapolation method
const cv::Scalar& borderValue = cv::Scalar() // Used for constant borders
);
Each element in the destination array is computed from the element of the source array at the location given
by:
𝑑𝑠𝑡 𝑥, 𝑦 = 𝑠𝑟𝑐
𝑀
!!
𝑥 + 𝑀
!"
𝑦 + 𝑀
!"
𝑀
!"
𝑥 + 𝑀
!"
𝑦 + 𝑀
!!
,
𝑀
!"
𝑥 + 𝑀
!!
𝑦 + 𝑀
!"
𝑀
!"
𝑥 + 𝑀
!"
𝑦 + 𝑀
!!
As with the affine transformation, the location indicated by the right side of this equation will not ...