Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the cv2.warpAffine parameter?

Shulou Source: shulou.com Published: 2022-06-01 07:45:30 09月27日 Update

This article will explain in detail what the cv2.warpAffine parameters are, and the editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.

WarpAffine: it means affine change. The official parameters are:

Cv2.warpAffine (src, M, dsize [, dst [, flags [, borderMode [, borderValue]) → dst

Where:

Src-enter the image.

M-transformation matrix.

Dsize-the size of the output image.

Flags-combination of interpolation methods (int type! )

BorderMode-Border Pixel Mode (int type! )

BorderValue-(key point! The boundary fill value; by default, it is 0

Of the above parameters:

M, as an affine transformation matrix, generally reflects the relationship between translation or rotation, and is a 2 × 3 transformation matrix of InputArray type.

Flages represents interpolation method. Default is flags=cv2.INTER_LINEAR, which represents linear interpolation.

In addition: cv2.INTER_NEAREST (nearest neighbor interpolation)

Cv2.INTER_AREA (region interpolation)

Cv2.INTER_CUBIC (cubic Spline interpolation)

Cv2.INTER_LANCZOS4 (Lanczos interpolation)

In daily affine transformation, when only the first three parameters are set, such as cv2.warpAffine (img,M, (rows,cols)), the basic affine transformation effect can be achieved, but the "black edge" phenomenon can occur, as shown in the figure:

This often causes a lot of trouble to the subsequent processing, the sixth parameter can choose the color of the fill, the default is black. The parameter for setting warpAffine in python is different from that in C++. You must specify the name of the parameter, as shown below:

In C++:

WarpAffine (src,img,M,Size (aforme b), 1meme 0meme Scalar (255255255))

In python:

Cv2.warpAffine (img,M, (rows,cols), flags=cv2.INTER_,borderMode=cv2.BORDER_REFLECT,borderValue= (255255255))

One advantage in python is that you don't have to set it sequentially, but simply specify the parameters you set. For example, fill the boundary area of the above image with white:

Cv2.warpAffine (img,M, (lengh,lengh), borderValue= (255255255))

Effect picture:

This is the end of this article on "what are cv2.warpAffine parameters?". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Parameters interpolation transformation affine matrix article type boundary region image situation effect more cantilever different good practical very large three pixels Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB MySQL vpn Huawei