Text image generation method and device
By identifying target characters from handwritten text images and generating and fusing them with images of misspelled characters, the problem of high cost in obtaining misspelled character images is solved, enabling the low-cost generation of a large number of misspelled character images and improving the development and accuracy of misspelled character recognition technology.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-18
- Publication Date
- 2026-04-07
AI Technical Summary
The high cost of acquiring text images containing misspellings has limited the development of misspelling recognition technology.
By identifying the target character to be replaced from the first handwritten text image, generating the corresponding handwritten misspelling image, and merging it with the original image, a text image containing the misspelling is automatically generated.
It reduced the cost of acquiring text images containing misspellings, expanded the number of misspelling images, and promoted the development of misspelling recognition technology and the accuracy of the model.
Smart Images

Figure CN116597463B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present disclosure relates to the field of artificial intelligence, and in particular, to a method and apparatus for generating a text image. BACKGROUND
[0002] In scenarios such as intelligent correction, a neural network model can automatically identify a wrong word in a user's homework or test paper, and further correct the wrong word. Before this, the model needs to be trained using a text image containing a wrong word, so that the trained model can detect or recognize the wrong word from the text image. However, in the related art, the cost of obtaining a text image containing a wrong word is high, such as the need to screen text containing a wrong word from a large amount of writing content, which requires meticulous and tedious work. The use of artificial handwriting of wrong words to obtain text containing wrong words is uncontrollable and also requires a great amount of manual cost. In summary, in the related art, the way of obtaining a text image containing a wrong word is costly, resulting in a scarcity of text images containing wrong words, and the scarcity of text images containing wrong words has become a major reason restricting the development of wrong word recognition technology. SUMMARY
[0003] To solve the above technical problems or at least partially solve the above technical problems, the present disclosure provides a method and apparatus for generating a text image, a device, and a medium.
[0004] According to an aspect of the present disclosure, a method for generating a text image is provided, including: obtaining a first handwritten text image; wherein the first handwritten text image contains a plurality of handwritten correct words; determining a current target word to be replaced from the plurality of handwritten correct words, and obtaining information of the current target word; generating a handwritten wrong word image corresponding to the current target word according to the information of the current target word; wherein the word in the handwritten wrong word image is an error word obtained based on the current target word; and fusing the handwritten wrong word image and the first handwritten text image to obtain a second handwritten text image; wherein the second handwritten text image is a text image in which the current target word is replaced by the error word.
[0005] According to another aspect of this disclosure, a text image generation apparatus is provided, comprising: a first image acquisition module for acquiring a first handwritten text image; wherein the first handwritten text image contains a plurality of correctly handwritten characters; a target character information acquisition module for determining a current target character to be replaced from the plurality of correctly handwritten characters and acquiring information about the current target character; a misspelling image acquisition module for generating a handwritten misspelling image corresponding to the current target character based on the information about the current target character; wherein the characters in the handwritten misspelling image are misspellings obtained based on the current target character; and a second image acquisition module for fusing the handwritten misspelling image with the first handwritten text image to obtain a second handwritten text image; wherein the second handwritten text image is a text image in which the current target character is replaced with the misspelling.
[0006] According to another aspect of this disclosure, an electronic device is provided, comprising: a processor; and a memory storing a program, wherein the program includes instructions that, when executed by the processor, cause the processor to perform the text image generation method.
[0007] According to another aspect of this disclosure, a computer-readable storage medium is provided, wherein the storage medium stores a computer program for performing the text image generation method described above.
[0008] The technical solution provided in this embodiment can determine the current target character to be replaced from multiple correctly handwritten characters contained in a first handwritten text image, generate a handwritten error image corresponding to the current target character based on the information obtained from the current target character, and finally fuse the handwritten error image with the first handwritten text image to obtain a second handwritten text image in which the current target character is replaced with the error character. Through this method, text images containing errors can be automatically generated conveniently and quickly, greatly reducing the cost of acquiring text images containing errors.
[0009] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of this disclosure, nor is it intended to limit the scope of this disclosure. Other features of this disclosure will become readily apparent from the following description. Attached Figure Description
[0010] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments of the present disclosure and, together with the description, serve to explain the principles of the disclosure.
[0011] To more clearly illustrate the technical solutions in the embodiments of this disclosure or the prior art, the accompanying drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0012] Figure 1 A flowchart illustrating a method for generating a text image provided in this embodiment of the disclosure;
[0013] Figure 2 A schematic diagram of a first handwritten text image provided in an embodiment of this disclosure;
[0014] Figure 3 A schematic diagram of a detection frame provided in an embodiment of this disclosure;
[0015] Figure 4 A schematic diagram of a handwritten misspelling image provided in an embodiment of this disclosure;
[0016] Figure 5 A schematic diagram of a second handwritten text image provided in an embodiment of this disclosure;
[0017] Figure 6 This is a schematic diagram of image conversion provided in an embodiment of the present disclosure;
[0018] Figure 7 A schematic diagram of a printed misspelling image provided in an embodiment of this disclosure;
[0019] Figure 8 A schematic diagram of the structure of a text image generation apparatus provided in an embodiment of this disclosure;
[0020] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this disclosure. Detailed Implementation
[0021] Embodiments of this disclosure will now be described in more detail with reference to the accompanying drawings. While some embodiments of this disclosure are shown in the drawings, it should be understood that this disclosure can be implemented in various forms and should not be construed as limited to the embodiments set forth herein. Rather, these embodiments are provided to provide a more thorough and complete understanding of this disclosure. It should be understood that the accompanying drawings and embodiments of this disclosure are for illustrative purposes only and are not intended to limit the scope of protection of this disclosure.
[0022] It should be understood that the steps described in the method embodiments of this disclosure may be performed in different orders and / or in parallel. Furthermore, the method embodiments may include additional steps and / or omit the steps shown. The scope of this disclosure is not limited in this respect.
[0023] As used in this disclosure, the term "comprising" and its variations are open-ended, that is, "including but not limited to". The term "based on" means "at least partially based on". The term "one embodiment" means "at least one embodiment"; the term "another embodiment" means "at least one additional embodiment"; the term "some embodiments" means "at least some embodiments". The relevant definitions of other terms will be given in the following description. It should be noted that the concepts such as "first", "second", etc. mentioned in this disclosure are only used to distinguish different devices, modules or units, and are not used to limit the order or interdependence of the functions performed by these devices, modules or units.
[0024] It should be noted that the modification of "one" and "multiple" mentioned in this disclosure is illustrative rather than restrictive. Those skilled in the art should understand that unless otherwise clearly stated in the context, it should be understood as "one or more".
[0025] In order to more clearly understand the above-mentioned objects, features and advantages of this disclosure, the solutions of this disclosure will be further described below. It should be noted that, without conflict, the embodiments of this disclosure and the features in the embodiments can be combined with each other.
[0026] Figure 1 The flowchart of a method for generating a text image provided for an embodiment of this disclosure. This method can be executed by a text image generation device, where the device can be implemented by software and / or hardware and is generally integrated in an electronic device. As Figure 1 shown, this method mainly includes the following steps S102 to step S108:
[0027] Step S102, obtain a first handwritten text image; wherein, the first handwritten text image contains multiple correctly handwritten characters. In other words, the correctly written characters are in handwritten form, and the first handwritten text image contains multiple correctly written handwritten single characters. In practical applications, multiple correctly handwritten characters can be arranged in a specified direction such as the horizontal direction. That is, the first handwritten text image can be a text line image. Specifically, the first handwritten text image can contain only one text line or multiple text lines, which is not limited here. For easy understanding, reference can be made to Figure 2 a schematic diagram of a first handwritten text image shown, which shows a text line composed of multiple correctly handwritten characters "Love and Technology Help with Lifelong Growth", and each Chinese character can be regarded as a character. In addition, the characters mentioned in the embodiments of this disclosure are not limited to Chinese characters, and can also be characters in other languages such as Japanese and Korean, which is not limited here.
[0028] Step S104, determine the current target character to be replaced from multiple correctly handwritten characters, and obtain the information of the current target character.
[0029] In practical applications, the current target character to be replaced can be determined according to requirements. For example, one or more characters can be randomly selected as the current target character, or the current target character to be replaced can be determined based on historical target characters selected from multiple correctly handwritten characters. For example, the current target character can be different from the historical target characters. That is, before determining the current target character, the target characters to be replaced (which can be called historical target characters) may have been selected from multiple correctly handwritten characters in the first handwritten text image, and a handwritten text image (which can be called historical handwritten text image) has been generated to replace the historical target characters with the corresponding incorrect characters. In other words, in order to make full use of the first handwritten text image, different characters can be selected from multiple correct characters in the first handwritten text image as the target characters for each selection and corresponding handwritten text images can be generated. Therefore, when determining the current target character, the previously selected historical target characters can be referenced so that multiple handwritten text images containing different incorrect characters can be generated based on the same first handwritten text image, which can improve the utilization rate of the first handwritten text image.
[0030] This disclosure does not limit the information of the current target character; any necessary information related to the current target character can be used. For example, the information of the current target character includes: the pixel value of the current target character, the background pixel value of the detection box region corresponding to the current target character, and the size information of the detection box region. Furthermore, the information of the current target character also includes the position of the detection box region corresponding to the current target character, the sequence number of the current target character among multiple correctly handwritten characters, etc., which are not limited here. Specifically, a single-character detection algorithm can first be used to detect the position of all characters in the first handwritten text image and mark them with detection boxes (also called character frames). For ease of understanding, please refer to... Figure 3A schematic diagram of a detection box is shown, indicating the detection box corresponding to each character. Additionally, in practical applications, each character can be sorted based on the position of the key points (such as the center point) of the detection box. Taking the case where multiple characters form a horizontal row as an example, the serial number of each detection box can be determined in ascending order of the abscissa of the key points, thereby obtaining the serial number of the correct character corresponding to the detection box. Furthermore, the position of the detection box area in the first handwritten text image can be determined based on information such as the position of the key points and the size of the detection box. It can be understood that the same character may appear among multiple handwritten correct characters. For example, in the text line "The sky is very blue today", two "天" (sky) characters will appear simultaneously. These two "天" characters can be regarded as different characters and correspond to different serial numbers. Suppose the first "天" character has been selected as the historical target character previously, and the second "天" character can still be selected as the current target character subsequently. The main reason is that although the two "天" characters are the same, their positions in the text line are different, and multiple handwritten text images with misspelled characters in different positions can still be generated. Identifying the correct characters with serial numbers helps to distinguish the correct characters, facilitates the subsequent selection of the correct characters to be processed from the first handwritten text image, and can effectively avoid confusing the same characters during the selection process. The above is only an example. In practical applications, serial numbers may not be used, and the correct characters in the first handwritten text image can be directly distinguished and selected based on the positions of the detection boxes corresponding to each correct character in the first handwritten text image. No restrictions are imposed here.
[0031] Step S106: Generate a handwritten misspelled character image corresponding to the current target character according to the information of the current target character; wherein, the character in the handwritten misspelled character image is a misspelled character obtained based on the current target character. In practical applications, the above-mentioned handwritten misspelled character image can also be referred to as a handwritten misspelled character image. The misspelled characters included in the handwritten misspelled character image can be handwritten misspelled characters generated by an electronic device according to a preset method. Additionally, if the number of selected current target characters is multiple, each current target character can respectively correspond to a handwritten misspelled character image, and only one handwritten misspelled character corresponding to the current target character is included in the handwritten misspelled character image.
[0032] In some specific implementation examples, the character in the handwritten misspelled character image is the misspelled character obtained by performing an erasure operation on the target stroke in the current target character. The embodiments of the present disclosure do not limit the erasure method, and any method capable of erasing the target stroke can be used. For example, a method of erasing strokes based on computer vision algorithms or a method of erasing strokes using image processing tools (such as Photoshop) can be used. In practical applications, the target stroke to be erased can be determined according to requirements. Specifically, the target stroke can be determined based on the number of target strokes to be erased. In some implementation examples, when the number of target strokes is one, the target stroke is any stroke in the current target character. In other implementation examples, when the total number of strokes of the current target character is not less than a preset threshold and the number of target strokes is greater than one, the multiple target strokes do not form the radical of the current target character, thereby effectively increasing the success probability of finally obtaining the misspelled character. By performing an erasure operation on the target stroke in the current target character, the current target character can be conveniently and quickly converted into the corresponding misspelled character. For ease of understanding, reference can be made to Figure 4 A schematic diagram of a handwritten misspelled character image shown, showing the handwritten misspelled character image of "技" corresponding to the erasure of the third stroke. In practical applications, the number of current target characters can be one or more, and each current target character can generate a corresponding handwritten misspelled character image. That is, each handwritten misspelled character image can be a handwritten image containing only one misspelled single character.
[0033] Step S108, fuse the handwritten misspelled character image with the first handwritten text image to obtain a second handwritten text image; wherein, the second handwritten text image is a text image in which the current target character is replaced with a misspelled character.
[0034] For ease of understanding, reference can be made to Figure 5 A schematic diagram of a second handwritten text image shown, showing Figure 2 The first handwritten text image shown is fused with Figure 4 The handwritten misspelled character image shown to obtain a second handwritten text image containing a misspelled character. For ease of viewing, reference can also be made to Figure 6 An image conversion schematic diagram shown, mainly showing the effect of converting the first handwritten text image into the second handwritten text image. In Figure 6 The current target character "技" contained in the first handwritten text image and the misspelled character corresponding to "技" (that is, the misspelled character obtained by erasing the third stroke) contained in the finally generated second handwritten text image are clearly marked in the form of circles.
[0035] Through the above method, a text image containing misspelled characters can be conveniently and quickly automatically generated based on a text image containing correct characters, greatly reducing the acquisition cost of the text image containing misspelled characters.
[0036] An embodiment of the present disclosure provides an implementation example of the above step S104. Specifically, the steps of determining the current target word to be replaced from multiple handwritten correct words can be performed according to the following steps (1) and (2):
[0037] Step (1), obtain the application scenario type corresponding to the second handwritten text image, and the correct words that have been selected as historical target words among the multiple handwritten correct words.
[0038] Exemplarily, the application scenario type can be determined based on the type of the model that needs to be trained with the second handwritten text image. For example, the application scenario corresponding to the misspelling detection model is the misspelling detection scenario, and the application scenario corresponding to the misspelling recognition model is the misspelling recognition scenario. Further, the misspelling recognition model can include a model that recognizes misspelled words as corresponding correct words (such as directly recognizing and correcting the character "技" missing the third stroke as the correct "技") or a model that recognizes misspelled words as preset special characters (such as directly recognizing the character "技" missing the third stroke as a special character such as "※"), corresponding to the scenario of recognizing misspelled words as preset special characters and the scenario of recognizing misspelled words as corresponding correct words respectively. The above is only an exemplary description of the application scenario, and there may be other application scenarios in actual applications, which are not limited here.
[0039] As mentioned above, the historical target word is the target word selected before the current target word, and a handwritten text image containing the misspelled word corresponding to the historical target word is generated. The information of the correct words that have been selected as historical target words among the multiple handwritten correct words helps to use it as a reference for selecting the current target word.
[0040] Step (2), determine the current target word to be replaced from the multiple handwritten correct words according to the application scenario type and the correct words that have been selected as historical target words. In this way, the current target word can be selected more reasonably and reliably, and the effectiveness and rationality of the second handwritten text image generated based on the current target word can be better ensured. For ease of understanding, two implementation examples of step (2) are given in the embodiments of the present disclosure, which can be specifically referred to as Example 1 and Example 2 below:
[0041] Example 1: In the case of application scenario type 1, from multiple correctly handwritten characters excluding those already selected as historical target characters, a first preset proportion of correct characters are selected as the current target characters to be replaced. That is, the ratio between the number of selected current target characters and the total number of multiple correctly handwritten characters is the first preset proportion, and the current target characters are selected from the correct characters excluding those already selected as historical target characters. This embodiment does not limit the method of selecting the current target character. To ensure the validity of the final generated second handwritten text image and thus guarantee the effect of model training based on the second handwritten text image, a random selection method can be used to select the current target character from the correct characters excluding those already selected as historical target characters.
[0042] In some specific implementation examples, the first type of application scenario includes error detection scenarios, or scenarios where error characters are identified as preset special characters. It is understood that in the first type of application scenario, the requirements for the capabilities of the model to be trained are not very high; the model only needs to be able to detect error characters from the text image or identify error characters as preset special characters. Therefore, a relatively high first preset quantity ratio can be set. For example, the first preset quantity ratio can be 25%. For instance, assuming there are 20 correct characters in the first handwritten text image, five characters are selected as the current target characters to be replaced with error characters in the first iteration, and a corresponding second handwritten text image is generated for model training. In the second iteration, five more characters can be selected from the remaining 15 characters as the current target characters to be replaced with error characters, and a corresponding second handwritten text image is generated for model training. This process continues, repeating up to four times until a preset condition is met. The preset condition could be, for example, that all correct characters in the first handwritten text image have been selected as target characters, or that the model has been trained and there is no need to generate handwritten text images containing error characters for model training. By setting a first preset quantity ratio (which can also be understood as the percentage of misspelled characters), the utilization rate of training data can be significantly improved, and the ratio of positive to negative samples can be balanced. Furthermore, in practical applications, if the number of characters to be selected based on the first preset quantity ratio is not an integer, then the closest integer number can be selected. For example, if there are 30 characters in total, and 30 * 25% = 7.2, then 7 characters can be selected from that.
[0043] Example 2: In the case where the application scenario type is the second type of application scenario, obtain the word segmentation results corresponding to multiple handwritten correct characters; based on the word segmentation results, select the correct characters with the second preset quantity ratio as the current target characters to be replaced from the other correct characters except the correct characters that have been selected as the historical target characters among the multiple handwritten correct characters. In practical applications, word segmentation tools such as Jieba can be used to perform word segmentation on the multiple handwritten correct characters in the first handwritten text image. For example, the word segmentation results corresponding to "Love and technology help lifelong growth" are: "Love", "and", "technology", "help", "lifelong", "growth". Then, based on the word segmentation results, the current target characters are selected to ensure the rationality of the selection of the current target characters, so that the second handwritten text image generated based on the current target characters can be better applied to the second type of application scenario.
[0044] In some specific implementation examples, the second type of application scenario includes the scenario of recognizing incorrect characters as corresponding correct characters. It can be understood that in the second type of application scenario, the requirements for the capabilities of the model to be trained are relatively high. The model needs to be able to detect incorrect characters from the text image and recognize them as the corresponding correct characters. Therefore, a relatively low second preset quantity ratio can be set. The second preset quantity ratio does not exceed the preset ratio threshold, such as not exceeding 10%. That is, in the second type of application scenario, at most 10% of the characters are selected as the current target characters, and it can be understood that the number of current target characters is not less than one. Taking the second preset quantity ratio of 10% as an example, for instance, assuming that there are a total of 20 correct characters in the first handwritten text image, 2 characters are selected as the current target characters to be replaced with incorrect characters for the first time, and the corresponding second handwritten text image is generated for model training. For the second time, 2 characters can be continuously selected from the remaining 18 characters as the current target characters to be replaced with incorrect characters, and the corresponding second handwritten text image is generated for model training. At this time, the current target characters selected for the first time are historical target characters for the second time, and so on, until the preset conditions are met and then it ends. The preset conditions can refer to the relevant content mentioned above and will not be elaborated here.
[0045] In some specific implementation examples, the embodiments of the present disclosure can set that at most one character in each word of the word segmentation results is selected as the current target character. For example, for "technology" in the word segmentation results, at most "science" or "technology" is selected as the current target character, and both "science" and "technology" cannot be used as the current target characters at the same time. The main reason is that when there are incorrect characters in the text image, the model still needs to recognize the incorrect characters as their corresponding correct characters. At this time, not only the glyph structure of the incorrect characters but also the semantic information of the context needs to be relied on for association. By setting the method of selecting at most one character in each word to be replaced with an incorrect character, it can effectively ensure that the second handwritten text image used for training the model can retain a certain degree of semantic information, thereby helping the model gradually establish robustness to incorrect characters.
[0046] Once the current target character is determined, its information can be further obtained. This embodiment provides an implementation method for obtaining the current target character information in step S104. When the current target character information includes the size information of the detection box region corresponding to the current target character, the width W and height H of the detection box can be directly obtained. When the current target character information includes the pixel values of the current target character and the background color pixel values of the detection box region corresponding to the current target character, it can be obtained according to either method one or method two:
[0047] Method 1: Cluster the pixel values of the detection box region corresponding to the current target character to obtain a first cluster and a second cluster. Based on the average pixel values of the first cluster (hereinafter referred to as the first average) and the average pixel values of the second cluster (hereinafter referred to as the second average), determine the pixel value of the current target character and the background pixel value of the detection box region corresponding to the current target character. Considering that the pixel values of characters in common text images are usually smaller than the background pixel values, in some specific examples, the larger of the first average and the second average can be used as the background pixel value of the detection box region corresponding to the current target character, and the smaller of the first average and the second average can be used as the pixel value of the current target character.
[0048] Method 2 involves binarizing the detection box region corresponding to the target character to obtain a binary image. The background pixel value of the detection box region corresponding to the current target character is determined based on the average pixel value within the blank area of the binary image (hereinafter referred to as the third average value), and the pixel value of the current target character is determined based on the average pixel value outside the blank area (hereinafter referred to as the fourth average value). Specifically, an adaptive threshold binarization algorithm from a computer vision library can be used to binarize the detection box region corresponding to the target character to obtain a binary image. The third average value can be used as the background pixel value, and the fourth average value can be used as the pixel value of the current target character.
[0049] In practical applications, if the text image is a grayscale image, either method one or method two described above can be used directly. If the text image is an RGB image, method one and method two can be used for each channel separately, which will not be elaborated further here. Using these methods, the pixel value of the current target character and the background pixel value of the detection box region corresponding to the current target character can be accurately and reliably determined.
[0050] Based on the information of the current target character, such as the pixel value of the current target character, the background pixel value of the detection box area corresponding to the current target character, and the size information of the detection box area, this embodiment provides an implementation example of step S106, that is, the step of generating a handwritten misspelling image corresponding to the current target character based on the information of the current target character. It can be executed with reference to the following steps A to C:
[0051] Step A: Determine the size of the handwritten misspelling image corresponding to the current target character based on the size information of the detection box region corresponding to the current target character. Specifically, the size of the detection box region corresponding to the current target character can be directly used as the size of the handwritten misspelling image corresponding to the current target character.
[0052] Step B involves determining the background pixel value of the handwritten misspelling image corresponding to the current target character based on the background pixel value of the detection box region corresponding to the current target character, and determining the pixel value of the misspelled character in the handwritten misspelling image based on the pixel value of the current target character.
[0053] In some implementations, the background pixel value of the handwritten misspelling image is the same as the background pixel value of the detection box region corresponding to the current target character, and the pixel value of the misspelled character in the handwritten misspelling image is the same as or different from the pixel value of the current target character. This disclosure provides a specific implementation example for determining the pixel value of the misspelled character in the handwritten misspelling image based on the pixel value of the current target character, which can be performed by referring to the following steps 1 to 2:
[0054] Step 1: Obtain the pixel values of erroneous characters in the pre-generated historical handwritten text image; wherein, the erroneous characters in the historical handwritten text image are obtained based on the historical target characters in the first handwritten text image.
[0055] Step 2: Determine the pixel values of the erroneous characters in the handwritten misspelling image based on the pixel values of the erroneous characters in the historical handwritten text images. The pixel values of the erroneous characters in the handwritten misspelling image differ from those in the historical handwritten text images. In practical applications, the pixel values of the multiple correctly handwritten characters contained in the first handwritten text image can all be identical, while the pixel values of the erroneous characters in the handwritten misspelling image generated for the selected target character can differ from the pixel values of the characters contained in the first handwritten text image itself. Through this method, image feature specialization can be achieved for erroneous characters, helping the model gradually establish its ability to detect and recognize misspelled characters.
[0056] Specifically, step 2 can be performed as follows: Steps 2.1 to 2.3:
[0057] Step 2.1: Obtain the first ratio of the pixel value of the erroneous character in the historical handwritten text image to the pixel value of the historical target character. If the historical handwritten text image has been acquired multiple times previously, the first ratio can be the first ratio between the pixel value of the erroneous character in the most recently acquired historical handwritten text image and the pixel value of its corresponding historical target character.
[0058] Step 2.2: Based on the first ratio, determine a second ratio between the pixel value of the erroneous character in the handwritten misspelling image and the pixel value of the current target character; wherein the second ratio is not less than the first ratio and is not greater than one. In practical applications, the difference between the second ratio and the first ratio can be preset, for example, setting the difference to 5%. Assuming the first ratio is 80%, the second ratio can be 85%, and subsequently, it can be gradually increased to 100% with the number of iterations. This helps the model gradually establish the ability to detect and recognize misspellings by leveraging the specificity of the image features of the erroneous characters.
[0059] Step 2.3: Determine the pixel value of the erroneous character in the handwritten misspelling image based on the second ratio and the pixel value of the current target character. Specifically, the product of the pixel value of the current target character and the second ratio can be used as the pixel value of the erroneous character in the handwritten misspelling image.
[0060] In practical applications, the above method can be used to determine the pixel value of the erroneous character in the handwritten misspelling image in all application scenarios. Alternatively, the pixel value of the current target character can be directly used as the pixel value of the erroneous character in the handwritten misspelling image in all application scenarios. In some application scenarios (such as the first type of application scenario mentioned above), the above method can be used to determine the pixel value of the erroneous character in the handwritten misspelling image, while in other application scenarios (such as the second type of application scenario mentioned above), the pixel value of the current target character can be directly used as the pixel value of the erroneous character in the handwritten misspelling image. The settings can be flexibly configured according to requirements and are not restricted here.
[0061] Step C involves generating a handwritten misspelling image based on the size of the misspelling image, the background pixel values of the misspelling image, and the pixel values of the misspelled character. In some specific implementation examples, step C can be performed as follows: Steps C1 to C3.
[0062] Step C1: Obtain the printed image of the misspelled character corresponding to the current target character. For easier understanding, please refer to... Figure 7A schematic diagram of a printed misspelled character image is shown, indicating the printed misspelled character image corresponding to the character "技" with the third stroke missing, and taking the printed style as bold as an example for illustration. In practical applications, the standard printed image corresponding to the current target character can be obtained first. Among them, the printed style includes various fonts, such as Song typeface, regular script, clerical script, boldface, etc. Exemplarily, the required font corresponding to the printed style can be selected from the specified national standard font according to the requirements. In the case of obtaining the standard printed image corresponding to the current target character, the stroke information of the target stroke to be erased in the standard printed image of the current target character can be obtained. This stroke information includes the pixel point information of the target stroke in the standard printed image. Specifically, the pixel point information includes the coordinate position of the pixel points of the target stroke in the standard printed image. The pixel points of the target stroke can be all the pixel points or multiple key pixel points of the target stroke, which are not restricted here. Then, an erasing operation is performed based on the stroke information of the target stroke to obtain the printed misspelled character image corresponding to the current target character.
[0063] Step C2: According to the target handwriting style corresponding to the first handwritten text image, perform style transfer processing on the printed misspelled character image to obtain an initial misspelled character image with the target handwriting style.
[0064] In practical applications, the handwriting styles of multiple handwritten correct characters in the first handwritten text image are unified, such as being written by the same person. In specific implementation, the style transfer processing can be performed on the printed misspelled character image through a preset generative adversarial network. The generative adversarial network can be, for example, CGAN (Conditional Generative Adversarial Nets, conditional generative adversarial network) or CycleGAN (Cycle Generative Adversarial Nets, cycle generative adversarial network), etc., which are not restricted here. Specifically, the generative adversarial network can be obtained through pre-training. For example, the initial network is trained using the standard printed image samples and the handwritten text image samples with a preset handwriting style until a generative adversarial network that can convert the printed image into a handwritten image is obtained. Through the pre-trained generative adversarial network, the printed misspelled character image can be converted into an initial misspelled character image with the target handwriting style.
[0065] Step C3: Based on the size of the handwritten misspelled character image, the background pixel value of the handwritten misspelled character image, and the pixel value of the misspelled character, convert the initial misspelled character image into the handwritten misspelled character image corresponding to the target character.
[0066] In practice, each pixel value in the initial misspelled character image can be set to the background pixel value and the pixel value of the misspelled character image. The size of the initial misspelled character image can then be adjusted based on the dimensions of the original misspelled character image to obtain a satisfactory handwritten misspelled character image. This handwritten misspelled character image can be referenced from... Figure 4 As shown.
[0067] Based on the premise that the information of the current target character also includes the position of the detection box region corresponding to the current target character, and that the size of the handwritten misspelling image is consistent with the size of the detection box region corresponding to the current target character, this embodiment provides an implementation example of step S108, which is the step of fusing the handwritten misspelling image with the first handwritten text image. Specifically, it can be performed as follows: According to the position of the detection box region corresponding to the current target character, the handwritten misspelling image covers the detection box region corresponding to the current target character in the first handwritten text image. That is, the pixel values on the handwritten misspelling image are replaced one by one with the pixel values of the detection box region corresponding to the current target character in the first handwritten text image according to their positions, thereby obtaining the second handwritten text image.
[0068] In practical applications, the number of first handwritten text images can be one or more. Each first handwritten text image can be used to generate multiple corresponding second handwritten text images using the text image generation method provided in this embodiment, and these images can be used to train models such as misspelling detection models and misspelling recognition models. To improve the robustness of the model, first handwritten text images from different people can be obtained, and these can be considered as different people having different handwriting styles. That is, first handwritten text images with multiple handwriting styles can be obtained, and the number of first handwritten text images corresponding to each handwriting style meets the preset quantity requirements. This not only helps to generate multiple second handwritten text images with the required quantity, but also allows the first handwritten text images to be used to train the style transfer model, ensuring the style transfer effect and thus ensuring the realism of the final second handwritten text image containing misspellings. In practice, it is not necessary to cover all handwriting styles. Practice shows that even with a limited number of handwriting styles in the training data, the style transfer model still has the ability to generalize to handwritten fonts with different writing styles. That is, it can still generate handwritten misspelling images with corresponding handwriting styles based on the target characters in the first handwritten text image, thereby ensuring the realism of the second handwritten text image obtained by fusing the handwritten misspelling image and the first handwritten text image.
[0069] In summary, the text image generation method provided in this embodiment of the present disclosure does not require the high cost of obtaining text images containing misspellings through manual labor. Instead, it can automatically generate a large number of text images containing misspellings at low cost. This method is not only convenient and fast, but also greatly expands the number of text images containing misspellings, improving the problem of the scarcity of text images containing misspellings in the prior art. It can also further promote the development of misspelling recognition technology and improve the accuracy of network models in identifying misspellings in text images.
[0070] Corresponding to the aforementioned method for generating text images, this disclosure also provides an apparatus for generating text images. Figure 8 This is a schematic diagram of a text image generation device provided in an embodiment of the present disclosure. The device can be implemented by software and / or hardware and is generally integrated into an electronic device. Figure 8 As shown, the text image generation apparatus 800 includes:
[0071] The first image acquisition module 802 is used to acquire a first handwritten text image; wherein, the first handwritten text image contains multiple correctly handwritten characters;
[0072] The target character information acquisition module 804 is used to determine the current target character to be replaced from multiple correctly handwritten characters and to acquire the information of the current target character;
[0073] The misspelling image acquisition module 806 is used to generate a handwritten misspelling image corresponding to the current target character based on the information of the current target character; wherein, the characters in the handwritten misspelling image are misspellings obtained based on the current target character;
[0074] The second image acquisition module 808 is used to fuse the handwritten misspelling image with the first handwritten text image to obtain a second handwritten text image; wherein, the second handwritten text image is a text image in which the current target character is replaced with the misspelling character.
[0075] The aforementioned device can conveniently and quickly generate text images containing typos automatically, greatly reducing the cost of obtaining such text images.
[0076] In some implementations, the target character information acquisition module 804 is specifically used to: acquire the application scenario type corresponding to the second handwritten text image, and the correct characters that have been selected as historical target characters from the plurality of handwritten correct characters; and determine the current target character to be replaced from the plurality of handwritten correct characters based on the application scenario type and the correct characters that have been selected as historical target characters.
[0077] In some implementations, the target character information acquisition module 804 is specifically used to: when the application scenario type is the first type of application scenario, select a first preset number of correct characters from the correct characters other than the correct characters that have been selected as historical target characters as the current target characters to be replaced.
[0078] In some implementations, the first type of application scenario includes error word detection scenarios, or scenarios where error words are identified as preset special characters.
[0079] In some implementations, the target character information acquisition module 804 is specifically used to: when the application scenario type is the second type of application scenario, acquire the word segmentation results corresponding to the multiple handwritten correct characters; based on the word segmentation results, select a second preset number of correct characters from the multiple handwritten correct characters, excluding the correct characters that have been selected as historical target characters, as the current target characters to be replaced.
[0080] In some implementations, at most one character from each word segmentation result is selected as the current target character.
[0081] In some implementations, the second type of application scenario includes scenarios where incorrect characters are identified as corresponding correct characters.
[0082] In some implementations, the information of the current target character includes: the pixel value of the current target character, the background color pixel value of the detection box area corresponding to the current target character, and the size information of the detection box area.
[0083] In some embodiments, the misspelled character image acquisition module 806 is specifically used to: determine the size of the handwritten misspelled character image corresponding to the current target character based on the size information of the detection box region corresponding to the current target character; determine the background pixel value of the handwritten misspelled character image corresponding to the current target character based on the background pixel value of the detection box region corresponding to the current target character; and determine the pixel value of the erroneous character in the handwritten misspelled character image based on the pixel value of the current target character; and generate the handwritten misspelled character image corresponding to the current target character based on the size of the handwritten misspelled character image, the background pixel value of the handwritten misspelled character image, and the pixel value of the erroneous character.
[0084] In some implementations, the background pixel value of the handwritten misspelling image is the same as the background pixel value of the detection box area corresponding to the current target character, and the pixel value of the misspelled character in the handwritten misspelling image is the same as or different from the pixel value of the current target character.
[0085] In some embodiments, the misspelling image acquisition module 806 is specifically used to: acquire the pixel values of misspelled characters in a pre-generated historical handwritten text image; wherein the misspelled characters in the historical handwritten text image are misspelled characters obtained based on historical target characters in the first handwritten text image; determine the pixel values of misspelled characters in the handwritten misspelling image based on the pixel values of misspelled characters in the historical handwritten text image; wherein the pixel values of misspelled characters in the handwritten misspelling image are different from the pixel values of misspelled characters in the historical handwritten text image.
[0086] In some embodiments, the misspelled word image acquisition module 806 is specifically used to: acquire a first ratio of the pixel value of the misspelled word in the historical handwritten text image to the pixel value of the historical target word; determine a second ratio of the pixel value of the misspelled word in the handwritten misspelled word image to the pixel value of the current target word based on the first ratio; wherein the second ratio is not less than the first ratio and the second ratio is not greater than one; and determine the pixel value of the misspelled word in the handwritten misspelled word image based on the second ratio and the pixel value of the current target word.
[0087] In some implementations, the pixel values of the target character and the background pixel values of the detection box region corresponding to the target character are obtained as follows: the pixel values of the detection box region corresponding to the target character are clustered to obtain a first cluster and a second cluster; the pixel values of the target character and the background pixel values of the detection box region corresponding to the target character are determined based on the average value of the pixel values corresponding to the first cluster and the average value of the pixel values corresponding to the second cluster.
[0088] In some implementations, the pixel value of the target character and the background pixel value of the detection box region corresponding to the target character are obtained as follows: the detection box region corresponding to the target character is binarized to obtain a binary image; the background pixel value of the detection box region corresponding to the target character is determined based on the average value of the pixel values in the blank area of the binary image, and the pixel value of the target character is determined based on the average value of the pixel values outside the blank area.
[0089] In some embodiments, the misspelling image acquisition module 806 is specifically used to: acquire a printed misspelling image corresponding to the current target character; perform style transfer processing on the printed misspelling image according to the target handwriting style corresponding to the first handwritten text image to obtain an initial misspelling image with the target handwriting style; and convert the initial misspelling image into a handwritten misspelling image corresponding to the current target character based on the size of the handwritten misspelling image, the background pixel value of the handwritten misspelling image, and the pixel value of the misspelled character.
[0090] In some embodiments, the information of the current target character also includes the position of the detection box region corresponding to the current target character, and the size of the handwritten misspelling image is the same as the size of the detection box region corresponding to the current target character; the second image acquisition module 808 is configured to: cover the detection box region corresponding to the current target character in the first handwritten text image with the handwritten misspelling image according to the position of the detection box region corresponding to the current target character.
[0091] In some implementations, the characters in the handwritten misspelling image are misspelled characters obtained by erasing the target strokes of the current target character.
[0092] The text image generation apparatus provided in this disclosure can execute the text image generation method provided in any embodiment of this disclosure, and has the corresponding functional modules and beneficial effects of executing the method.
[0093] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the above-described device embodiments can be referred to the corresponding process in the method embodiments, and will not be repeated here.
[0094] Exemplary embodiments of this disclosure also provide an electronic device, including: at least one processor; and a memory communicatively connected to the at least one processor. The memory stores a computer program executable by the at least one processor, the computer program being executed by the at least one processor to cause the electronic device to perform a method according to an embodiment of this disclosure.
[0095] Exemplary embodiments of this disclosure also provide a non-transitory computer-readable storage medium storing a computer program, wherein the computer program, when executed by a computer's processor, is used to cause the computer to perform a method according to embodiments of this disclosure.
[0096] Exemplary embodiments of this disclosure also provide a computer program product, including a computer program, wherein, when executed by a processor of a computer, the computer program is used to cause the computer to perform a method according to an embodiment of this disclosure.
[0097] The computer program product can be written in any combination of one or more programming languages to perform the operations of the embodiments of this disclosure. The programming languages include object-oriented programming languages such as Java and C++, as well as conventional procedural programming languages such as C or similar languages. The program code can be executed entirely on a user's computing device, partially on a user's computing device, as a standalone software package, partially on a user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0098] Furthermore, embodiments of this disclosure can also be computer-readable storage media storing computer program instructions that, when executed by a processor, cause the processor to perform the text image generation method provided in embodiments of this disclosure. The computer-readable storage medium can be any combination of one or more readable media. A readable medium can be a readable signal medium or a readable storage medium. A readable storage medium can be, for example, including but not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatuses, or devices, or any combination thereof. More specific examples of readable storage media (a non-exhaustive list) include: electrical connections having one or more wires, portable disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0099] refer to Figure 9 The present invention describes a structural block diagram of an electronic device 900 that can serve as a server or client of the present disclosure, which is an example of a hardware device that can be applied to various aspects of the present disclosure. The electronic device is intended to represent various forms of digital electronic computer devices, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the present disclosure described and / or claimed herein.
[0100] like Figure 9 As shown, the electronic device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded from a storage unit 908 into a random access memory (RAM) 903. The RAM 903 may also store various programs and data required for the operation of the device 900. The computing unit 901, ROM 902, and RAM 903 are interconnected via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0101] Multiple components in electronic device 900 are connected to I / O interface 905, including: input unit 906, output unit 907, storage unit 908, and communication unit 909. Input unit 906 can be any type of device capable of inputting information to electronic device 900. Input unit 906 can receive input digital or word information and generate key signal inputs related to user settings and / or function control of electronic device. Output unit 907 can be any type of device capable of presenting information and may include, but is not limited to, a display, speaker, video / audio output terminal, vibrator, and / or printer. Storage unit 908 may include, but is not limited to, disk and optical disk. Communication unit 909 allows electronic device 900 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks, and may include, but is not limited to, modems, network cards, infrared communication devices, wireless communication transceivers and / or chipsets, such as Bluetooth™ devices, WiFi devices, WiMa9 devices, cellular communication devices, and / or the like.
[0102] The computing unit 901 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. The computing unit 901 performs the various methods and processes described above. For example, in some embodiments, the text image generation method can be implemented as a computer software program tangibly contained in a machine-readable medium, such as storage unit 908. In some embodiments, part or all of the computer program can be loaded and / or installed on the electronic device 900 via ROM 902 and / or communication unit 909. In some embodiments, the computing unit 901 can be configured to perform the text image generation method by any other suitable means (e.g., by means of firmware).
[0103] The program code used to implement the methods of this disclosure may be written in any combination of one or more programming languages. This program code may be provided to a processor or controller of a general-purpose computer, special-purpose computer, or other programmable data processing apparatus, such that when executed by the processor or controller, the program code causes the functions / operations specified in the flowcharts and / or block diagrams to be implemented. The program code may be executed entirely on a machine, partially on a machine, as a standalone software package partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0104] In the context of this disclosure, a machine-readable medium can be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, apparatus, or device. A machine-readable medium can be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium can be, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination of the foregoing.
[0105] As used in this disclosure, the terms "machine-readable medium" and "computer-readable medium" refer to any computer program product, device, and / or apparatus (e.g., disk, optical disk, memory, programmable logic device (PLD)) for providing machine instructions and / or data to a programmable processor, including machine-readable media that receive machine instructions as machine-readable signals. The term "machine-readable signal" refers to any signal for providing machine instructions and / or data to a programmable processor.
[0106] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device for displaying information to the user (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor); and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the computer. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0107] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as a data server), or computing systems that include middleware components (e.g., an application server), or computing systems that include frontend components (e.g., a user computer with a graphical user interface or web browser through which a user can interact with embodiments of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., a communication network). Examples of communication networks include local area networks (LANs), wide area networks (WANs), and the Internet.
[0108] Computer systems can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. Client-server relationships are created by computer programs running on the respective computers and having a client-server relationship with each other.
[0109] It should be noted that, in this document, relational terms such as "first" and "second" are used merely to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0110] The above description is merely a specific embodiment of this disclosure, enabling those skilled in the art to understand or implement it. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of this disclosure. Therefore, this disclosure is not to be limited to the embodiments described herein, but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.
Claims
1. A method for generating a text image, comprising: Obtain a first handwritten text image; wherein the first handwritten text image contains multiple correctly handwritten characters; The current target character to be replaced is determined from the plurality of correctly handwritten characters, and the information of the current target character is obtained; the information of the current target character includes: the pixel value of the current target character, the background color pixel value of the detection box area corresponding to the current target character, and the size information of the detection box area; Based on the size information of the detection box region corresponding to the current target character, the size of the handwritten misspelling image corresponding to the current target character is determined; based on the background pixel value of the detection box region corresponding to the current target character, the background pixel value of the handwritten misspelling image corresponding to the current target character is determined; and based on the pixel value of the current target character, the pixel value of the incorrect character in the handwritten misspelling image is determined; based on the size of the handwritten misspelling image, the background pixel value of the handwritten misspelling image, and the pixel value of the incorrect character, a handwritten misspelling image corresponding to the current target character is generated; wherein, the character in the handwritten misspelling image is an incorrect character obtained based on the current target character; The handwritten misspelled character image is fused with the first handwritten text image to obtain a second handwritten text image; wherein, the second handwritten text image is a text image in which the current target character is replaced with the misspelled character.
2. The method for generating a text image as described in claim 1, wherein, The step of determining the current target character to be replaced from the plurality of correctly handwritten characters includes: Obtain the application scenario type corresponding to the second handwritten text image, and the correct character that has been selected as the historical target character from among the multiple correct handwritten characters; Based on the application scenario type and the correct characters that have been selected as historical target characters, the current target character to be replaced is determined from the plurality of handwritten correct characters.
3. The method for generating a text image as described in claim 2, wherein, The step of determining the current target character to be replaced from the plurality of handwritten correct characters based on the application scenario type and the correct characters that have been selected as historical target characters includes: In the case where the application scenario type is the first type of application scenario, from the correct characters other than the correct characters that have been selected as historical target characters, a first preset number of correct characters are selected as the current target characters to be replaced.
4. The method for generating a text image as described in claim 3, wherein, The first type of application scenario includes error word detection scenarios, or scenarios that identify error words as preset special characters.
5. The method for generating a text image as described in claim 2, wherein, The step of determining the current target character to be replaced from the plurality of handwritten correct characters based on the application scenario type and the correct characters that have been selected as historical target characters includes: When the application scenario type is the second type of application scenario, obtain the word segmentation results corresponding to the multiple correctly handwritten characters; Based on the word segmentation results, from the correct characters other than those already selected as historical target characters, a second preset proportion of correct characters are selected as the current target characters to be replaced.
6. The method for generating a text image as described in claim 5, wherein, At most one character in each word segmentation result is selected as the current target character.
7. The method for generating a text image as described in claim 5, wherein, The second type of application scenario includes scenarios where incorrect characters are identified as the corresponding correct characters.
8. The method for generating a text image as described in claim 1, wherein, The background pixel value of the handwritten misspelled character image is the same as the background pixel value of the detection box area corresponding to the current target character, and the pixel value of the misspelled character in the handwritten misspelled character image is the same as or different from the pixel value of the current target character.
9. The method for generating a text image as described in claim 1, wherein, The step of determining the pixel value of the erroneous character in the handwritten misspelling image based on the pixel value of the current target character includes: Obtain the pixel values of erroneous characters in a pre-generated historical handwritten text image; wherein, the erroneous characters in the historical handwritten text image are obtained based on the historical target characters in the first handwritten text image; The pixel value of the erroneous character in the handwritten misspelling image is determined based on the pixel value of the erroneous character in the historical handwritten text image; wherein the pixel value of the erroneous character in the handwritten misspelling image is different from the pixel value of the erroneous character in the historical handwritten text image.
10. The method for generating a text image as described in claim 9, wherein, The step of determining the pixel value of the erroneous character in the handwritten misspelling image based on the pixel value of the erroneous character in the historical handwritten text image includes: Obtain a first ratio of the pixel value of the erroneous character in the historical handwritten text image to the pixel value of the historical target character; Based on the first ratio, a second ratio is determined between the pixel value of the erroneous character in the handwritten misspelling image and the pixel value of the current target character; wherein the second ratio is not less than the first ratio and the second ratio is not greater than one. The pixel value of the erroneous character in the handwritten misspelling image is determined based on the second ratio and the pixel value of the current target character.
11. The method for generating a text image as described in claim 1, wherein, The pixel value of the current target character and the background pixel value of the detection box area corresponding to the current target character are obtained in the following way: Clustering is performed on the pixel values of the detection box region corresponding to the current target character to obtain a first cluster and a second cluster; The pixel value of the current target character and the background pixel value of the detection box area corresponding to the current target character are determined based on the average pixel value of the first cluster and the average pixel value of the second cluster.
12. The method for generating a text image as described in claim 1, wherein, The pixel value of the current target character and the background pixel value of the detection box area corresponding to the current target character are obtained in the following way: The detection box region corresponding to the current target character is binarized to obtain a binary image; The background pixel value of the detection box region corresponding to the current target character is determined based on the average value of the pixel values in the blank area of the binary image, and the pixel value of the current target character is determined based on the average value of the pixel values outside the blank area.
13. The method for generating a text image as described in claim 1, wherein, The step of generating the handwritten misspelled character image corresponding to the current target character based on the size of the handwritten misspelled character image, the background pixel value of the handwritten misspelled character image, and the pixel value of the misspelled character includes: Obtain the printed text image of the misspelled character corresponding to the current target character; Based on the target handwriting style corresponding to the first handwritten text image, the printed misspelling image is subjected to style transfer processing to obtain an initial misspelling image with the target handwriting style; Based on the size of the handwritten misspelled word image, the background pixel value of the handwritten misspelled word image, and the pixel value of the misspelled word, the initial misspelled word image is converted into the handwritten misspelled word image corresponding to the current target word.
14. The method for generating a text image as described in claim 1, wherein, The information of the current target character also includes the position of the detection box region corresponding to the current target character, and the size of the handwritten misspelling image is the same as the size of the detection box region corresponding to the current target character; The step of fusing the handwritten misspelling image with the first handwritten text image includes: Based on the position of the detection box region corresponding to the current target character, the handwritten misspelling image is used to cover the detection box region corresponding to the current target character in the first handwritten text image.
15. The method for generating a text image as described in any one of claims 1 to 14, wherein, The characters in the handwritten misspelling image are the misspelled characters obtained after performing an erasure operation on the target strokes of the current target character.
16. A text image generation apparatus, comprising: The first image acquisition module is used to acquire a first handwritten text image; wherein, the first handwritten text image contains multiple correctly handwritten characters; The target character information acquisition module is used to determine the current target character to be replaced from the plurality of correctly handwritten characters, and to acquire the information of the current target character; the information of the current target character includes: the pixel value of the current target character, the background color pixel value of the detection box area corresponding to the current target character, and the size information of the detection box area; The misspelled character image acquisition module is used to determine the size of the handwritten misspelled character image corresponding to the current target character based on the size information of the detection box region corresponding to the current target character; determine the background pixel value of the handwritten misspelled character image corresponding to the current target character based on the background pixel value of the detection box region corresponding to the current target character; and determine the pixel value of the erroneous character in the handwritten misspelled character image based on the pixel value of the current target character; and generate the handwritten misspelled character image corresponding to the current target character based on the size of the handwritten misspelled character image, the background pixel value of the handwritten misspelled character image, and the pixel value of the erroneous character; wherein, the character in the handwritten misspelled character image is an erroneous character obtained based on the current target character; The second image acquisition module is used to fuse the handwritten misspelling image with the first handwritten text image to obtain a second handwritten text image; wherein, the second handwritten text image is a text image in which the current target character is replaced with the misspelling character.
Citation Information
Patent Citations
Wrongly written character proofreading method and device for automatically generating training data
CN112560451A
Image synthesis method and device, electronic equipment and storage medium
CN114841906A