Perspective transformation

Perspective transformation is also called projection transformation. The affine transformation we often talk about is a special case of perspective transformation. The purpose of perspective transformation is to transform objects that are straight lines in reality into straight lines in the picture. Perspective transformation can map a rectangle to an arbitrary quadrilateral.

This technology is used when the robot is driving automatically. Perspective transformation is done through the function:

dst = cv2. warpPerspective(src, M, dsize[,flag, [,borderMode[,borderValue]]])

dst : The output image after perspective transformation, dsize determines the actual size of the output.

src: Source Image

M:3X3 transformation matrix

dsize: Output image size.

flags: Interpolation method, the default is INTER_LINEAR (bilinear interpolation). When it is WARP_INVERSE_MAP, it means that M is an inverse transformation, which can achieve the inverse transformation from the target dst to src.

borderMode: The edge type. The default is BORDER_CONSTANT. When the value is BORDER_TRANSPARENT, the values in the target image are not changed, and these values correspond to the outliers in the original image.

borderValue: Boundary value, the default is 0. Like affine transformation, OpenCV still provides a function cv2.getPerspectiveTransform() to provide the transformation matrix above.

The function is as follows.

matSrc: The coordinates of the four vertices of the input image.

matDst: Output the coordinates of the four vertices of the image.

Code path: