Text image generation method, device and electronic device

By obtaining text sequences from the corpus and combining them with real paper background images for rendering, the problem of lack of text image data sets in educational scenarios is solved, high-quality text images with content labels are generated, and the training accuracy of the text recognition model is improved. And reduce the cost of manual annotation.

CN114565702BActive Publication Date: 2024-09-24BEIJING DINGSHIXINGJIAOYU CONSULTATION CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202210179876.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-02-25
Publication Date
2024-09-24
Estimated Expiration
2042-02-25

AI Technical Summary

Technical Problem

In the existing technology, there is a lack of text image data sets for text recognition training in educational scenarios, resulting in low recognition accuracy of the model, and manual annotation is time-consuming and labor-intensive, and it is difficult to ensure accuracy.

Method used

By obtaining text sequences from the corpus, synthesizing the original text foreground image based on preset parameters, and combining it with the real paper background image for overall rendering, a realistic text image with content labels is generated, which solves the problem of scarce data sets.

Benefits of technology

It achieves large-scale synthesis of text images with content labels, improves the quality and accuracy of training data for text recognition models, reduces the cost and time of manual annotation, and generates images that are closer to real scenes.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114565702B
    Figure CN114565702B
Patent Text Reader

Abstract

The present disclosure relates to a method, device and electronic device for generating a text image. The method comprises: obtaining a text sequence of a predetermined length from a corpus; adjusting the text sequence based on pre-set parameters to synthesize an original text foreground image; performing foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image; obtaining a background image, merging the text foreground image with the background image to generate a merged image; performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image, and using the text sequence as a content label of the final text image.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of image processing, and in particular, to a text image generation method, device and electronic device. Background Art

[0002] In educational scenarios, there are large amounts of text in teaching materials such as test papers, PPTs, and books. Teachers and students need to extract text content from image formats. Common teaching tasks such as collecting wrong questions, archiving test questions, and converting books to editable formats all require text recognition technology. Therefore, there is a great demand for text recognition technology.

[0003] Currently, text recognition requires a large number of text line images for model training, and text line recognition training is a supervised learning process, which requires clear text annotation content corresponding to each text line image. Text images with content annotations are extremely important but very scarce. The industry often uses public data sets such as scene character recognition, relying on annotators to manually annotate, or directly save text labels as images and convert them into text line images through some simple cropping.

[0004] Most of the existing public scene character recognition datasets are collected from natural scenes, such as street scene images, etc. The text style of such scene character recognition images is very different from the text in educational scenes, so the model trained with such data has a low recognition accuracy in educational scenes.

[0005] For manual labeling, investing manpower to label text line content is an extremely time-consuming and labor-intensive task, and the accuracy of manually labeled text line content is difficult to guarantee. If dirty data with incorrect labels enters the model training, it is easy to reduce the accuracy of the model reasoning.

[0006] However, the solution of directly saving text labels as images can only obtain text line images similar to the scanned style. It is difficult to simulate the texture of paper text in real scenes, and it is also difficult to simulate real natural photographed text effects such as lighting and shadows.

[0007] It can be seen that there is a technical problem in the prior art that there is a lack of text image datasets for text recognition training in current educational scenarios. Summary of the invention

[0008] The purpose of the present disclosure is to provide a text image generation method, device and electronic device, which are used to solve the technical problem of the lack of text image data sets for text recognition training in current educational scenarios in the prior art.

[0009] In order to achieve the above-mentioned object, the present disclosure provides, in a first aspect, a text image generation method for text recognition model training, the method comprising:

[0010] Obtain a text sequence of predetermined length from the corpus;

[0011] The text sequence is adjusted based on preset parameters to synthesize an original text foreground image;

[0012] According to the foreground rendering strategy, the original text foreground image is subjected to foreground rendering to generate a text foreground image;

[0013] Acquire a background image, merge the text foreground image and the background image to generate a merged image;

[0014] The combined image is subjected to overall image rendering according to an overall image rendering strategy to obtain a final text image, and the text sequence is used as a content label of the final text image.

[0015] Optionally, adjusting the text sequence based on preset parameters to synthesize the original text foreground image includes:

[0016] Initializing the text style of the text to be synthesized in the text sequence, wherein the text style includes one or more combinations of font type, font size, font color, spacing between characters, and actual pixel width of text spaces;

[0017] Calculating the width, height and distance between characters of each character in the text sequence to obtain the position of each character in the text sequence in the original text foreground image to be synthesized;

[0018] Calculating the original pixel size of the original text foreground image to be synthesized based on the position of each character in the original text foreground image to be synthesized;

[0019] Initialize an image according to the original pixel size; wherein the size of the initialized image is equal to the original pixel size; or, the width of the initialized image is equal to the width of the original pixel size, and the height of the initialized image is greater than the height of the original pixel size;

[0020] According to the position of each character in the original text foreground image to be synthesized, each character is drawn on the initialization image to synthesize the original text foreground image.

[0021] Optionally, when the width of the initialized image is equal to the width of the original pixel size and the height of the initialized image is greater than the height of the original pixel size, performing foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image includes:

[0022] According to the original text foreground image, determining whether it is necessary to draw a character mark under the character in the original text foreground image according to a random probability value;

[0023] If it is determined to be necessary, the drawing width and the starting position of the character mark are selected according to a preset synthesis mode, and the ending position is calculated according to the drawing width and the starting position;

[0024] The character mark is drawn with the bottom of the character at the starting position as the starting point and the bottom of the character at the ending position as the end point to generate the text foreground image; wherein the character mark is an underline or an emphasis mark; and the pre-set synthesis mode is a fixed character synthesis mode, a random character synthesis mode and a full character synthesis mode.

[0025] Optionally, performing foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image includes:

[0026] Calculating a binary image of the original text foreground image;

[0027] According to the preset filtering template and filtering rules, the original text foreground image is filtered in a left-to-right and top-to-bottom order to generate the filtered text foreground image;

[0028] Among them, the number of vertical pixel points of the filter template is greater than the number of horizontal pixel points of the filter template; the filtering rule refers to selecting the minimum pixel value in the overlapping area between the filter template and the binary image as the pixel value of the center point of the current overlapping area in the binary image.

[0029] Optionally, performing foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image includes:

[0030] Based on the target direction distortion formula, the target direction offset of the one-dimensional position vector of the original text foreground image in the orthogonal direction under the target direction distortion formula is calculated, and the target direction offset is recorded; wherein, when the target direction is a vertical direction, the orthogonal direction is a horizontal direction; when the target direction is a horizontal direction, the orthogonal direction is a vertical direction;

[0031] Calculating the maximum range of the overall relative offset according to the target direction offset;

[0032] According to the original pixel size of the text image to be synthesized and the maximum range of the overall relative offset;

[0033] Creating a new foreground image, and calculating the size of the newly created foreground image according to the size of the original text foreground image and the maximum range of the overall relative offset;

[0034] The image vector on each one-dimensional position vector in the original text foreground image is reconstructed on the newly created foreground image according to the target direction offset corresponding to each one-dimensional position vector to generate the text foreground image.

[0035] Optionally, the vertical distortion formula is any of the following;

[0036]

[0037]

[0038]

[0039]

[0040] Among them, F v_sin represents the sinusoidal twist formula, F v_cos represents the cosine curve twist formula, F v_rsin represents the inverse sine curve twist formula, F v_rcos Represents the arccosine curve distortion formula; x is the horizontal axis coordinate, from [0, W f -1], W f is the width of the original text foreground image, ratio is the frequency adjustment parameter of sine and cosine, K is the amplitude adjustment parameter of sine and cosine, H f is the height of the original text foreground image;

[0041] The horizontal distortion formula is

[0042]

[0043] Where x is the vertical axis coordinate, from [0, H f -1], H f is the height of the original text foreground image, D char is the average character width, and ratio is the translation factor.

[0044] Optionally, performing foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image includes:

[0045] Calculating the position mapping relationship between the rotated pixel points and the pixel points of the original text foreground image according to a preset rotation matrix;

[0046] The text foreground image is generated based on the original text foreground image and the position mapping relationship.

[0047] Optionally, the rotation matrix is

[0048]

[0049] Among them, k represents the scaling factor, θ represents the rotation angle, and x and y represent the rotation center.

[0050] Optionally, the background image is a real paper background image; the method further includes:

[0051] Calculating a normalized distribution matrix of the real paper background image so that the pixel values ​​of the real paper background image are between 0 and 1;

[0052] The normalized distribution matrix is ​​multiplied pixel by pixel by pixel in the text foreground image to obtain the text foreground image after adaptive brightness adjustment.

[0053] The text foreground image after the brightness adaptive adjustment is combined with the real paper background image to obtain a text image after the brightness adaptive adjustment.

[0054] Optionally, performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes:

[0055] Calculating the size of the merged image;

[0056] Based on the size of the merged image, calculate the starting position and the ending position of the table lines in the four directions of up, down, left, and right of the merged image;

[0057] The remaining state of the table lines in the four directions is randomly determined; if they are retained, line segments are drawn on the merged image according to the starting position and the end position of the corresponding table lines to obtain the final text image.

[0058] Optionally, the size of the merged image is W*H, and based on the size of the merged image, the starting position and the ending position of the table lines in the four directions of up, down, left, and right of the merged image are calculated, including:

[0059] Calculate the starting position of the table line above the merged image as (0, h top ), the end point is (W-1, h top );

[0060] Calculate the starting position of the table line below the merged image as (0, h bottom ), the end point is (W-1, h bottom );

[0061] Calculate the starting position of the table line on the left side of the merged image as (w left , 0), the end point is (w left , H-1);

[0062] Calculate the starting position of the table line on the right side of the merged image as (w right , 0), the end point is (w right , H-1);

[0063] Among them, h top 、h bottom 、w left and w right These are preset values.

[0064] Optionally, performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes:

[0065] Select the number of random interference lines;

[0066] For each interference line, randomly set the starting position and the ending position of each interference line within the two-dimensional range of the merged image;

[0067] According to the starting point position and the end point position of each interference line and the interference line style in the preset image library, a line segment is drawn on the merged image to obtain the final text image.

[0068] Optionally, performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes:

[0069] Create an N*N diagonal matrix; where N represents the sampling range of motion blur;

[0070] Randomly initialize the rotation angle of the motion process, and calculate the rotation matrix based on the rotation angle;

[0071] Calculating an overall fuzzy operator based on the diagonal fuzzy operator created by the rotation matrix;

[0072] According to the overall motion blur operator, motion blur processing is performed on the merged image to obtain the final text image.

[0073] Optionally, performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes:

[0074] The combined image is rendered as a whole using a Gaussian blur algorithm to obtain the final text image.

[0075] Optionally, the background image is a real paper background image, a scanned background image or a Gaussian noise background image.

[0076] A second aspect of the present disclosure provides a text image generation device for character recognition model training, comprising:

[0077] A foreground synthesis module is used to obtain a text sequence of a predetermined length from a corpus; adjust the text sequence based on pre-set parameters to synthesize an original text foreground image; perform foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image;

[0078] A background synthesis module, used to obtain a background image, merge the text foreground image and the background image, and generate a merged image;

[0079] The overall image rendering module is used to perform overall image rendering on the merged image according to the overall image rendering strategy to obtain a final text image, and use the text sequence as a content label of the final text image.

[0080] A third aspect of the present disclosure provides a non-temporary computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of the method described in the first aspect.

[0081] A fourth aspect of the present disclosure provides an electronic device, including:

[0082] a memory having a computer program stored thereon;

[0083] A processor is used to execute the computer program in the memory to implement the steps of the method described in the first aspect.

[0084] Through the above technical scheme, the text foreground image and the background image are designed separately, and the text foreground image and the background image are rendered separately, and then the synthesized overall image is further rendered, thereby achieving a realistic text image synthesis effect. This scheme can synthesize text images with content labels on a large scale, thereby solving the problem of lack of text image data sets for text recognition training in educational scenarios, and obtaining a large number of text images with content labels for text recognition training.

[0085] Other features and advantages of the present disclosure will be described in detail in the following detailed description. BRIEF DESCRIPTION OF THE DRAWINGS

[0086] The accompanying drawings are used to provide a further understanding of the present disclosure and constitute a part of the specification. Together with the following specific embodiments, they are used to explain the present disclosure but do not constitute a limitation of the present disclosure. In the accompanying drawings:

[0087] Figure 1 is a block diagram of a text image generation method according to an exemplary embodiment;

[0088] Figure 2 is a flowchart of a method for generating a text image according to an exemplary embodiment;

[0089] Figure 3 is a schematic diagram of basic text synthesis according to an exemplary embodiment;

[0090] Figure 4 is a schematic diagram showing a random synthesis of underlines or emphasis marks according to an exemplary embodiment;

[0091] Figure 5 is a schematic diagram of a text image before and after corrosion according to an exemplary embodiment;

[0092] Figure 6 is a schematic diagram showing a synthetic text distortion according to an exemplary embodiment;

[0093] Figure 7 is a schematic diagram of a background image according to an exemplary embodiment;

[0094] Figure 8 is a schematic diagram of Gaussian blur according to an exemplary embodiment;

[0095] Fig. 9 is a schematic diagram of motion blur according to an exemplary embodiment;

[0096] Fig.10 is a schematic diagram of a process of overall image rendering according to an exemplary embodiment;

[0097] Figure 11A-11C is a schematic diagram showing a foreground rendering mode, a background rendering mode and a synthesized image according to an exemplary embodiment;

[0098] Fig.12 is a block diagram of a text image generating device according to an exemplary embodiment;

[0099] Fig.13 It is a block diagram of an electronic device according to an exemplary embodiment. DETAILED DESCRIPTION

[0100] The specific implementation of the present disclosure is described in detail below in conjunction with the accompanying drawings. It should be understood that the specific implementation described herein is only used to illustrate and explain the present disclosure, and is not used to limit the present disclosure.

[0101] In the embodiment of the present disclosure, a text image generation method for training a text recognition model in an educational scenario is proposed. Figure 1As shown in FIG. 1 , the image processing method is divided into three main modules, namely, foreground synthesis module, background synthesis module and overall image rendering module. The three modules are used in coordination to finally obtain a text image with text identification content for training a text recognition model.

[0102] like Figure 2 FIG. 1 is a flow chart of a text image generation method according to an exemplary embodiment, which includes the following steps.

[0103] Step 201: Obtain a text sequence of a predetermined length from a corpus.

[0104] In the foreground synthesis stage, we first need to obtain a text sequence of appropriate character length from the corpus. This text sequence will serve as the content label of the subsequent synthesized text image. The content label of the text image is the content of the text sequence, which is used for subsequent text recognition model training and testing.

[0105] Step 202: The text sequence is adjusted based on pre-set parameters to synthesize the original text foreground image, wherein the pre-set parameters include font type, font size, font color, spacing between characters, actual pixel width of text spaces, etc.

[0106] Step 203, foreground rendering is performed on the original text foreground image according to a foreground rendering strategy to generate a text foreground image. The foreground rendering strategy may include one or more of random synthesis of underlines and emphasis marks, horizontal erosion, random tilting, random text edge cutting, and text distortion, which are not limited in the present disclosure.

[0107] Step 204, obtain a background image, merge the text foreground image and the background image, and generate a merged image. The background image may be a real paper background image, a scanned background, a Gaussian noise background, etc., and the present disclosure does not limit this.

[0108] Step 205, performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image, and using the text sequence as a content label of the final text image. The overall image rendering strategy may include one or more of foreground image adaptive illumination adjustment, random interference line synthesis, table line generation, Gaussian blur, and motion blur, which are not limited in the present disclosure.

[0109] Through the above technical scheme, the text foreground image and the background image are designed separately, and the text foreground image and the background image are rendered separately, and then the synthesized overall image is further rendered, thereby achieving a realistic text image synthesis effect. This scheme can synthesize text images with content labels on a large scale, thereby solving the problem of lack of text image data sets for text recognition training in educational scenarios, and obtaining a large number of text images with content labels for text recognition training.

[0110] In the disclosed embodiment, basic text synthesis is first described.

[0111] In the foreground synthesis stage, it is necessary to obtain a text sequence with an appropriate character length from the corpus, and this text sequence will be used as the content label of the text image synthesized later. When performing basic text synthesis, the style of the synthesized text needs to be initialized as follows. The style of the text at least includes font category, font size, font color, spacing between characters, and actual pixel width of the text space. Among them, the font category is randomly selected from the pre-collected font library. In the embodiment of the present disclosure, for educational scenarios, common educational fonts and other fonts that may be used can be collected, and the probability of the font being selected is set based on the actual frequency of use of different fonts. The spacing between characters represents the free pixel distance between adjacent characters. For example, it can be taken as the character spacing value according to a uniform distribution between [0, 5]. After the parameters of the basic text synthesis are initialized, the width and height of each character and the distance between characters are calculated to obtain the actual two-dimensional position of each character in the synthesis process.

[0112] Based on the character position calculated in the previous step, that is, the two-dimensional position coordinates of each character in the text image, the pixel size of the basic text foreground can be calculated, expressed as W f and H f Then initialize an image with RGBA color channels and the image size is W f *(H f +32), where the height can be equal to the original pixel size or greater than the original pixel size. In the embodiment of the present disclosure, the image size is W f *(H f +32), 32 pixels are added for the subsequent rendering of underlines or emphasis. Using the PIL (Python Image Library, image processing toolkit) image library, each character is drawn on the foreground image according to the original position (the character position calculated in the previous step). This method is used to obtain the initial version of the original text foreground image, such as Figure 3 As shown, Figure 3It is a visualization of the RGBA color space. The text color depth represents the font color, and the box line indicates the drawing position of each character.

[0113] The basic text synthesis method in the disclosed embodiment facilitates flexible adjustment of synthesis parameters and can synthesize an original text foreground image of any shape based on the designed parameters.

[0114] Next, foreground rendering will be described.

[0115] The inventor of the present disclosure has analyzed educational scenarios and found that there are often underlines or origins under the text in test papers and books, indicating emphasis symbols; the width of the horizontal strokes of special fonts is narrow, and the horizontal foreground of some scanned test papers is easy to fade; taking pictures or scanning causes the text direction to tilt; some text is irregular and prone to edge cutting; the text is irregularly bent and deformed. Therefore, after obtaining the basic original text foreground image, different foreground rendering strategies are disclosed in the embodiments of the present disclosure for further foreground rendering to simulate the above-mentioned reality and make the synthesized text image close to the real text image. In the embodiments of the present disclosure, the foreground rendering strategy includes one or more of random synthesis of underlines and emphasis symbols, horizontal corrosion, random tilting, random text edge cutting, and text distortion. These foreground rendering strategies are explained below. In the specific implementation process, they are not limited to the following methods.

[0116] Randomly synthesize underscores and emphasis

[0117] In the disclosed embodiment, three synthesis modes of underline and emphasis are preset, namely fixed character synthesis (fixed), random character synthesis (random) and full character synthesis (full). Fixed character synthesis means randomly selecting a character starting point in the current text sequence, and drawing an underline or emphasis according to a fixed number of characters; random character synthesis means randomly selecting a character starting point and randomly selecting a character width to draw an underline or emphasis; full character synthesis means drawing an underline or emphasis under all characters. These three modes can be flexibly selected according to actual needs, so as to simulate the text style in real teaching materials.

[0118] For any synthesis mode, the following synthesis method is used. Given a basic text foreground, determine whether to draw a character mark according to a random probability value. If the determination is successful, draw an underline or emphasis. According to the current synthesis mode, select the drawing width of the underline or emphasis, and randomly select the starting position of the underline or emphasis (such as the current full mode, the starting position is 0), and calculate the end position according to the drawing width. Then, use the PIL library to draw a straight line segment with the character below the starting position as the starting point and the character below the end position as the end point. The line segment width can be specified by parameters, such as Figure 4The diagram shown is a schematic diagram of randomly synthesizing underlines or emphasis marks.

[0119] Lateral corrosion

[0120] The inventor of the present disclosure analyzed text images in educational scenarios and found that the horizontal strokes of some teaching fonts are smaller than the vertical strokes. During the photo or scan process, the horizontal strokes are prone to become lighter or even lost. In order to simulate this process, the present solution discloses a foreground rendering mode of horizontal erosion. Erosion is a processing algorithm in image morphology, which is mainly used to remove certain parts of an image in morphology.

[0121] The horizontal erosion algorithm in the embodiment of the present disclosure can simulate the phenomenon that the horizontal strokes become narrower or disappear, and ensure that the vertical strokes are not affected to a large extent. The detailed algorithm is as follows.

[0122] (1) Calculate the binary image of the original text foreground image, and the size of the obtained binary image is consistent with that of the original text foreground image.

[0123] (2) Design a filter template, wherein the number of vertical pixel points of the filter template is greater than the number of horizontal pixel points of the filter template.

[0124] For example, a 3*1 filter template can be designed. The 3*1 filter template can ensure that the erosion process is calculated in the vertical direction, so that the final vertical stroke pixel width becomes narrower, that is, the width of the horizontal stroke becomes narrower. Compressing the effective pixel content in the vertical direction makes the horizontal line appear to be flattened, thereby achieving horizontal erosion. Among them, 3*1 refers to the filter size of image processing, the unit is the number of pixels, that is, a filter with 3 pixels in height and 1 pixel in width, the height is greater than the width, which can ensure that the erosion process is carried out in the vertical direction.

[0125] (3) Specify filtering rules: Select the minimum value in the overlapping area between the template and the binary image as the minimum point of the center point of the current overlapping area in the binary image.

[0126] (4) Filter from left to right and from top to bottom to complete the lateral corrosion process.

[0127] The lateral erosion algorithm in the disclosed embodiment can efficiently and realistically simulate the phenomenon of lateral stroke narrowing commonly seen in educational scenarios, such as Figure 5 As shown, the upper figure is the text image before corrosion, and the lower figure is the text image after corrosion.

[0128] Random Tilt

[0129] In order to simulate situations such as paper tilt or camera tilt, the embodiment of the present disclosure designs a function of random text tilt. During the foreground rendering process, the following rotation matrix can be used to calculate the position mapping relationship between the pixel points of the rotated text and the original basic foreground image.

[0130]

[0131] Wherein, k represents the scaling ratio, which can be set to 1 by default or can be adjusted according to other application requirements; θ represents the rotation angle, for example, θ can be randomly selected from [-15, 15]. x, y represent the rotation center, and in the embodiment of the present disclosure, the center of the picture is used as the rotation center.

[0132] Random text trimming

[0133] In actual business scenarios, text recognition technology is often used in conjunction with a text detection module. However, the results of text detection are difficult to ensure the integrity of the text area, and the bottom or top edges of the text are prone to clipping. In order to simulate this phenomenon, a small-scale text edge clipping method is designed in the embodiment of the present disclosure. The detailed steps are as follows.

[0134] (1), calculate the height of the current foreground image as H.

[0135] (2) Randomly calculate the pixel distance of the upper and lower edges in the range [0, 0.1*H]. For example, the upper edge cutting distance is h. c_up , the cutting distance of the lower edge is h c_bottom .

[0136] (3) Select The foreground image within the height range is the cropped image and is returned.

[0137] Text distortion

[0138] The inventors of the present disclosure have discovered that in actual business scenarios, the text on the paper will appear distorted due to the handheld test paper or the uneven desktop. Distorted text is difficult to recognize. If the text recognition model is not trained for the distorted form, the recognition accuracy of the distorted text will be greatly reduced. In order to improve the robustness of the text recognition model to distorted text, the present disclosure embodiment designs a text distortion simulation algorithm. In the present disclosure embodiment, the target direction includes the horizontal direction and the vertical direction, and correspondingly, the distortion formula includes the horizontal distortion formula and the vertical distortion formula. The detailed algorithm is as follows.

[0139] (1) Designing vertical distortion formulas. In the embodiment of the present disclosure, four text distortion formulas in the vertical direction are designed, namely: sine curve distortion, cosine curve distortion, inverse sine curve distortion and inverse cosine curve distortion. The formulas are as follows.

[0140]

[0141]

[0142]

[0143]

[0144] Among them, F v_sin represents the sinusoidal twist formula, F v_cos represents the cosine curve twist formula, F v_rsin represents the inverse sine curve twist formula, F v_rcos Represents the arccosine curve twist formula. x is the horizontal axis coordinate, from [0, W f -1], W f is the width of the foreground image, ratio is the frequency adjustment parameter of sine and cosine, K is the amplitude adjustment parameter of sine and cosine, H f is the height of the foreground image.

[0145] (2) Designing a horizontal distortion formula. The inventors of the present disclosure have found that the common form of text often presents a left-right offset style, so a translation transformation algorithm is designed in the embodiments of the present disclosure, and its formula is as follows.

[0146]

[0147] Where x is the vertical axis coordinate, from [0, H f -1], H f is the height of the foreground image, D char is the average character width, and ratio is the translation coefficient. The geometric meaning of this formula is that the text in the foreground image shows a tendency to lean to the left or right as the value on the vertical axis changes.

[0148] (3) Select a vertical distortion method, taking sinusoidal distortion as an example, calculate the vertical offset of the one-dimensional position vector in the horizontal direction under the distortion formula, and record it.

[0149] (4) Based on the vertical offset obtained in (3), calculate the maximum range of the overall relative offset H v_m , and then create a new foreground image in RGBA color space with a size of (H f +H v_m )*W fThen, for each one-dimensional position vector in the horizontal direction, the vertical image vector at the horizontal position in the original image is reconstructed on the newly created foreground image according to the vertical offset position at the horizontal position (i.e., the vertical offset in the vertical direction, calculated according to the horizontal axis position in the original image and the vertical distortion formula). At this point, the vertical distortion is completed. For each x-coordinate in the horizontal direction, a vertical column of image pixels is the vertical image vector.

[0150] (5) Select whether to perform horizontal distortion. If necessary, reconstruct the foreground image according to the horizontal distortion method and steps (3) and (4).

[0151] The foreground text image distortion algorithm in the embodiment of the present disclosure can achieve rich distortion style rendering based on the combination of distortions in the horizontal and vertical directions and by adjusting the parameters such as the frequency and amplitude of the vertical distortion formula, thereby simulating the text distortion in real scenes. Figure 6 The following is a schematic diagram of synthetic text distortion.

[0152] Next, the background synthesis module is described.

[0153] The background synthesis module is responsible for synthesizing the background image. Three background synthesis modes are designed in the embodiment of the present disclosure, namely, real paper photographing background, scanning background, and Gaussian noise background. In practical applications, other background images can also be used, and the present disclosure does not limit this. Among them, for the real paper photographing background, the real paper background can be collected in the embodiment of the present disclosure, and the brightness can be adjusted and enhanced to obtain a large number of paper backgrounds. The scanning background is a solid color background, which is basically white and gray tones, used to simulate the text image of the scanning style. Gaussian noise background, in order to improve the robustness of text recognition under any background, a Gaussian noise background is designed in the embodiment of the present disclosure. The synthetic text image under the Gaussian noise background can simulate the effect of background random disturbance to a large extent, which is conducive to the training of the text recognition model.

[0154] In the disclosed embodiment, the process of generating the Gaussian noise background is as follows.

[0155] (1) Generate a two-dimensional array image with all 1s, and the image size is consistent with the foreground image size.

[0156] (2) For each pixel in the two-dimensional array image, the pixel value at that location is calculated based on the Gaussian distribution. The probability density function of the Gaussian distribution is as follows.

[0157]

[0158] Wherein, μ is the mean value, which may be set to 235 by default in the embodiment of the present disclosure. 2is the variance, which can be set to 10 by default in the embodiment of the present disclosure. The two-dimensional array generated based on the above values ​​is a Gaussian noise image.

[0159] like Figure 7 As shown, Figure 7 The upper middle is the real paper background, the middle is the scanned background, and the bottom is the Gaussian noise background.

[0160] Next, the overall image rendering module is described.

[0161] The overall image rendering module is used to overlap the foreground text image and the background image, and render the overall image in detail according to the text characteristics of the educational scene. The overall image rendering strategy may include one or more of foreground image adaptive lighting adjustment, random interference line synthesis, table line generation, Gaussian blur and motion blur, and the present disclosure does not limit this. The above-mentioned overall image rendering strategies are described below.

[0162] Adaptive illumination adjustment algorithm for foreground images

[0163] When the background image mode is a real paper background, the brightness of different positions on the paper background is inconsistent due to the influence of lighting in the real environment and the interference of paper texture. The font color of the text in the foreground text image is consistent. At this time, if the foreground and background are directly collaged and merged, the foreground color will be consistent, but the background color will be inconsistent, resulting in a reduction in the degree of simulation.

[0164] In order to solve the above problems, the embodiment of the present disclosure discloses a foreground image adaptive illumination adjustment algorithm, which includes the following steps.

[0165] (1), obtain the background image in real paper mode.

[0166] (2) Calculate the two-dimensional normalized matrix of the background image so that the pixels of the entire background image are between 0 and 1. The normalization formula is as follows.

[0167]

[0168] Among them, X represents the total pixel value, x i is the pixel value at the current position, f pixel is the final normalized distribution value of the position.

[0169] (3) The normalized distribution matrix obtained in step (2) is multiplied pixel by pixel with the foreground, and the result obtained is the foreground image after adaptive brightness adjustment.

[0170] (4) Collage and merge the foreground image and the background image.

[0171] Through the foreground image adaptive illumination adjustment algorithm, a foreground image whose brightness changes with the background image can be obtained, and then the two can be combined to achieve a more realistic synthesis effect.

[0172] Random Interference Line Synthesis

[0173] In real scenes, the text on paper is often interfered by other line segments, such as handwriting noise, etc. In order to simulate this effect, a random interference line synthesis method is designed in the disclosed embodiment of the present invention, and interference line segments are randomly drawn on the image after the foreground and background are combined, so as to achieve a better simulation effect. The method includes the following steps.

[0174] (1) Set the number of random interference lines. In the embodiment of the present disclosure, it can be defaulted to be randomly selected from [0, 3].

[0175] (2) For each random line, the starting point and the end point are randomly set within the two-dimensional range of the image, and this randomness is obtained using uniform distribution.

[0176] (3) Use the image library to draw line segments.

[0177] Table line generation

[0178] Since there are often text data in table style in teaching scenarios, in the text detection stage, table lines are often classified as nearby text candidate boxes because they are close to the text style. However, table lines are a very interfering noise for text recognition, resulting in a decrease in recognition accuracy. Therefore, in order to improve the text recognition accuracy of the text recognition model under the interference of table lines, a table line generation algorithm is designed in the embodiment of the present disclosure, as detailed below.

[0179] (1), calculate the size W*H of the whole image.

[0180] (2) Calculate the position of the table line in the four directions of up, down, left and right respectively. The calculation method is as follows.

[0181] Top: The starting point is (0, h top ), the end point is (W-1, h top ), where h top The value range can be [1, 3]

[0182] Bottom: The starting point is (0, h bottom ), the end point is (W-1, h bottom ), where h bottom The value range is [H-4, H-1]

[0183] Left: The starting point is (w left , 0), the end point is (w left , H-1), where wleft The value range is [1, 3]

[0184] Right: The starting point is (w right , 0), the end point is (w right , H-1), where w right The value range is [W-4, W-1]

[0185] (3) In order to simulate the real situation, there may be [0-4] table lines, that is, there may be 0-4 table lines in the entire text line. Therefore, the existence status of the above four table lines is randomly determined. If they exist, the line segment is drawn according to the starting and ending positions of the table line.

[0186] In the disclosed embodiment, the table line generation method can be used to synthesize cell data close to the actual situation, which is beneficial to improving the recognition accuracy of the cell text by the text recognition model.

[0187] Gaussian Blur

[0188] In teaching scenarios, when teachers and students take photos of test papers and books with mobile phones or other devices, the text is often blurred due to blurred light or the quality of the mobile phone camera. However, the text images obtained by synthesis have clear text and theoretically no blur problem. Directly using such clear text images to participate in model training will result in a low recognition accuracy rate for the blurred text images in the final text recognition model.

[0189] In order to simulate the blurry shooting, Gaussian blur is used in the present embodiment for text image rendering. Gaussian blur is a digital image processing method that reduces the level of image detail. Its visual effect is similar to observing an image through frosted glass. After selecting a suitable Gaussian kernel, the effect of text blur in a photographed image can be simulated more realistically.

[0190] In the disclosed embodiment, Gaussian blur is selected as the blur rendering algorithm because the Gaussian blur filter can well preserve the edge effect of text in the image and ensure that no false high-frequency oscillations are generated during the image filtering process.

[0191] The key parameter of Gaussian blur is the Gaussian kernel radius. After many experiments, it is found that in educational scenarios, based on the nature of text images, the Gaussian kernel radius should not exceed 3 (the Gaussian kernel radius is relative to the image pixels). Otherwise, it is easy to cause excessive loss of text information and generate false samples during the text synthesis process. Therefore, the Gaussian kernel radius of the Gaussian blur in the embodiment of the present disclosure is randomly sampled between [1, 3], and the image is blurred and rendered. Figure 8 The following is a schematic diagram of Gaussian blur.

[0192] Motion Blur

[0193] Since teachers and students are susceptible to environmental or hand shaking factors when taking photos of test papers and books, the final imaging effect is blurred, and this blur can be classified as motion blur. Motion blur refers to a phenomenon in which the object is dragged due to the relatively rapid relative movement between the object and the camera. In order to simulate this effect, the embodiment of the present disclosure designs a motion blur algorithm, which uses a diagonal motion blur operator and a rotation matrix to achieve motion blur at any angle, and the degree of blur can be controlled by parameters. The method is as follows.

[0194] (1), first create an N*N diagonal matrix, where N represents the sampling range of motion blur.

[0195] (2) Then, the rotation angle angle of the motion process is randomly initialized, where the value of angle is randomly selected between [1, 360].

[0196] (3) Based on the rotation angle angle, calculate the rotation matrix M.

[0197] (4) The rotation matrix M is applied to the diagonal blur operator created in (1) to calculate the overall blur operator.

[0198] (5) Applying the motion blur operator obtained in (4) to the entire image can achieve a better motion blur effect.

[0199] like Fig. 9 The following is a schematic diagram of motion blur.

[0200] Next, the overall image rendering process in the embodiment of the present disclosure is described by using a specific example. Fig.10 As shown, the following steps are included.

[0201] Step 100: adaptive illumination adjustment of the foreground image.

[0202] Step 101, merging the text foreground image and the background image.

[0203] Step 102, determine whether to synthesize interference lines; if the judgment result is yes, execute step 103; if the judgment result is no, execute step 104.

[0204] Step 103, synthesizing random interference lines.

[0205] Step 104, determine whether to synthesize table lines. If the determination result is yes, execute step 105; if the determination result is no, execute step 106.

[0206] Step 105, synthesize the table lines.

[0207] Step 106, determine whether to perform Gaussian blur. If the determination result is yes, execute step 107; if the determination result is no, execute step 108.

[0208] Step 107: Gaussian blur.

[0209] Step 108, determine whether to perform motion blur. If the determination result is yes, execute step 109; if the determination result is no, execute step 110.

[0210] Step 109, motion blur.

[0211] Step 110: output the final image.

[0212] The text image generation method in the educational scenario proposed in the above embodiment mainly includes three parts: foreground synthesis module, background synthesis module and overall image rendering module. Using the text image generation algorithm proposed in the embodiment of the present disclosure, it is possible to synthesize text line images close to the educational scenario based on the existing educational scenario corpus, thereby providing sufficient labeled text line image data for subsequent text recognition model training. Figure 11A-11C As shown, they are schematic diagrams of foreground rendering mode, background rendering mode and synthetic image.

[0213] One or more technical solutions in the embodiments of the present disclosure have at least the following technical effects or advantages:

[0214] In the disclosed embodiment, a realistic text image synthesis effect is achieved by separately designing the text foreground image and the background image, rendering the text foreground image and the background image respectively, and then further rendering the combined overall image.

[0215] The text image synthesis method proposed in the embodiment of the present disclosure can synthesize text images with content labels on a large scale, solving the problem of lack of text image data sets for text recognition training in educational scenarios.

[0216] In the disclosed embodiment, text images can be quickly synthesized on a large scale based on set parameters, and the text content labels correspond to the synthesized images one by one without errors. Compared with manual labeling, it saves time and effort, and the accuracy of the content is guaranteed.

[0217] The synthesized text image in the disclosed embodiment is based on a pre-designed educational scene corpus, so word frequency equalization can be performed in the corpus preparation stage, and the word frequency of the final synthesized text image data set is relatively balanced. However, the word frequency of the text content in the public data set varies greatly, which is not conducive to subsequent text recognition training.

[0218] In the disclosed embodiment, an efficient and accurate text image synthesis method is designed for educational scenarios, which can simulate the text form in educational scenarios. Therefore, compared with public data sets or scanned document data, it is closer to real educational scenarios.

[0219] Based on the same inventive concept, Fig.12 As shown, the embodiment of the present disclosure also discloses a text image generation device 1200 for text recognition model training, including: a foreground synthesis module 1201, used to obtain a text sequence of a predetermined length from a corpus; adjust the text sequence based on pre-set parameters to synthesize an original text foreground image; perform foreground rendering on the original text foreground image according to a foreground rendering strategy to generate a text foreground image; a background synthesis module 1202, used to obtain a background image, merge the text foreground image and the background image to generate a merged image; an overall image rendering module 1203, used to perform overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image, and use the text sequence as a content label of the final text image.

[0220] Regarding the device in the above embodiment, the specific manner in which each module performs operations has been described in detail in the embodiment of the method, and will not be elaborated here.

[0221] Fig.13 FIG. 1 is a block diagram of an electronic device 1300 according to an exemplary embodiment. Fig.13 As shown, the electronic device 1300 may include: a processor 1301 and a memory 1302. The electronic device 1300 may also include one or more of a multimedia component 1303, an input / output (I / O) interface 1304, and a communication component 1305.

[0222] The processor 1301 is used to control the overall operation of the electronic device 1300 to complete all or part of the steps in the above-mentioned text image generation method. The memory 1302 is used to store various types of data to support the operation of the electronic device 1300, and these data may include, for example, instructions for any application or method used to operate on the electronic device 1300, and application-related data, such as contact data, sent and received messages, pictures, audio, video, etc. The memory 1302 can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (Static Random Access Memory, referred to as SRAM), electrically erasable programmable read-only memory (Electrically Erasable Programmable Read-Only Memory, referred to as EEPROM), erasable programmable read-only memory (Erasable Programmable Read-Only Memory, referred to as EPROM), programmable read-only memory (Programmable Read-Only Memory, referred to as PROM), read-only memory (Read-Only Memory, referred to as ROM), magnetic memory, flash memory, magnetic disk or optical disk. The multimedia component 1303 may include a screen and an audio component. The screen may be, for example, a touch screen, and the audio component is used to output and / or input audio signals. For example, the audio component may include a microphone for receiving external audio signals. The received audio signal may be further stored in the memory 1302 or sent through the communication component 1305. The audio component also includes at least one speaker for outputting audio signals. The I / O interface 1304 provides an interface between the processor 1301 and other interface modules, and the above-mentioned other interface modules may be keyboards, mice, buttons, etc. These buttons may be virtual buttons or physical buttons. The communication component 1305 is used for wired or wireless communication between the electronic device 1300 and other devices. Wireless communication, such as Wi-Fi, Bluetooth, Near Field Communication (NFC), 2G, 3G, 4G, NB-IOT, eMTC, or other 5G, etc., or a combination of one or more of them, is not limited here. Therefore, the corresponding communication component 1305 may include: Wi-Fi module, Bluetooth module, NFC module, etc.

[0223] In an exemplary embodiment, the electronic device 1300 can be implemented by one or more application specific integrated circuits (ASIC), digital signal processors (DSP), digital signal processing devices (DSPD), programmable logic devices (PLD), field programmable gate arrays (FPGA), controllers, microcontrollers, microprocessors or other electronic components to execute the above-mentioned text image generation method.

[0224] In another exemplary embodiment, a computer-readable storage medium including program instructions is also provided, and when the program instructions are executed by a processor, the steps of the above-mentioned text image generation method are implemented. For example, the computer-readable storage medium can be the above-mentioned memory 1302 including program instructions, and the above-mentioned program instructions can be executed by the processor 1301 of the electronic device 1300 to complete the above-mentioned text image generation method.

[0225] In another exemplary embodiment, a computer program product is further provided. The computer program product includes a computer program that can be executed by a programmable device. The computer program has a code portion for executing the above-mentioned text image generation method when executed by the programmable device.

[0226] The preferred embodiments of the present disclosure are described in detail above in conjunction with the accompanying drawings; however, the present disclosure is not limited to the specific details in the above embodiments. Within the technical concept of the present disclosure, a variety of simple modifications can be made to the technical solution of the present disclosure, and these simple modifications all fall within the protection scope of the present disclosure.

[0227] It should also be noted that the various specific technical features described in the above specific embodiments can be combined in any suitable manner without contradiction. In order to avoid unnecessary repetition, the present disclosure will not further describe various possible combinations.

[0228] In addition, various embodiments of the present disclosure may be arbitrarily combined, and as long as they do not violate the concept of the present disclosure, they should also be regarded as the contents disclosed by the present disclosure.

Claims

1. A text image generation method for text recognition model training, characterized in that: The method comprises: Obtain a text sequence of predetermined length from the corpus; The text sequence is adjusted based on preset parameters to synthesize an original text foreground image; According to the foreground rendering strategy, the original text foreground image is subjected to foreground rendering to generate a text foreground image; Acquire a background image, merge the text foreground image and the background image to generate a merged image; Performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image, and using the text sequence as a content label of the final text image; The text sequence is adjusted based on preset parameters to synthesize the original text foreground image, including: Initializing the text style of the text to be synthesized in the text sequence, wherein the text style includes one or more combinations of font type, font size, font color, spacing between characters, and actual pixel width of text spaces; Calculating the width, height and distance between characters of each character in the text sequence to obtain the position of each character in the text sequence in the original text foreground image to be synthesized; Calculating the original pixel size of the original text foreground image to be synthesized based on the position of each character in the original text foreground image to be synthesized; Initialize an image according to the original pixel size; wherein the size of the initialized image is equal to the original pixel size; or, the width of the initialized image is equal to the width of the original pixel size, and the height of the initialized image is greater than the height of the original pixel size; According to the position of each character in the original text foreground image to be synthesized, each character is drawn on the initialization image to synthesize the original text foreground image.

2. The method according to claim 1, characterized in that When the width of the initialization image is equal to the width of the original pixel size and the height of the initialization image is greater than the height of the original pixel size, performing foreground rendering on the original text foreground image according to the foreground rendering strategy to generate a text foreground image, including: According to the original text foreground image, determining whether it is necessary to draw a character mark under the character in the original text foreground image according to a random probability value; If it is determined to be necessary, the drawing width and the starting position of the character mark are selected according to a preset synthesis mode, and the ending position is calculated according to the drawing width and the starting position; The character mark is drawn with the bottom of the character at the starting position as the starting point and the bottom of the character at the ending position as the end point to generate the text foreground image; wherein the character mark is an underline or an emphasis mark; and the pre-set synthesis mode is a fixed character synthesis mode, a random character synthesis mode and a full character synthesis mode.

3. The method according to claim 1, characterized in that According to the foreground rendering strategy, the original text foreground image is subjected to foreground rendering to generate a text foreground image, including: Calculating a binary image of the original text foreground image; According to the preset filtering template and filtering rules, the original text foreground image is filtered in a left-to-right and top-to-bottom order to generate the filtered text foreground image; Among them, the number of vertical pixel points of the filter template is greater than the number of horizontal pixel points of the filter template; the filtering rule refers to selecting the minimum pixel value in the overlapping area between the filter template and the binary image as the pixel value of the center point of the current overlapping area in the binary image.

4. The method according to claim 1, characterized in that According to the foreground rendering strategy, the original text foreground image is subjected to foreground rendering to generate a text foreground image, including: Based on the target direction distortion formula, the target direction offset of the one-dimensional position vector of the original text foreground image in the orthogonal direction under the target direction distortion formula is calculated, and the target direction offset is recorded; wherein, when the target direction is a vertical direction, the orthogonal direction is a horizontal direction; when the target direction is a horizontal direction, the orthogonal direction is a vertical direction; Calculating the maximum range of the overall relative offset according to the target direction offset; According to the original pixel size of the text image to be synthesized and the maximum range of the overall relative offset; Creating a new foreground image, and calculating the size of the newly created foreground image according to the size of the original text foreground image and the maximum range of the overall relative offset; The image vector on each one-dimensional position vector in the original text foreground image is reconstructed on the newly created foreground image according to the target direction offset corresponding to each one-dimensional position vector to generate the text foreground image.

5. The method according to claim 4, characterized in that The vertical distortion formula is any of the following; Among them, F v_sin represents the sinusoidal twist formula, F v_cos represents the cosine curve twist formula, F v_rsin represents the inverse sine curve twist formula, F v_rcos Represents the arccosine curve distortion formula; x is the horizontal axis coordinate, from [0, W f -1], W f is the width of the original text foreground image, ratio is the frequency adjustment parameter of sine and cosine, K is the amplitude adjustment parameter of sine and cosine, H f is the height of the original text foreground image; The horizontal distortion formula is Where x is the vertical axis coordinate, from [0, H f -1], H f is the height of the original text foreground image, D char is the average character width, and ratio is the translation factor.

6. The method according to claim 1, characterized in that According to the foreground rendering strategy, the original text foreground image is subjected to foreground rendering to generate a text foreground image, including: Calculating the position mapping relationship between the rotated pixel points and the pixel points of the original text foreground image according to a preset rotation matrix; The text foreground image is generated based on the original text foreground image and the position mapping relationship.

7. The method according to claim 6, characterized in that The rotation matrix is Among them, k represents the scaling factor, θ represents the rotation angle, and x and y represent the rotation center.

8. The method according to any one of claims 1 to 7, characterized in that The background image is a real paper background image; the method further comprises: Calculating a normalized distribution matrix of the real paper background image so that the pixel values ​​of the real paper background image are between 0 and 1; Multiplying the normalized distribution matrix by pixels in the text foreground image pixel by pixel to obtain a text foreground image after adaptive brightness adjustment; The text foreground image after the brightness adaptive adjustment is combined with the real paper background image to obtain a text image after the brightness adaptive adjustment.

9. The method according to any one of claims 1 to 7, characterized in that Performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes: Calculating the size of the merged image; Based on the size of the merged image, calculate the starting position and the ending position of the table lines in the four directions of up, down, left, and right of the merged image; The remaining state of the table lines in the four directions is randomly determined; if they are retained, line segments are drawn on the merged image according to the starting position and the end position of the corresponding table lines to obtain the final text image.

10. The method according to claim 9, characterized in that The size of the merged image is W*H. Based on the size of the merged image, the starting position and the ending position of the table lines in the four directions of up, down, left, and right of the merged image are calculated, including: Calculate the starting position of the table line above the merged image as (0, h top ), the end point is (W-1,h top ); Calculate the starting position of the table line below the merged image as (0, h bottom ), the end point is (W-1,h bottom ); Calculate the starting position of the table line on the left side of the merged image as (w left ,0), the end point is (w left ,H-1); Calculate the starting position of the table line on the right side of the merged image as (w right ,0), the end point is (w right ,H-1); Among them, h top 、h bottom 、w left and w right These are preset values.

11. The method according to any one of claims 1 to 7, characterized in that Performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes: Select the number of random interference lines; For each interference line, randomly set the starting position and the ending position of each interference line within the two-dimensional range of the merged image; According to the starting point position and the end point position of each interference line and the interference line style in the preset image library, a line segment is drawn on the merged image to obtain the final text image.

12. The method according to any one of claims 1 to 7, characterized in that Performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes: Create an N*N diagonal matrix; where N represents the sampling range of motion blur; Randomly initialize the rotation angle of the motion process, and calculate the rotation matrix based on the rotation angle; Calculating an overall fuzzy operator based on the diagonal fuzzy operator created by the rotation matrix; According to the overall motion blur operator, motion blur processing is performed on the merged image to obtain the final text image.

13. The method according to any one of claims 1 to 7, characterized in that Performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image includes: The combined image is rendered as a whole using a Gaussian blur algorithm to obtain the final text image.

14. The method according to claim 1, wherein: The background image is a real paper background image, a scanned background image or a Gaussian noise background image.

15. A text image generation device for character recognition model training, characterized in that: include: A foreground synthesis module is used to obtain a text sequence of a predetermined length from a corpus; The text sequence is adjusted based on preset parameters to synthesize an original text foreground image; According to the foreground rendering strategy, the original text foreground image is subjected to foreground rendering to generate a text foreground image; A background synthesis module, used to obtain a background image, merge the text foreground image and the background image, and generate a merged image; An overall image rendering module, used for performing overall image rendering on the merged image according to an overall image rendering strategy to obtain a final text image, and using the text sequence as a content label of the final text image; The foreground synthesis module is used for: Initializing the text style of the text to be synthesized in the text sequence, wherein the text style includes one or more combinations of font type, font size, font color, spacing between characters, and actual pixel width of text spaces; Calculating the width, height and distance between characters of each character in the text sequence to obtain the position of each character in the text sequence in the original text foreground image to be synthesized; Calculating the original pixel size of the original text foreground image to be synthesized based on the position of each character in the original text foreground image to be synthesized; Initialize an image according to the original pixel size; wherein the size of the initialized image is equal to the original pixel size; or, the width of the initialized image is equal to the width of the original pixel size, and the height of the initialized image is greater than the height of the original pixel size; According to the position of each character in the original text foreground image to be synthesized, each character is drawn on the initialization image to synthesize the original text foreground image.

16. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the method described in any one of claims 1 to 14 are implemented.

17. An electronic device, characterized in that: include: a memory having a computer program stored thereon; A processor, configured to execute the computer program in the memory to implement the steps of the method according to any one of claims 1 to 14.