Welcome to Raspberry Pi 4B repository
7.Perspective Transformation
Perspective Transformation
Perspective transformation is also called projection transformation. The purpose of perspective transformation is to transform objects that are line in reality but may appear as oblique lines on the picture into line by perspective transformation.
Perspective transformation can map rectangles to arbitrary quadrilaterals. We will use this technique when our robot Autopilot lessons.
Perspective transformation function,
dst = cv2. warpPerspective(src, M, dsize[,flag, [,borderMode[,borderValue]]])
l dst: the output picture after perspective transformation, dsize determines the actual size of the output picture .
l src: source image (Original picture)
l M: 3x3 transformation matrix
l dsize: size of output image
l Flags: interpolation method, the default INTER_LINEAR (bilinear interpolation), when it is WARP_INVERSE_MAP, it means that M is an inverse transformation, which can realize the inverse transformation from the target dst to src.
l borderMode: edge type. The default is BORDER_CONSTANT. When the value is BORDER_TRANSPARENT, it means that the values in the target image are not changed, and these values correspond to the abnormal values in the original image.
l borderValue: border value, the default is 0.
OpenCV provides a function to provide a transformation matrix for perspective transformation.
The function is as follows:
matAffine = cv2.getPerspectiveTransform(matSrc, matDst)
l matSrc: the coordinates of the four vertices of the input picture.
l matDst: the coordinates of the four vertices of the output picture.
Code:
|
After running the following program, we can see the picture after the perspective transformation, as shown below.