A method for generating a wavy text picture

By generating wavy text images during OCR recognition model training, and utilizing coordinate system mapping functions and OpenCV remapping, the problem of low recognition accuracy caused by scanning pen jitter was solved, thus improving the model's recognition performance.

CN116137018BActive Publication Date: 2026-06-05INGENIC SEMICON CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
INGENIC SEMICON CO LTD
Filing Date
2021-11-18
Publication Date
2026-06-05

AI Technical Summary

Technical Problem

Existing OCR recognition models have low accuracy when processing wavy text images caused by pen tremors.

Method used

By establishing a coordinate system and setting the mapping function h(x, y) = y + A|sin(2πx/T)|, the original image is remapped using OpenCV's Remap() function to generate a wavy text image that simulates the stitching of a scanning pen, controlling the undulations and periodicity of the text.

Benefits of technology

It improves the accuracy of OCR recognition models in recognizing wavy text images, and generates images with rich styles through simple data augmentation algorithms to simulate the stitching effect of a scanning pen.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116137018B_ABST
    Figure CN116137018B_ABST
Patent Text Reader

Abstract

The application provides a wave-shaped text picture generation method, which is based on an original image to establish a coordinate system, remap pixels, and set a mapping function h(x, y)=y+A|sin(2pi x / T)|, and the height and period of the text fluctuation can be controlled by setting A and T, and the mapping transformation is completed through the Remap() function of OpenCV. The method comprises the following steps: S1. preparing an original image to establish a coordinate system; S2. setting a mapping function: the wave-shaped transformation is completed by remapping the pixels on the image, and the position (x, y) of each pixel is expressed through the remapping, which is g(x, y)=f(h(x, y)); wherein g() is a target image, f() is a source image, and h(x, y) is a mapping method function acting on (x, y); the mapping formula is h(x, y)=y+A|sin(2pi x / T)|, and the height and period of the text fluctuation are controlled by setting A and T; A is the amplitude of the text, and T is the fluctuation period; a new image is generated by controlling the two parameters A and T; and S3. mapping transformation.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of intelligent video processing technology, and in particular to a method for generating wavy text images. Background Technology

[0002] With the development of computer technology and the widespread application of computer vision principles, the use of scanning pens is becoming increasingly accepted by the public. Training an OCR (Optical Character Recognition) model using a neural network requires collecting a large amount of image data containing text, and these images should be as similar as possible to the images used for recognition. The scanning pen collects a set of images during its swipe and then stitches these images together into a single image. Due to unavoidable shaking during the use of the scanning pen, the stitched image exhibits a wavy effect. However, text in images generated by text image generators or captured by photography is generally flat. This causes existing models to be less accurate when encountering images with wavy text. Therefore, the model needs to learn this wavy font during training to improve its recognition accuracy.

[0003] In addition, the following are commonly used terms in the prior art:

[0004] Image remapping maps each pixel in an input image to the corresponding position in another image according to certain rules, forming a new image.

[0005] OpenCV is an open-source, cross-platform computer vision and machine learning software library that provides a large number of image processing functions. This application will use the image remapping functions it provides. Summary of the Invention

[0006] This application proposes a data augmentation method, specifically a data augmentation algorithm for the training of an OCR recognition model using a scanning pen. This algorithm can render text in an image with a wavy effect, which, when applied to OCR recognition model training, improves the model's recognition performance.

[0007] Specifically, this invention provides a method for generating wavy text images. The method establishes a coordinate system based on the original image, remaps the pixels on the image, and sets a mapping function.

[0008] h(x, y) = y + A|sin(2πx / T)|, where A and T can be set to control the height and period of the text's undulations, and the mapping transformation is completed using OpenCV's Remap() function.

[0009] The method includes the following steps:

[0010] S1. Prepare the original image: Prepare an original image containing text, with a width of W and a height of H; and establish a coordinate system with the top left corner of the image as the origin, the rightward axis as the axis, and the downward axis as the axis, i.e., the XY coordinate system;

[0011] S2. Set the mapping function: To complete the wavy transformation, the pixels on the image need to be remapped. The position (x,y) of each pixel is expressed by the remapping, which is: g(x,y) = f ( h(x,y) );

[0012] Where g() is the target image, f() is the source image, and h(x,y) is the mapping method function applied to (x,y);

[0013] Mapping formula: h(x, y) = y + A|sin(2πx / T)|, where A and T are used to control the height and period of the text undulation; A is the maximum deviation from the initial text position along the y-axis, and T is the undulation period; by controlling the two parameters A and T, a new image is generated.

[0014] S3. Mapping Transformation:

[0015] S3.1 Construct two two-dimensional arrays img_x[H][W] and img_y[H][W] to record the mapped pixel coordinates; the size of the arrays is the same as the size of the image;

[0016] S3.2, traverse the entire image to obtain each pixel, and denote the current pixel as I(i, j); perform mapping on pixel I(i, j): i' = i; j' = h(i, j), and record the transformed values ​​img_x[j][i] = i', img_y[j][i] = j';

[0017] S3.3, use the Remap function provided by OpenCV to apply the mapping rules to the entire image:

[0018] new_img = Remap(img, img_x, img_y);

[0019] In the function, img is the original input image; img_x and img_y are the mapping matrices after the above h(x,y) transformation; new_img is the generated new image.

[0020] The original image containing text is in img format.

[0021] In step S1, since all coordinate calculations are based on pixels, the coordinate results are all integers.

[0022] In step S2, the generated new image is in the style of a pattern stitched together by a scanning pen.

[0023] The image remapping function Remap performs a geometric transformation on the original image according to a specified mapping form. The Remap function is the code implementation of the following formula: `img` corresponds to `src` in the formula; `img_x` and `img_y` correspond to `mapx(x,y)` and `mapy(x,y)` in the formula; `new_img` corresponds to `dst` in the formula. The formula is as follows:

[0024] dst(x,y)=src(mapx(x,y),mapy(x,y))

[0025] src: Input image, either grayscale or true color;

[0026] dst: Output image, which must be the same size as mapx and mapy, and have the same number of channels and data type as src;

[0027] mapx: Used to store the mapping relationship of the image in the X direction;

[0028] mapy: Used to store the mapping relationship of the image in the Y direction.

[0029] Therefore, the advantage of this application is:

[0030] The algorithm provided by this method has a relatively low computational load. By controlling the two parameters of character amplitude and period, it can generate images with rich styles, which greatly simulates the style of images stitched together by a scanning pen and improves the accuracy of the recognition model. Attached Figure Description

[0031] The accompanying drawings, which are provided to further illustrate the invention and form part of this application, are not intended to limit the scope of the invention.

[0032] Figure 1 This is a flowchart illustrating the method described in this application.

[0033] Figure 2 This is an initial schematic diagram of an embodiment in this application.

[0034] Figure 3 This is a schematic diagram of the mapped image of an embodiment in this application. Detailed Implementation

[0035] To better understand the technical content and advantages of the present invention, the present invention will now be described in further detail with reference to the accompanying drawings.

[0036] like Figure 1As shown, this application discloses a method for generating wavy text images, the method comprising the following steps:

[0037] S1. Prepare the original image: Prepare an original image containing text, with a width of W and a height of H; and establish a coordinate system with the top left corner of the image as the origin, the rightward axis as the axis, and the downward axis as the axis, i.e., the XY coordinate system;

[0038] S2. Set the mapping function: To complete the wavy transformation, the pixels on the image need to be remapped. The position (x,y) of each pixel is expressed by the remapping, which is: g(x,y) = f ( h(x,y) );

[0039] Where g() is the target image, f() is the source image, and h(x,y) is the mapping method function applied to (x,y);

[0040] Mapping formula: h(x, y) = y + A|sin(2πx / T)|, where A and T are used to control the height and period of the text undulation; A is the maximum deviation from the initial text position along the y-axis, and T is the undulation period; by controlling the two parameters A and T, a new image is generated.

[0041] S3. Mapping Transformation:

[0042] S3.1 Construct two two-dimensional arrays img_x[H][W] and img_y[H][W] to record the mapped pixel coordinates; the size of the arrays is the same as the size of the image;

[0043] S3.2, traverse the entire image to obtain each pixel, and denote the current pixel as I(i, j); perform mapping on pixel I(i, j): i' = i; j' = h(i, j), and record the transformed values ​​img_x[j][i] = i', img_y[j][i] = j';

[0044] S3.3, use the Remap function provided by OpenCV to apply the mapping rules to the entire image:

[0045] new_img = Remap(img, img_x, img_y);

[0046] In the function, img is the original input image; img_x and img_y are the mapping matrices after the above h(x,y) transformation; new_img is the generated new image.

[0047] Specifically, specific embodiments of this application can be further described as follows:

[0048] Step S1. Prepare the original image

[0049] Prepare an original image (img) containing text, such as... Figure 2 As shown, the image has a width of W and a height of H. A coordinate system, the XY coordinate system, is established with the top-left corner of the image as the origin, the rightward axis as the axis, and the downward axis as the axis. Since all coordinate calculations are based on pixels, the coordinate results are all integers.

[0050] Step S2. Set the mapping function

[0051] To perform a wavy transform, the pixels in the image need to be remapped. Generally, we express the position (x,y) of each pixel through remapping, like this: g(x,y) = f(h(x,y)). Here, g() is the target image, f() is the source image, and h(x,y) is the mapping method function applied to (x,y).

[0052] The mapping formula is: h(x, y) = y + A|sin(2πx / T)|. By setting A and T, the height and period of the text can be controlled.

[0053] Step S3. Mapping Transformation

[0054] (a) Construct two two-dimensional arrays img_x[H][W] and img_y[H][W] to record the mapped pixel coordinates. The size of the arrays is the same as the size of the image.

[0055] (b) Traverse the entire image to obtain each pixel, and denote the current pixel as I(i, j). Map the pixel I(i, j): i' = i; j' = h(i, j), and record the transformed values ​​img_x[j][i] = i', img_y[j][i] = j'.

[0056] (c) Apply the mapping rules to the entire image using the Remap function provided by OpenCV, as shown in the image below. Figure 3 As shown.

[0057] new_img = Remap(img, img_x, img_y).

[0058] The `remap()` function performs a geometric transformation on the original image based on the specified mapping format, using the following formula:

[0059] dst(x,y)=src(mapx(x,y),mapy(x,y))

[0060] src: Input image, either grayscale or true color.

[0061] dst: Output image, which should be the same size as mapx and mapy, and have the same number of channels and data type as src.

[0062] mapx: Used to store the mapping relationship of the image in the X direction.

[0063] mapy: Used to store the mapping relationship of the image in the Y direction.

[0064] To further understand the implementation scheme, the Remap function will be explained in C++ prototype:

[0065] void remap(InputArray src, OutputArray dst, InputArray map1,InputArray map2,int interpolation, int borderMode = BORDER_CONSTANT,constScalar& borderValue = Scalar())

[0066] Function analysis:

[0067] 1) InputArray type src, input image, fill in Mat class object, and it must be a single channel 8-bit or floating point image;

[0068] 2) The OutputArray type dst stores the result of the function call. That is, this parameter is used to store the output result after the function call, and it must have the same size and type as the original image.

[0069] 3) map1 of type InputArray has two possible representation objects;

[0070] Represents the first mapping of the point (x, y);

[0071] This represents an X value of type CV_16S, CV_32FC1, or CV_32FC2.

[0072] 4) map2 of type InputArray, similarly, has two possible representations of objects, and it determines which object to represent based on map1;

[0073] If map1 represents the point (x, y), this parameter does not represent any value;

[0074] This represents the Y value (second value) of type CV_16UC1 or CV_32FC1.

[0075] 5) Interpolation of int type: The interpolation method was discussed in the previous resize() function. Note that the INTER_AREA interpolation method mentioned in the resize() function is not supported here. Therefore, the available interpolation methods are as follows:

[0076] INTER_NEAREST: Nearest neighbor interpolation;

[0077] INTER_LINEAR: Bilinear interpolation (default value);

[0078] INTER_CUBIC: Bicubic spline interpolation (bicubic interpolation within a 4x4 pixel neighborhood);

[0079] INTER_LANCZOS4: Lanczos interpolation (Lanczos interpolation for neighborhoods larger than 8x8 pixels)

[0080] 6) The int type borderMode is the boundary mode, with a default value of BORDER_CONSTANT, which means that the pixels of "outliers" in the target image will not be modified by this function;

[0081] 7) `const Scalar& borderValue` is the value used when there is a constant boundary. The default value is 0.

[0082] The explanation of the Remap function is recorded in an article by CSDN blogger "iduanbin".

[0083] In summary, the method of this application achieves the generation of wavy text images through simple implementation steps of setting mapping functions and mapping transformations, which is beneficial for the model to better learn and recognize such image text.

[0084] The above description is merely a preferred embodiment of the present invention and is not intended to limit the present invention. For those skilled in the art, various modifications and variations can be made to the embodiments of the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of the present invention should be included within the protection scope of the present invention.

Claims

1. A method for generating wavy text images, characterized in that, The method establishes a coordinate system based on the original image, remaps the pixels on the image, and sets a mapping function. h(x, y) = y + A|sin(2πx / T)|, where A and T can be set to control the height and period of the text's undulations, and the mapping transformation is completed using OpenCV's Remap() function; The method includes the following steps: S1. Prepare the original image: Prepare an original image containing text, with a width of W and a height of H; and establish a coordinate system with the top left corner of the image as the origin, the rightward axis as the axis, and the downward axis as the axis, i.e., the XY coordinate system; S2. Set the mapping function: To complete the wavy transformation, the pixels on the image need to be remapped. The position (x,y) of each pixel is expressed by the remapping, which is: g(x,y) = f ( h(x,y) ); Where g() is the target image, f() is the source image, and h(x,y) is the mapping method function applied to (x,y); Mapping formula: h(x, y) = y + A|sin(2πx / T)|, where A and T are used to control the height and period of the text undulation; A is the maximum deviation from the initial text position along the y-axis, and T is the undulation period; by controlling the two parameters A and T, a new image is generated. S3. Mapping Transformation: S3.1 Construct two two-dimensional arrays img_x[H][W] and img_y[H][W] to record the mapped pixel coordinates; the size of the arrays is the same as the size of the image; S3.2, traverse the entire image to obtain each pixel, and denote the current pixel as I(i, j); perform mapping on pixel I(i, j): i' = i; j' = h(i, j), and record the transformed values ​​img_x[j][i] = i', img_y[j][i] = j'; S3.3, use the Remap function provided by OpenCV to apply the mapping rules to the entire image: new_img = Remap(img, img_x, img_y); In the function, img is the original input image; img_x and img_y are the mapping matrices after the above h(x,y) transformation; new_img is the generated new image.

2. The method for generating a wavy text image according to claim 1, characterized in that, The original image containing text is in img format.

3. The method for generating a wavy text image according to claim 1, characterized in that, In step S1, since all coordinate calculations are based on pixels, the coordinate results are all integers.

4. The method for generating a wavy text image according to claim 1, characterized in that, In step S2, the generated new image is in the style of a pattern stitched together by a scanning pen.

5. The method for generating a wavy text image according to claim 1, characterized in that, The image remapping function Remap performs a geometric transformation on the original image according to a specified mapping form. The Remap function is the code implementation of the following formula: `img` corresponds to `src` in the formula; `img_x` and `img_y` correspond to `mapx(x,y)` and `mapy(x,y)` in the formula; `new_img` corresponds to `dst` in the formula. The formula is as follows: dst(x,y)=src(mapx(x,y),mapy(x,y)) src: Input image, either grayscale or true color; dst: Output image, which must be the same size as mapx and mapy, and have the same number of channels and data type as src; mapx: Used to store the mapping relationship of the image in the X direction; mapy: Used to store the mapping relationship of the image in the Y direction.