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