About the CV: warpaffine Function

Source: Internet
Author: User

Warpaffine was used for image rotation during Chinese Character verification code recognition, and some problems were found. I have carefully read the description of this function as follows:

//! Warps the image using affine transformation
Cv_exports_w void warpaffine (const mat & SRC, cv_out mat & DST,
Const mat & M, size dsize,
Int flags = inter_linear,
Int bordermode = border_constant,
Const scalar & bordervalue = scalar ());

 

Explanation URL http://opencv.willowgarage.com/documentation/cpp/geometric_image_transformations.html

 

The image transformation is completed using the following formula:

M matrix can be generated by Using CV: mat MAT = CV: getrotationmatrix2d (center, angle, 1.0 );

Center determines the center of rotation, angle is the rotation angle, and 1.0 is the magnification.

 

M matrix can also be specified as another form, such as setting m values,

Use Center (59.9), angle = 1.0, factor = to rotate the m value of the image

Note that M is from cv_64f. This type does not seem accessible with at <t>, and m is considered to be of the unsigned type.

You need to forcibly convert the type to double * m = (double *) M. Data;, and then read the data through the pointer. For specific code, refer to the source code of getrotationmatrix2d.

 

The value is calculated using the formula below.

 

When the characters are rotated, the angle skew of-59 degrees is incorrect.

-The 32-degree angle is correct.

 

The reason is that, on CV: minarearect, there is a difference of 90 when calculating the tilt angle of the Left turn. The following figure shows the right turn and the front shows the left turn.

How do I know whether to add a 90-degree value? The source code is very long and I did not take a closer look. It is roughly calculated by using the Conner in the lower-left corner to determine the two edges. The question is, what is the edge? There is a switch between the left and right sides regardless of the position relationship. (Lazy drawing. You can draw a picture by yourself.) The difference between the two edge vectors is exactly 90 degrees. One way is to determine the length of the side, but some words are not suitable.

 

In addition, warpaffine has a parameter. Note: warp_inverse_map

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.