Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the cv2.warpAffine parameter?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/01 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report