Text image synthesis method, device, equipment, storage medium and program product
Through the fusion processing of template images and labeled information, text images with real text characteristics are generated, which solves the problem of insufficient data sets required for OCR model training in financial scenarios, and achieves fast and easy text image synthesis.
Patent Information
- Application Number
- CN202111614727.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-02-25
- Estimated Expiration
- 2041-12-27
AI Technical Summary
In financial scenarios, prior art has difficulty quickly and easily obtaining a sufficient number of data sets similar to the features of real text images, resulting in difficulty in training optical character recognition (OCR) models.
By obtaining template images and their annotation information, an initial text area is generated, and processing it according to local area processing rules, and the initial text image is fused to generate, thereby quickly obtaining multiple text images.
It realizes the rapid and easy generation of multiple text images, meets the training needs of OCR model, and makes the generated text area text characteristics more similar to real text.
Smart Images

Figure CN114332895B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the technical field of optical character recognition, and in particular to a text image synthesis method, device, equipment, storage medium and program product. Background Art
[0002] With the development of artificial intelligence technology, optical character recognition (OCR) technology has emerged. Optical character recognition (OCR) refers to the technology of analyzing and identifying image data files containing text data (which can be referred to as text images) to obtain text information. In financial scenarios, there are many types of text images, such as bills, documents, cards, forms and other text images with financial characteristics. These text images have the characteristics of uncertain text layout, different field fonts, colors, lengths, and corpora, and complex and diverse backgrounds of text.
[0003] When training an OCR model for text images with financial characteristics, it is necessary to prepare a data set with the same or similar data features as the real text images. However, the number of existing data sets with the same or similar data features as the real text images cannot meet the training requirements. If a sufficient number of real text images are actually taken manually, it will consume a lot of manpower and time costs, and the cost of manually annotating real text images is also very high.
[0004] In order to quickly and easily obtain a sufficient number of text images, a method of synthesizing text images can be used, but how to synthesize text images with good effects is a problem to be solved. Summary of the invention
[0005] Based on this, it is necessary to provide a method, apparatus, computer device, computer-readable storage medium and computer program product that can quickly and easily synthesize text images in order to solve the above technical problems.
[0006] In a first aspect, the present application provides a method for synthesizing a text image, the method comprising: obtaining a template image, the template image carrying annotation information; generating an initial text area according to content information in the annotation information; processing the initial text area according to a local area processing rule to obtain a target text area; and fusing the template image and the target text area according to position information in the annotation information to generate an initial text image.
[0007] In one of the embodiments, the processing of the initial text area according to the local area processing rule to obtain the target text area includes: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain the target text area; the basic image operator refers to an operator that performs area position operations on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font.
[0008] In one of the embodiments, the process of processing the initial text area by the stamp font effect operator includes: randomly selecting pixel points from the initial text area, and assigning the pixel points to the background color of the initial text area; performing image dilation operations and image erosion operations on the assigned initial text area to obtain a target text area.
[0009] In one of the embodiments, the process of processing the initial text area by the dot matrix printing font effect operator includes: superimposing a grid with the background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by the stamp font effect operator to obtain a target text area.
[0010] In one of the embodiments, the process of processing the initial text area by the mottled handwriting effect operator includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
[0011] In one of the embodiments, the method further comprises: processing the initial text image according to the overall image processing rule to obtain the target text image. In one of the embodiments, processing the initial text image according to the overall image processing rule to obtain the target text image comprises: processing the initial text image according to at least one of an image noise adding operation, a local fading operator, a stamping operator and a watermarking operator to obtain the target text image; the local fading operator refers to an operator for performing brightness processing on the initial text image; the stamping operator refers to an operator for adding a stamp image to the initial text image; the watermarking operator refers to an operator for adding a watermark image to the initial text image.
[0012] In one embodiment, the process of processing the initial text image by the local fade operator includes: obtaining a faded area and a central area of the initial text image; obtaining the maximum brightness of pixels within the faded range; processing the initial text image according to the faded area, the central area and the maximum brightness to obtain a target text image.
[0013] In one of the embodiments, the process of processing the initial text image by the stamping operator includes: acquiring the stamp image; and performing fusion processing on the stamp image and the initial text image to obtain a target text image.
[0014] In one of the embodiments, the process of processing the initial text image by the watermarking operator includes: obtaining an initial text area and performing an image position processing operation on the initial text area; fusing the processed initial text area with the initial text image to obtain a target text image.
[0015] In one of the embodiments, the method further includes: extracting a target text image area from the target text image according to the annotation information in the template image.
[0016] In one of the embodiments, the obtaining of the template image includes: obtaining a configuration file corresponding to the template image; before obtaining the configuration file corresponding to the template image, it includes: obtaining a sample image, and processing a target area of the sample image to obtain a corresponding template image; annotating the target area in the template image to obtain annotation information, wherein the annotation information includes at least one of a template image name, a target text area fusion position, and a text area category; and generating a configuration file corresponding to the template image according to the annotation information.
[0017] In one of the embodiments, generating the initial text area according to the annotation information includes: extracting the annotation information corresponding to each target area in the configuration file, and generating the initial text area according to the annotation information.
[0018] In the second aspect, the present application also provides a text image synthesis device, which includes: an acquisition module, used to acquire a template image, wherein the template image includes annotation information; an initial area generation module, used to generate an initial text area according to the annotation information and the received configuration instructions; an initial area processing module, used to process the initial text area according to a local area processing rule to obtain a target text area; and a fusion module, used to fuse the template image and the target text area according to the position information in the annotation information to generate an initial text image.
[0019] In a third aspect, the present application further provides a computer device, wherein the computer device comprises a memory and a processor, wherein the memory stores a computer program, and the processor implements the steps of the above method when executing the computer program.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program implements the steps of the above method when executed by a processor.
[0021] In a fifth aspect, the present application further provides a computer program product, wherein the computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the above method are implemented.
[0022] The above-mentioned text image synthesis method, device, equipment, storage medium and program product generate an initial text area through a template image and annotation information, process the initial text area through a local area processing rule to obtain a target text area, and generate an initial text image based on the fusion of the target text area and the template image. A plurality of corresponding initial text images can be generated through a template image. If the types of template images are different, corresponding initial text images can be generated based on different types of template images, so as to quickly and easily obtain a sufficient number of text images. The initial text area is processed through a local area processing rule so that the text characteristics in the generated target text area are more similar to real text. BRIEF DESCRIPTION OF THE DRAWINGS
[0023] Figure 1 A diagram showing an application environment of a text image synthesis method in an embodiment;
[0024] Figure 2 1 is a flow chart of a text image synthesis method in one embodiment;
[0025] Figure 3 A schematic diagram of a flow chart of a template image in a text image synthesis method in an embodiment;
[0026] Figure 4 is a schematic diagram of a target text area in a text image synthesis method in one embodiment;
[0027] Figure 5 is a schematic diagram of a dilation operation in a text image synthesis method in one embodiment;
[0028] Figure 6 is a schematic diagram of an erosion operation in a text image synthesis method in one embodiment;
[0029] Figure 7 is a schematic diagram of a target text area in a text image synthesis method in another embodiment;
[0030] Figure 8 is a schematic diagram of a target text area in a text image synthesis method in yet another embodiment;
[0031] Fig. 9 is a schematic diagram of a target text image in a text image synthesis method in one embodiment;
[0032] Fig.10 is a schematic diagram of a target text image in a text image synthesis method in another embodiment;
[0033] Fig.11 A schematic diagram of steps of a text image synthesis method in one embodiment;
[0034] Fig.12 A schematic diagram of a json configuration file in a text image synthesis method in one embodiment;
[0035] Fig.13 A schematic diagram of two-point annotation in a text image synthesis method in one embodiment;
[0036] Fig.14 A schematic diagram of four-point annotation in a text image synthesis method in one embodiment;
[0037] Fig.15 is a structural block diagram of a text image synthesis device in one embodiment;
[0038] Fig.16 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0039] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0040] The text image synthesis method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. Among them, the terminal 102 communicates with the server 104 through the network. The data storage system can store the data that the server 104 needs to process. The data storage system can be integrated on the server 104, or it can be placed on the cloud or other network servers. The terminal 102 obtains a template image, and the template image carries annotation information; generates an initial text area according to the content information in the annotation information; processes the initial text area according to the local area processing rules to obtain the target text area; and fuses the template image and the target text area according to the position information in the annotation information to generate an initial text image. Text image synthesis can be performed quickly and easily. The template image obtained by the terminal 102 can be input by the user, or it can be a template image stored in the server 104. The initial template image generated by the terminal 102 can also be stored in the server 104.
[0041] The terminal 102 may be, but is not limited to, various personal computers, laptops, smart phones, tablet computers, IoT devices, and portable wearable devices. The IoT devices may be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. The portable wearable devices may be smart watches, smart bracelets, head-mounted devices, etc. The server 104 may be implemented as an independent server or a server cluster consisting of multiple servers.
[0042] In one embodiment, Figure 2 As shown, a text image synthesis method is provided, and the method is applied to Figure 1 The terminal 102 in the example is used as an example to illustrate, and the following steps are included:
[0043] Step 202: Acquire a template image, where the template image carries annotation information.
[0044] The template image is obtained based on the sample image. For example, the terminal deletes certain areas in the sample image of the business license to generate a template image corresponding to the business license. The template image includes but is not limited to a template image corresponding to the business license, a template image corresponding to a bank note, a template image corresponding to an identity card, etc. The annotation information includes but is not limited to the location information of the deleted area in the sample image, the attributes of the sample image, and the attributes of the text in the deleted area.
[0045] Specifically, the terminal obtains a sample image, processes the content in the sample image, uses the processed sample image as a template image, and uses the attributes of the sample image, the position information of the processed area in the sample image, and the text attributes in the processed area as the specific content information of the annotation information of the template image. If the terminal processes multiple areas in the same sample image, the attributes of the sample image, the position information corresponding to each processed area, and the text attributes in the processed area are sequentially stored as the specific content information of the annotation information.
[0046] Step 204: Generate an initial text region according to the content information in the annotation information.
[0047] The initial text area is generated according to the annotation information of the template image and the corresponding size is determined.
[0048] Specifically, the terminal generates the initial text region according to the content information in the annotation information, that is, according to the attributes of the sample image in the template image, the position information of the processed region and the text attributes in the processed region.
[0049] In the specific implementation process, Figure 3 Taking the business license in the sample image as an example, the terminal deletes the content corresponding to the name in the sample image, and marks the location of the deleted content, the font attributes of the deleted content, and the attributes of the sample image as annotation information. The terminal obtains the attributes of the sample image, and the attributes of the sample image include but are not limited to whether the deleted content has jagged edges, whether it is skipped, the text area category, and the generation rules of the corpus. Among them, the font attributes include but are not limited to the type, size, style, color, and thickness of the font. The terminal determines the starting position of the field in the initial text area according to the location of the deleted content. The terminal limits the jagged conditions of the field in the initial text area based on whether it has jagged edges, determines whether the location of the deleted content generates the corresponding initial text area based on whether it is skipped, and determines the processing rules of the initial text area based on the text area category. The processing rules make the obtained text similar to the real text, and the text content of the initial text area is generated according to the generation rules of the corpus. The size of the initial text area is determined according to the text content of the initial text area generated above. The corpus generation rule can specify the corpus name in the configuration file, and randomly select a corpus from the specified corpus as the text content when generating the corpus; the corpus generation rule can also specify the text format through regular rules, such as randomly generating an 18-digit number containing only numbers and letters. The terminal makes corresponding restrictions on the properties of the text generated in the initial text area according to the font properties.
[0050] Step 206: Process the initial text region according to the local region processing rule to obtain a target text region.
[0051] The local area processing rules are rules for processing the text in the initial text area, and the obtained text is similar to the real text.
[0052] The terminal processes the initial text region according to the local processing rules, and the obtained text is similar to the real text, which is the target text region.
[0053] Step 208: The template image and the target text area are fused according to the position information in the annotation information to generate an initial text image.
[0054] The terminal fuses the target text area with the template image through the Poisson image fusion method according to the position information in the annotation information, introduces gradient information in the fusion process of the target text area and the template image, and generates an initial text image.
[0055] In the above-mentioned text image synthesis method, an initial text area is generated by using a template image and annotation information, the initial text area is processed by using a local area processing rule to obtain a target text area, and an initial text image is generated based on the fusion of the target text area and the template image. A plurality of corresponding initial text images can be generated by using a template image. If the types of template images are different, corresponding initial text images can be generated based on different types of template images, so as to quickly and easily obtain a sufficient number of text images. The initial text area is processed by using a local area processing rule so that the text features in the generated target text area are more similar to real text.
[0056] An implementation method of obtaining a target text area by processing an initial text area according to a local area processing rule in the above embodiment includes: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain a target text area; the basic image operator refers to an operator that performs area position operations on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font.
[0057] Specifically, the terminal obtains the rotation angle and offset range through the annotation information corresponding to the initial text area, and rotates and offsets the position of the initial text area according to the rotation angle and offset range according to the basic image operator to obtain the target text area. Among them, the rotation angle and offset range can be specified values, or can be randomly generated within a certain range. The terminal processes the text in the initial text area according to the stamp font effect operator to form text in the stamp font format, and obtains the target text area with the stamp font format. The terminal processes the text in the initial text area according to the pin-type printing font effect operator to form text in the pin-type printing font, and obtains the target text area with the pin-type printing font. The terminal processes the text in the initial text area according to the mottled handwriting effect operator to form mottled handwriting text, and obtains the target text area with the mottled handwriting effect. The terminal can process the initial text area with at least one operator. The terminal can determine the type and number of operators to be executed through the text area category attribute in the annotation information in the template image.
[0058] In the above-mentioned text image synthesis method, the initial text area is processed according to at least one of the basic image operator, the stamp font effect operator, the dot matrix printing font effect operator and the mottled handwriting effect operator, so that the text characteristics in the target text area are more similar to the real text characteristics.
[0059] In one embodiment, the process of processing the initial text area by the stamp font effect operator includes: randomly selecting pixel points from the initial text area and assigning the pixel points to the background color of the initial text area; performing image dilation operations and image erosion operations on the assigned initial text area to obtain a target text area.
[0060] Specifically, the terminal randomly selects pixels from the initial text area multiple times and assigns values to the randomly selected pixels, and the assigned values are background colors. The background color is the color of the non-text part in the initial text area. The terminal performs an image expansion operation and an image erosion operation on the assigned initial text area in a superimposed manner to obtain a target text area. The text effect in the target text area is the same as the stamp font effect, such as Figure 4 Optionally, the image dilation operation is performed by Figure 5 To explain, Figure 5On the left is the processed image X, which is a binary image. The object of the image dilation operation is the black dot in image X. In the middle is the structural element B. The point marked with origin in the structural element B is the center point, that is, the position of the currently processed element. On the right is the result after the dilation operation. The specific process of the dilation operation is that the terminal performs a convolution operation on the structural element B on the image X to determine whether the center point of the structural element B coincides with the black dot in the image X. If the center point of the structural element B coincides with the black dot in the image X, the position on the image X that coincides with the black dot on the structural element B is assigned a black dot. On the right is the result after the dilation. Optionally, the image erosion operation is performed by Figure 6 To explain, Figure 6 The left side is the processed image X, which is a binary image. The object of the image erosion operation is the black dots in image X. The middle is the structural element B. The point marked with origin in the structural element B is the center point, that is, the position of the currently processed element. The right side is the result after the erosion operation. The specific process of the erosion operation is that the terminal performs a convolution operation on the structural element B on the image X to determine whether all the black dots of the structural element B coincide with the black dots of the image X. If all the black dots of the structural element B coincide with the black dots of the image X, the position on the image X that coincides with the center point of the structural element B is assigned as a black dot; if all the black dots of the structural element B do not completely coincide with the black dots of the image X, the position on the image X that coincides with the center point of the structural element B is assigned as a white dot; the right side is the result after erosion.
[0061] The above-mentioned text image synthesis method randomly selects pixel points from the initial text area and assigns the pixel points to the background color of the initial text area, causing the text in the initial text area to have a certain degree of color loss, and then performs image expansion and image erosion operations on the assigned initial text area, so that the strokes of the text in the initial text area have the characteristic of irregular fusion of ink, thereby simulating the blurring effect of the ink of the text when stamping, and forming a target text area.
[0062] In one embodiment, the process of processing the initial text area by the dot matrix printing font effect operator includes: superimposing a grid with the background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by the stamp font effect operator to obtain the target text area.
[0063] Specifically, the terminal obtains the color of the non-text part in the initial text area as the background color, and formulates a grid with the background color according to the background color, and superimposes the grid with the background color on the initial text area to form a grid text area. The terminal randomly selects pixels from the grid text area multiple times, and assigns values to the randomly selected pixels, and the assigned values are the background color. Among them, the background color is the color of the non-text part in the grid text area. The terminal performs image expansion operations and image erosion operations on the grid text area after the assignment in a superimposed manner to obtain a target text area. The text effect in the target text area is the same as that of a dot matrix printing font, such as Figure 7 shown.
[0064] The above-mentioned text image synthesis method simulates the dot matrix effect of the dot matrix printing font by superimposing a grid with the background color of the initial text area on the initial text area, and processes the initial text area after the superimposed grid through the stamp font effect operator, so that the dot matrix of the text in the initial text area is irregularly merged or disconnected, thereby simulating ink smudges to form a target text area, so that the text effect in the target text area is closer to the dot matrix printing font effect in the real scene.
[0065] In one embodiment, the process of processing an initial text area by a mottled handwriting effect operator includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
[0066] The preset value is the threshold of the Gaussian distribution matrix, which is determined based on experience. The larger the threshold, the larger the average area of the patches of text in the target text area. The threshold needs to be adjusted many times until the text display effect in the target text area and the text display effect in the sample image corresponding to the template image meet the preset requirements. This embodiment does not limit the preset value, which is determined based on the preset requirements for the similarity between the text display effect in the target text area and the text display effect in the sample image corresponding to the template image.
[0067] Specifically, the terminal obtains the size of the initial text area and the threshold of the Gaussian distribution matrix, generates a Gaussian distribution matrix of the same size according to the pixels of the initial text area and the size of the initial text area, establishes a mapping relationship between each element of the Gaussian distribution matrix and the pixels of the initial text area, screens each element in the Gaussian distribution matrix by the threshold, randomly increases or decreases the brightness value of the pixel points of the initial text area corresponding to the element whose value is less than a preset value, and performs Gaussian blur soft operation and strong edge operation on the initial text area after brightness adjustment to obtain the target text area, and the text effect in the target text area is the same as the effect of the mottled font, such as Figure 8 shown.
[0068] The above-mentioned text image synthesis method establishes a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusts the brightness of the pixel points corresponding to the elements in the matrix that are smaller than a preset value; and performs image processing operations on the initial text area after the brightness adjustment, so that the color of the text in the target text area has a mottled effect of dark and light handwriting.
[0069] In one embodiment, the initial text image is processed according to the overall image processing rule to obtain the target text image.
[0070] The overall image processing rule is a rule for processing the initial text region, and the target text image obtained is similar to the real text image.
[0071] The terminal processes the initial text region according to the overall image processing rules to obtain a target text image similar to the real text image.
[0072] The above-mentioned text image synthesis method processes the initial text image according to the overall image processing rule to obtain a target text image similar to the real text image.
[0073] An implementation method of obtaining a target text image by processing an initial text image according to the overall image processing rules in the above embodiment includes: processing the initial text image according to at least one of an image denoising operation, a local fading operator, a stamping operator and a watermarking operator to obtain a target text image; the local fading operator refers to an operator that performs brightness processing on the initial text image; the stamping operator refers to an operator that adds a stamp image to the initial text image; the watermarking operator refers to an operator that adds a watermark image to the initial text image.
[0074] Specifically, the terminal performs at least one of the noise operations such as salt and pepper noise, Gaussian blur, motion blur, etc. on the initial text image according to the image noise operation. The terminal performs brightness processing on the initial text image according to the local fade operator to obtain a locally faded target text image; the terminal adds a seal image to the initial text image according to the stamp operator to obtain a target text image with the seal image added; the terminal adds a watermark image to the initial text image according to the watermark operator to obtain a target text image with the watermark image added; the terminal can perform at least one operator processing on the initial text image according to the real scene data included in the sample image. The above at least one or at least one can be one, or a random combination of two or more.
[0075] The above-mentioned text image synthesis method processes the initial text image according to at least one of the image noise addition operation, the local fading operator, the stamping operator and the watermarking operator, so that the characteristics of the obtained target text image are more similar to the real text image.
[0076] In one embodiment, the process of processing an initial text image by a local fade operator includes: obtaining a faded area and a central area of the initial text image; obtaining the maximum brightness of pixels within the faded range; and processing the initial text image according to the faded area, the central area and the maximum brightness to obtain a target text image.
[0077] The faded area is the area in the initial text image that needs to adjust the brightness, and the central area is located within the faded area. Specifically, the positions of the faded area and the central area can be automatically generated according to the rules preset by the terminal, or can be specified by the user. The maximum brightness value (extr) can be automatically generated according to the rules preset by the terminal, or can be specified by the user. It is the maximum brightness coefficient. The maximum brightness coefficient is specified or automatically generated according to the actual effect to be achieved. The larger the brightness coefficient, the brighter the image. Fig. 9 The maximum brightness factor is 2.0.
[0078] Specifically, the terminal obtains the faded area and the central area of the initial text image, and obtains the maximum brightness of the pixels within the faded range. The terminal multiplies the brightness of the pixels in the central area by the maximum brightness coefficient, and multiplies the brightness of the pixels outside the central area in the faded area by the preset brightness coefficient to obtain the target text image, which has the same local fade characteristics as the real image. The value of the preset brightness coefficient is linearly related to the distance of the pixels outside the central area in the faded area from the central area to the faded area. The greater the distance of the pixels outside the central area in the faded area from the central area, the smaller the value of the brightness coefficient is, until it decreases to 1. The value range of the preset brightness coefficient is [1, extr].
[0079] The above-mentioned text image synthesis method processes the initial text image according to the faded area, the central area and the maximum brightness to form a gradually fading effect and obtain the target text image.
[0080] In one embodiment, the process of stamping an initial text image with a seal operator to process the initial text image includes: acquiring a seal image; and performing fusion processing on the seal image and the initial text image to obtain a target text image.
[0081] Specifically, the terminal obtains the seal image and the position of the seal image in the initial text image, wherein the position of the seal image in the initial text image is stored in the annotation information of the corresponding template image. The terminal fuses the seal image and the initial text image at the position of the seal image in the initial text image by the Poisson fusion method to obtain a target text image, and the target text image has the same characteristics of the seal image as the real image.
[0082] In the above-mentioned text image synthesis method, the terminal performs fusion processing based on the seal image and the initial text image to form a target text image with a seal image that is similar to the real image.
[0083] In one embodiment, the process of adding a watermark operator to an initial text image to process the initial text image includes: obtaining an initial text area and performing an image position processing operation on the initial text area; fusing the processed initial text area with the initial text image to obtain a target text image.
[0084] Among them, the initial text area is the watermark text content area, the size of the watermark text content area can be preset according to needs, and the text content and text characteristics of the watermark text content area can be generated in the same way as but not limited to the text generation method in the initial text area.
[0085] Specifically, the terminal obtains the initial text area and the rotation angle of the initial text area in the initial text image, wherein the rotation angle of the initial text area in the initial text image is stored in the annotation information of the corresponding template image. The terminal rotates the initial text area by the rotation angle of the initial text area in the initial text image, and performs Poisson image fusion on the rotated initial text area and the initial text image. Optionally, the terminal performs Poisson image fusion on the rotated initial text area and the initial text image multiple times. Optionally, the terminal offsets the initial text area from the upper left corner of the initial text image to the lower right corner by a preset distance until it exceeds the size range of the initial text image, such as Fig.10 shown.
[0086] In the above-mentioned text image synthesis method, the terminal fuses the processed initial text area with the initial text image to form a target text image with a watermark image similar to the real image.
[0087] In one embodiment, the target text image region is extracted from the target text image according to the extraction position information, and the extraction position information is the position of the target text region after the target text region is fused into the initial text image.
[0088] Specifically, the terminal slices the target text image according to the extracted position information, i.e., the position of the target text area after the target text area is fused into the initial text image, and extracts the target text image extracted within the position information after slicing as the target text image area. The above target text image area is stored separately. Optionally, while generating the target text image, a labeling file of the target text image is also generated. The labeling file contains the position information of all text areas in the target text image (OCR detection model training data), the category information of the text area (OCR slice classification model training data), and the text content of the text area (OCR recognition model training data). The terminal performs a slicing operation according to the position information recorded in the labeling file of the target text image. The above text image synthesis method extracts the target text image area from the target text image according to the labeling information in the template image, and can obtain the target text image area separately to meet the text image storage methods of different dimensions.
[0089] The process of acquiring the template image in the above-mentioned embodiment is explained in this embodiment, and acquiring the template image includes: acquiring a configuration file corresponding to the template image; before acquiring the configuration file corresponding to the template image, it includes: acquiring a sample image, and processing the target area of the sample image to obtain the corresponding template image; annotating the target area in the template image to obtain annotation information, and the annotation information includes at least one of the template image name, the target text area fusion position, and the text area category; generating the configuration file corresponding to the template image according to the annotation information.
[0090] The sample image is a real text image, the target area is the position corresponding to the target text area in the initial text image, and the text area category is the text category of the target area of the sample image, for example, the text category is stamp font, dot matrix font, mottled handwriting, etc.
[0091] Specifically, the terminal obtains a sample image, and processes the target area in the sample image to obtain a corresponding template image. The terminal annotates and generates annotation information for at least one of the position of the target area of the template image, i.e., the fusion position of the target text area, the name of the template image, the text category of the target area, the text attribute of the target area, the attributes of the sample image, i.e., the watermark rotation range of the sample image, the watermark attribute and position of the sample image, the stamp image attribute and position of the sample image, the fade range of the sample image, the center range, and the maximum brightness coefficient. And a corresponding configuration file is generated based on the above annotation information.
[0092] The above-mentioned text image synthesis method generates a configuration file corresponding to the template image according to the annotation information and saves it in the form of a configuration file. It can extract codes for common operations such as reading configuration, generating images, and saving annotation information, and can generate images semi-automatically.
[0093] In one embodiment, the annotation information corresponding to each target area in the configuration file is extracted, and the initial text area is generated according to the annotation information.
[0094] Specifically, the terminal extracts the annotation information corresponding to each target area in the configuration file, and generates an initial text area according to the annotation information.
[0095] In the above-mentioned text image synthesis method, the terminal generates an initial text area according to the annotation information, thereby reducing the tedious operation of writing layout codes one by one.
[0096] In one embodiment, Fig.11 As shown, a text image synthesis method in a financial scenario is provided, comprising:
[0097] The terminal erases the text in the target area of the sample image through the P map, generates a corresponding template image, and annotates the template image. The annotation information includes the template image name, the target area location, and the text area category, such as Figure 3 As shown. The terminal automatically generates the initial json (a data format) configuration file for all templates based on the annotation information, and modifies the parameters in the json file for each template. Among them, the json configuration file defines the font size, font color, starting position, alignment, rotation angle, horizontal offset range, vertical offset range, whether there are jagged edges, whether to bold, whether to skip, field label (text area category) and corpus generation rules for each field in the initial text area. The json configuration file is as follows Fig.12As shown, the overall attribute is global and valid for all fields. When a single field attribute exists, it will overwrite the overall attribute, by saving the synthesis method of each different template image in the form of a configuration file. The terminal extracts the code of common operations such as reading configuration, generating images, and saving annotation information in each configuration file, and performs text image synthesis by calling the code of the common part. The terminal obtains and parses the json configuration file, extracts the configuration information of each field, and generates text slices for each field according to the configuration information. The parsed json configuration file includes font name, color, size, thickness, corpus generation rules, etc. Here, the text content of the initial text area is generated according to the corpus rules. Optionally, the corpus rule can specify the corpus name in the configuration file. For example, when generating the text content of the initial text area, the terminal randomly selects a corpus in the specified corpus as the text content, or the corpus rule is a regular rule. For example, the terminal randomly generates an 18-digit number containing only numbers and letters. The terminal performs basic image enhancement operations on the initial text area according to the json configuration file, including rotation, offset, etc. The terminal processes the initial text area after basic image enhancement according to the enhancement operator specified in the json configuration file to obtain the target text area. For example, the terminal processes the initial text area after basic image enhancement according to the stamp font effect operator specified in the json configuration file, first randomly selects pixels multiple times and assigns them to background colors, then performs image expansion and corrosion operations on the initial text area after the assignment, and obtains the following Figure 4 For example, the terminal processes the initial text area after the basic image enhancement operation according to the dot matrix printing font effect operator specified in the json configuration file. First, a grid with the background color is added to the initial text area after the basic image enhancement operation. Then, pixels are randomly selected multiple times on the initial text area and assigned to the background color. The image expansion operation and the erosion operation are superimposed on the initial text area after the assignment, and the following is obtained: Figure 7 For example, the terminal processes the initial text area after basic image enhancement operation according to the mottled handwriting effect operator specified in the json configuration file, first generates a Gaussian distribution matrix of the same size as the initial text area, establishes a mapping relationship between the matrix and the pixels of the initial text area, obtains the part of the matrix that is smaller than the threshold by specifying a threshold, randomly increases or decreases the brightness of the pixels corresponding to the part of the matrix that is smaller than the threshold, and performs Gaussian blur soft operation and strong edge operation on the initial text area after brightness adjustment, and obtains the following Figure 8The target text area shown. The terminal fuses the target text area with the template image through the Poisson image fusion method according to the location information of the json configuration text, the offset range of the text in the initial text area in the x and y directions, and the rotation angle range according to the corresponding gradient information, and randomly offsets and rotates the target text area to obtain the initial text image. The terminal processes the initial text image according to the overall image processing rules to obtain the target text image. For example, the terminal fuses the seal image and the initial text image through the Poisson fusion method to obtain the target text image to be stamped. The terminal sets a rectangular fade range and an extreme value extr of a brightness coefficient, and multiplies the brightness coefficient of the pixel points in the fade range by the brightness coefficient between [1, extr] to achieve a fade effect. Optionally, a central area is set within the fade range. Within the central area, the brightness coefficient of the pixel points within the central area is multiplied by extr. Outside the central area, the brightness coefficient is linearly related to the distance from the pixel point to the edge of the central area. The farther away from the central area, the smaller the brightness coefficient is until it decreases to 1. The target text image obtained is as follows Fig. 9 For example, the terminal sets the watermark text content and font and completes the synthesis of the horizontal text slice, then performs the enhancement operation of the mottled handwriting effect operator on the horizontal text slice, rotates the mottled handwriting horizontal text slice with the initial text image by a Poisson image after a fixed angle, and obtains the initial text image after adding a watermark, and offsets the horizontal text slice from the upper left corner of the initial text image to the lower right corner by the same distance, and performs the fusion operation in sequence until it exceeds the range of the initial text image, thus forming the target text image, as shown in FIG. Fig.10 Optionally, the terminal saves the generated target text image and the corresponding annotation information, which can be used to expand the detection model training data. The annotation information includes the text content and text box of each field, and supports 4-point annotation and 2-point annotation of the text box. Fig.13 As shown, the text annotation box can be specified by two points, namely the coordinates (x, y) of the upper left corner and the lower right corner: 1041; 87; 1648; 207, and can only be a horizontal box. Fig.14 As shown, the annotation box of the text can also be specified by 4 points clockwise, namely, upper left, upper right, lower right, and lower left: 1041; 87; 1644; 78; 1648; 207; 1041; 211, and the 4-point annotation form can be a quadrilateral of any shape. The terminal cuts out a slice, i.e., the target text image area, from the target text image according to the text box coordinates, and obtains the recognition model training data containing the text content annotation. Optionally, the terminal generates the target text image in a multi-threaded manner.
[0098] It should be understood that, although the various steps in the flowcharts involved in the above-mentioned embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps does not have a strict order restriction, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above-mentioned embodiments can include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0099] Based on the same inventive concept, the embodiment of the present application also provides a text image synthesis device for implementing the text image synthesis method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more text image synthesis device embodiments provided below can refer to the limitations of the text image synthesis method above, and will not be repeated here.
[0100] In one embodiment, Fig.15 As shown, a text image synthesis device is provided, comprising: an acquisition module 100, an initial region generation module 200, an initial region processing module 300 and a fusion module 400, wherein:
[0101] An acquisition module 100 is used to acquire a template image, wherein the template image includes annotation information;
[0102] An initial region generating module 200, for generating an initial text region according to the annotation information and the received configuration instruction;
[0103] An initial region processing module 300 is used to process the initial text region according to the local region processing rule to obtain a target text region;
[0104] The fusion module 400 is used to fuse the template image and the target text area according to the position information in the annotation information to generate an initial text image.
[0105] In one embodiment, the initial area processing module 300 includes: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain a target text area; the basic image operator refers to an operator that performs area position operations on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font.
[0106] In one embodiment, the stamp font processing submodule of the initial area processing module 300 includes: a pixel assignment unit, which is used to randomly select pixels from the initial text area and assign the pixels to the background color of the initial text area; an expansion and corrosion subunit, which is used to perform image expansion and image corrosion operations on the assigned initial text area to obtain a target text area.
[0107] In one embodiment, the dot matrix printing font submodule of the initial area processing module 300 includes: a grid overlay unit for overlaying a grid with the background color of the initial text area on the initial text area; and a stamp font processing submodule for processing the initial text area after the grid is overlaid to obtain a target text area.
[0108] In one embodiment, the mottled handwriting submodule of the initial area processing module 300 includes: a matrix generation unit, which is used to generate a Gaussian distribution matrix, and the size of the matrix is equal to the size of the initial text area; an acquisition subunit, which is used to obtain a preset value; a relationship establishment unit, which is used to establish a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjust the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; and a mediation processing unit, which is used to perform image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
[0109] In one embodiment, the text image synthesis device further includes: an initial text image processing module, which is used to process the initial text image according to the overall image processing rule to obtain a target text image.
[0110] In one embodiment, the initial text image processing module includes: processing the initial text image according to at least one of an image denoising operation, a local fading operator, a stamping operator and a watermarking operator to obtain a target text image; the local fading operator refers to an operator that performs brightness processing on the initial text image; the stamping operator refers to an operator that adds a stamp image to the initial text image; the watermarking operator refers to an operator that adds a watermark image to the initial text image.
[0111] In one embodiment, the local fading submodule of the initial text image processing module includes: an area acquisition unit, used to acquire the faded area and the central area of the initial text image; a brightness acquisition unit, used to acquire the maximum brightness of the pixels within the faded range; and a fading processing unit, used to process the initial text image according to the faded area, the central area and the maximum brightness to obtain a target text image.
[0112] In one embodiment, the stamping submodule of the initial text image processing module includes: a stamp acquiring unit for acquiring a stamp image; and a stamp processing unit for performing fusion processing on the stamp image and the initial text image to obtain a target text image.
[0113] In one embodiment, the watermark adding submodule of the initial text image processing module includes: an initial text area unit, used to obtain the initial text area and perform image position processing operations on the initial text area; and a fusion unit, used to fuse the processed initial text area with the initial text image to obtain a target text image.
[0114] In one embodiment, it further includes: an extraction module, which is used to extract the target text image area from the target text image according to the annotation information in the template image.
[0115] In one embodiment, the acquisition module 100 includes: a configuration file acquisition module, which is used to acquire a configuration file corresponding to a template image; a sample image acquisition module, which is used to acquire a sample image and process a target area of the sample image to obtain a corresponding template image; a labeling module, which is used to label the target area in the template image to obtain labeling information, wherein the labeling information includes at least one of a template image name, a target text area fusion position, and a text area category; and a configuration file generation module, which is used to generate a configuration file corresponding to the template image according to the labeling information.
[0116] In one embodiment, the initial region generating module 200 includes: extracting annotation information corresponding to each target region in the configuration file, and generating an initial text region according to the annotation information.
[0117] Each module in the above-mentioned text image synthesis device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module.
[0118] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.16As shown. The computer device includes a processor, a memory, a communication interface, a display screen and an input device connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be achieved through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a text image synthesis method is implemented. The display screen of the computer device can be a liquid crystal display screen or an electronic ink display screen, and the input device of the computer device can be a touch layer covered on the display screen, or a key, trackball or touchpad set on the computer device housing, or an external keyboard, touchpad or mouse, etc.
[0119] Those skilled in the art will understand that Fig.16 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0120] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the following steps when executing the computer program: obtaining a template image, wherein the template image carries annotation information; generating an initial text area according to content information in the annotation information; processing the initial text area according to a local area processing rule to obtain a target text area; and fusing the template image and the target text area according to position information in the annotation information to generate an initial text image.
[0121] In one of the embodiments, the processor executes a computer program to process the initial text area according to the local area processing rules to obtain the target text area, including: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain the target text area; the basic image operator refers to an operator that performs area position operations on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font.
[0122] In one of the embodiments, the process of processing the initial text area by the stamp font effect operator implemented when the processor executes the computer program includes: randomly selecting pixel points from the initial text area, and assigning the pixel points to the background color of the initial text area; performing image dilation operations and image erosion operations on the assigned initial text area to obtain the target text area.
[0123] In one embodiment, the process of processing an initial text area by a dot matrix printing font effect operator implemented when a processor executes a computer program includes: superimposing a grid with a background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by a stamp font effect operator to obtain a target text area.
[0124] In one of the embodiments, the process of processing an initial text area by a mottled handwriting effect operator implemented when a processor executes a computer program includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
[0125] In one embodiment, when the processor executes the computer program, the following steps are further implemented: the initial text image is processed according to the overall image processing rule to obtain the target text image. In one embodiment, the initial text image is processed according to the overall image processing rule to obtain the target text image, including: the initial text image is processed according to at least one of the image noise addition operation, the local fade operator, the seal operator and the watermark operator to obtain the target text image; the local fade operator refers to an operator that performs brightness processing on the initial text image; the seal operator refers to an operator that adds a seal image to the initial text image; the watermark operator refers to an operator that adds a watermark image to the initial text image.
[0126] In one embodiment, the process of processing an initial text image by a local fade operator implemented when a processor executes a computer program includes: obtaining a faded area and a central area of the initial text image; obtaining the maximum brightness of pixels within the faded range; and processing the initial text image according to the faded area, the central area and the maximum brightness to obtain a target text image.
[0127] In one embodiment, the process of stamping an initial text image implemented by a processor when executing a computer program and processing the initial text image by a seal operator includes: obtaining a seal image; and fusing the seal image and the initial text image to obtain a target text image.
[0128] In one of the embodiments, the process of adding a watermark operator to an initial text image implemented when a processor executes a computer program includes: obtaining an initial text area and performing an image position processing operation on the initial text area; fusing the processed initial text area with the initial text image to obtain a target text image.
[0129] In one of the embodiments, when the processor executes the computer program, the processor further implements the following steps: extracting a target text image region from the target text image according to the annotation information in the template image.
[0130] In one of the embodiments, the acquisition of a template image implemented when a processor executes a computer program includes: acquiring a configuration file corresponding to the template image; before acquiring the configuration file corresponding to the template image, including: acquiring a sample image, and processing a target area of the sample image to obtain a corresponding template image; annotating the target area in the template image to obtain annotation information, wherein the annotation information includes at least one of a template image name, a target text area fusion position, and a text area category; and generating a configuration file corresponding to the template image according to the annotation information.
[0131] In one embodiment, the generation of the initial text area according to the annotation information implemented by the processor when executing the computer program includes: extracting the annotation information corresponding to each target area in the configuration file, and generating the initial text area according to the annotation information.
[0132] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented: obtaining a template image, the template image carrying annotation information; generating an initial text area according to content information in the annotation information; processing the initial text area according to a local area processing rule to obtain a target text area; and fusing the template image and the target text area according to position information in the annotation information to generate an initial text image.
[0133] In one of the embodiments, the computer program implemented when being executed by the processor processes the initial text area according to the local area processing rules to obtain the target text area, including: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain the target text area; the basic image operator refers to an operator that performs area position operations on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font.
[0134] In one of the embodiments, the process of processing an initial text area by a stamp font effect operator implemented when a computer program is executed by a processor includes: randomly selecting pixel points from the initial text area and assigning the pixel points to the background color of the initial text area; performing image dilation operations and image erosion operations on the assigned initial text area to obtain a target text area.
[0135] In one embodiment, the process of processing an initial text area by a dot matrix printing font effect operator implemented when a computer program is executed by a processor includes: superimposing a grid with a background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by a stamp font effect operator to obtain a target text area.
[0136] In one of the embodiments, the process of processing an initial text area by a mottled handwriting effect operator implemented when a computer program is executed by a processor includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
[0137] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented. The method also includes: processing the initial text image according to the overall image processing rule to obtain the target text image. In one embodiment, processing the initial text image according to the overall image processing rule to obtain the target text image includes: processing the initial text image according to at least one of an image noise addition operation, a local fade operator, a seal operator, and a watermark operator to obtain the target text image; the local fade operator refers to an operator that performs brightness processing on the initial text image; the seal operator refers to an operator that adds a seal image to the initial text image; and the watermark operator refers to an operator that adds a watermark image to the initial text image.
[0138] In one embodiment, the process of processing an initial text image by a local fade operator implemented when a computer program is executed by a processor includes: obtaining a faded area and a central area of the initial text image; obtaining the maximum brightness of pixels within the faded range; and processing the initial text image according to the faded area, the central area and the maximum brightness to obtain a target text image.
[0139] In one embodiment, the process of stamping an initial text image implemented by a processor when a computer program is executed includes: obtaining a seal image; and fusing the seal image and the initial text image to obtain a target text image.
[0140] In one of the embodiments, the process of adding a watermark operator to an initial text image implemented when the computer program is executed by a processor includes: obtaining an initial text area and performing an image position processing operation on the initial text area; fusing the processed initial text area with the initial text image to obtain a target text image.
[0141] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: extracting the target text image area from the target text image according to the annotation information in the template image.
[0142] In one of the embodiments, the method of obtaining a template image implemented when a computer program is executed by a processor includes: obtaining a configuration file corresponding to the template image; before obtaining the configuration file corresponding to the template image, including: obtaining a sample image, and processing a target area of the sample image to obtain a corresponding template image; annotating the target area in the template image to obtain annotation information, wherein the annotation information includes at least one of a template image name, a target text area fusion position, and a text area category; and generating a configuration file corresponding to the template image according to the annotation information.
[0143] In one embodiment, the computer program, when executed by a processor, generates an initial text area according to the annotation information, including: extracting the annotation information corresponding to each target area in the configuration file, and generating the initial text area according to the annotation information.
[0144] In one embodiment, a computer program product is provided, including a computer program, which, when executed by a processor, implements the following steps: obtaining a template image, the template image carrying annotation information; generating an initial text region according to content information in the annotation information; processing the initial text region according to a local region processing rule to obtain a target text region; and fusing the template image and the target text region according to position information in the annotation information to generate an initial text image.
[0145] In one of the embodiments, the computer program implemented when being executed by the processor processes the initial text area according to the local area processing rules to obtain the target text area, including: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain the target text area; the basic image operator refers to an operator that performs area position operations on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font.
[0146] In one of the embodiments, the process of processing an initial text area by a stamp font effect operator implemented when a computer program is executed by a processor includes: randomly selecting pixel points from the initial text area and assigning the pixel points to the background color of the initial text area; performing image dilation operations and image erosion operations on the assigned initial text area to obtain a target text area.
[0147] In one embodiment, the process of processing an initial text area by a dot matrix printing font effect operator implemented when a computer program is executed by a processor includes: superimposing a grid with a background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by a stamp font effect operator to obtain a target text area.
[0148] In one of the embodiments, the process of processing an initial text area by a mottled handwriting effect operator implemented when a computer program is executed by a processor includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
[0149] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented. The method also includes: processing the initial text image according to the overall image processing rule to obtain the target text image. In one embodiment, processing the initial text image according to the overall image processing rule to obtain the target text image includes: processing the initial text image according to at least one of an image noise addition operation, a local fade operator, a seal operator, and a watermark operator to obtain the target text image; the local fade operator refers to an operator that performs brightness processing on the initial text image; the seal operator refers to an operator that adds a seal image to the initial text image; and the watermark operator refers to an operator that adds a watermark image to the initial text image.
[0150] In one embodiment, the process of processing an initial text image by a local fade operator implemented when a computer program is executed by a processor includes: obtaining a faded area and a central area of the initial text image; obtaining the maximum brightness of pixels within the faded range; and processing the initial text image according to the faded area, the central area and the maximum brightness to obtain a target text image.
[0151] In one embodiment, the process of stamping an initial text image implemented by a processor when a computer program is executed includes: obtaining a seal image; and fusing the seal image and the initial text image to obtain a target text image.
[0152] In one of the embodiments, the process of adding a watermark operator to an initial text image implemented when the computer program is executed by a processor includes: obtaining an initial text area and performing an image position processing operation on the initial text area; fusing the processed initial text area with the initial text image to obtain a target text image.
[0153] In one embodiment, when the computer program is executed by the processor, the following steps are also implemented: extracting the target text image area from the target text image according to the annotation information in the template image.
[0154] In one of the embodiments, the method of obtaining a template image implemented when a computer program is executed by a processor includes: obtaining a configuration file corresponding to the template image; before obtaining the configuration file corresponding to the template image, including: obtaining a sample image, and processing a target area of the sample image to obtain a corresponding template image; annotating the target area in the template image to obtain annotation information, wherein the annotation information includes at least one of a template image name, a target text area fusion position, and a text area category; and generating a configuration file corresponding to the template image according to the annotation information.
[0155] In one embodiment, the computer program, when executed by a processor, generates an initial text area according to the annotation information, including: extracting the annotation information corresponding to each target area in the configuration file, and generating the initial text area according to the annotation information.
[0156] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties.
[0157] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0158] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0159] The above embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A text image synthesis method, characterized in that: The method comprises: Acquire a template image, the template image carrying annotation information; the annotation information includes location information of a deleted area in a sample image, attributes of the sample image, and attributes of text in the deleted area; the attributes of the sample image include whether the deleted content has jagged edges, whether it is skipped, a text area category, and a corpus generation rule; Generate an initial text area according to the content information in the annotation information; Processing the initial text area according to the local area processing rule to obtain a target text area; Fusion of the template image and the target text region to generate an initial text image according to the position information in the annotation information; Wherein, the processing of the initial text area according to the local area processing rule to obtain the target text area includes: processing the initial text area according to at least one of a basic image operator, a stamp font effect operator, a dot matrix printing font effect operator and a mottled handwriting effect operator to obtain the target text area; the basic image operator refers to an operator that performs an area position operation on the initial text area; the stamp font effect operator refers to an operator that processes the text in the initial text area into a stamp font; the dot matrix printing font effect operator refers to an operator that processes the text in the initial text area into a dot matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text area into a mottled handwriting font; The process of processing the initial text area by the stamp font effect operator includes: randomly selecting pixels from the initial text area and assigning the pixels to the background color of the initial text area; performing image expansion and image erosion operations on the assigned initial text area to obtain a target text area; The process of processing the initial text area by the dot matrix printing font effect operator includes: superimposing a grid with the background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by the stamp font effect operator to obtain a target text area; The process of processing the initial text area by the mottled handwriting effect operator includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operations on the initial text area after the brightness adjustment to obtain a target text area.
2. The method according to claim 1, characterized in that The method further comprises: The initial text image is processed according to the overall image processing rule to obtain a target text image.
3. The method according to claim 2, characterized in that The step of processing the initial text image according to the overall image processing rule to obtain the target text image includes: The initial text image is processed according to at least one of an image denoising operation, a local fading operator, a stamping operator and a watermarking operator to obtain a target text image; the local fading operator refers to an operator that performs brightness processing on the initial text image; the stamping operator refers to an operator that adds a stamp image to the initial text image; the watermarking operator refers to an operator that adds a watermark image to the initial text image.
4. The method according to claim 3, characterized in that The process of processing the initial text image by the local fading operator includes: Get the faded area and the center area of the initial text image; Obtaining the maximum brightness of the pixels in the faded area; The initial text image is processed according to the faded area, the central area and the maximum brightness value to obtain a target text image.
5. The method according to claim 3, characterized in that: The process of processing the initial text image by the stamping operator includes: Acquire the seal image; A fusion process is performed on the seal image and the initial text image to obtain a target text image.
6. The method according to claim 3, characterized in that The process of processing the initial text image by the watermarking operator includes: Acquire an initial text area, and perform an image position processing operation on the initial text area; The processed initial text area is fused with the initial text image to obtain a target text image.
7. The method according to claim 2, characterized in that Also includes: A target text image region is extracted from the target text image according to extraction position information, wherein the extraction position information is the position of the target text region after the target text region is fused into the initial text image.
8. The method according to claim 1, characterized in that The step of obtaining a template image comprises: Get the configuration file corresponding to the template image; Before obtaining the configuration file corresponding to the template image, the method includes: Acquire a sample image, and process a target area of the sample image to obtain a corresponding template image; Annotating the target area in the template image to obtain annotation information, wherein the annotation information includes at least one of a template image name, a target text area fusion position, and a text area category; A configuration file corresponding to the template image is generated according to the annotation information.
9. The method according to claim 8, characterized in that The generating an initial text area according to the content information in the annotation information includes: Extract the annotation information corresponding to each target area in the configuration file, and generate an initial text area according to the annotation information.
10. A text image synthesis device, characterized in that: The device comprises: An acquisition module is used to acquire a template image, wherein the template image includes annotation information; the annotation information includes location information of a deleted area in a sample image, attributes of the sample image, and attributes of text in the deleted area; the attributes of the sample image include whether the deleted content has jagged edges, whether it is skipped, text area categories, and corpus generation rules; An initial region generating module, used for generating an initial text region according to the annotation information and the received configuration instructions; The initial region processing module is used to process the initial text region according to the local region processing rule to obtain the target text region; wherein, the processing according to the local region processing rule to obtain the target text region includes: processing the initial text region according to at least one of a basic image operator, a stamp font effect operator, a pin-matrix printing font effect operator and a mottled handwriting effect operator to obtain the target text region; the basic image operator refers to an operator that performs region position operation on the initial text region; the stamp font effect operator refers to an operator that processes the text in the initial text region into a stamp font; the pin-matrix printing font effect operator refers to an operator that processes the text in the initial text region into a pin-matrix printing font; the mottled handwriting effect operator refers to an operator that processes the text in the initial text region into a mottled handwriting font; the process of the initial text region being processed by the stamp font effect operator includes: Randomly select pixel points in the domain, and assign the pixel points to the background color of the initial text area; perform image expansion operation and image erosion operation on the assigned initial text area to obtain a target text area; the process of processing the initial text area by the pin-matrix printing font effect operator includes: superimposing a grid with the background color of the initial text area on the initial text area; processing the initial text area after superimposing the grid by the stamp font effect operator to obtain the target text area; the process of processing the initial text area by the mottled handwriting effect operator includes: generating a Gaussian distribution matrix, the size of the matrix is equal to the size of the initial text area; obtaining a preset value; establishing a mapping relationship between each element of the matrix and the pixel points of the initial text area, and randomly adjusting the brightness of the pixel points corresponding to the elements in the matrix that are smaller than the preset value; performing image processing operation on the initial text area after brightness adjustment to obtain the target text area; A fusion module is used to fuse the template image and the target text area to generate an initial text image according to the position information in the annotation information.
11. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 9 are implemented.
12. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
13. A computer program product, comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 9 are implemented.
Citation Information
Patent Citations
Structure feature based on Chinese painting and calligraphy seal image automatic extracting method
CN101533517A
Method and system for judging whether image is too dark or too bright
CN104700426A
Image simulation generation method for dot matrix character printing effect
CN110807823A
Picture reconstruction method based on bill template
CN112529989A