Image generation method and rare character recognition model training method

CN122949525APending Publication Date: 2026-10-20BEIJING YUANLI WEILAI SCI & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611094894.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-07-22
Publication Date
2026-10-20

AI Technical Summary

Technical Problem

[0003]现有技术通常采用人工合成图像的方式,获取带有生僻字的标注图像,然而,人工合成方式效率较低,难以快速生成大规模带有生僻字的标注图像,无法满足识别模型训练需求

Benefits of technology

[0010]根据本说明书实施例的第六方面,提供了一种计算机程序产品,包括计算机程序/指令,该计算机程序/指令被处理器执行时实现上述第一方面、第二方面或者第三方面所提供方法的步骤。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure FT_1
    Figure FT_1
  • Figure FT_2
    Figure FT_2
  • Figure FT_3
    Figure FT_3
Patent Text Reader

Abstract

This specification provides an image generation method and a rare character recognition model training method. The image generation method includes: acquiring a target image, wherein the target image includes multiple image characters, each carrying character position information; determining a character to be replaced from the multiple image characters, and determining a replacement image region from the target image based on the character position information carried by the replacement character; determining a target replacement character based on the current statistical information of multiple candidate characters; erasing the replacement character from the replacement image region, and adding the target replacement character to the replacement image region to obtain a target generated image. This method improves the generation efficiency of rare character labeled images, enabling rapid batch generation of large-scale, standardized rare character image samples, effectively solving the technical problems of scarce rare character samples in real-world scenarios, insufficient manual synthesis capacity, and inability to meet model training requirements.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments in this specification relate to the field of optical character recognition technology, and in particular to image generation methods and training methods for rare character recognition models. Background Technology

[0002] With the development of computer vision and optical character recognition technologies, various document recognition scenarios require a large number of labeled images to train recognition models. The vast majority of everyday documents contain common Chinese characters, with rare characters appearing very infrequently. Directly collecting a sufficient number of labeled images containing rare characters is costly in terms of both manpower and time.

[0003] Existing technologies typically employ artificial image synthesis to obtain labeled images containing rare characters. However, artificial synthesis is inefficient and cannot quickly generate large-scale labeled images containing rare characters, thus failing to meet the training requirements of recognition models. Summary of the Invention

[0004] In view of this, embodiments of this specification provide an image generation method. One or more embodiments of this specification also relate to a method for training a rare character recognition model, a rare character recognition method, a computing device, a computer-readable storage medium, and a computer program product, to address the technical deficiencies existing in the prior art.

[0005] According to a first aspect of the embodiments of this specification, an image generation method is provided, comprising: Acquire a target image, wherein the target image includes multiple image characters, and the image characters carry character position information; The character to be replaced is determined from the plurality of image characters, and the image region to be replaced is determined from the target image based on the character position information carried by the character to be replaced. Based on the current statistical information of multiple candidate characters, the target replacement character is determined; Erase the character to be replaced in the image area to be replaced, and add the target replacement character to the image area to be replaced to obtain the target generated image.

[0006] According to a second aspect of the embodiments of this specification, a method for training a rare character recognition model is provided, comprising: A sample image is obtained, wherein the sample image includes sample rare characters. The sample image is obtained by erasing the characters to be replaced in the image region to be replaced and adding the sample rare characters to the image region to be replaced. The sample rare characters are determined based on the current statistical information of multiple candidate rare characters. The image region to be replaced is determined from the original image based on the character position information carried by the characters to be replaced. The characters to be replaced are determined from multiple image characters in the original image. Based on the sample image and the rare characters in the sample, the parameters of the initial recognition model are adjusted to obtain a trained rare character recognition model.

[0007] According to a third aspect of the embodiments of this specification, a method for recognizing rare characters is provided, comprising: Acquire the image to be recognized; The image to be recognized is input into the rare character recognition model to obtain the rare character recognition result of the image to be recognized, wherein the rare character recognition model is trained based on the method provided in the second aspect.

[0008] According to a fourth aspect of the embodiments of this specification, a computing device is provided, comprising: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions, which, when executed by the processor, implement the steps of the methods provided in the first, second, or third aspects described above.

[0009] According to a fifth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores a computer program / instructions that, when executed by a processor, implement the steps of the methods provided in the first, second, or third aspects described above.

[0010] According to a sixth aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the steps of the methods provided in the first, second, or third aspects described above.

[0011] The image generation method provided in one embodiment of this specification acquires a target image containing multiple image characters and carrying character position information, filters the characters to be replaced from the multiple image characters, and determines the image region to be replaced based on the corresponding character position information. This eliminates the need for manual character identification and avoids the problem of low efficiency in manual screening and positioning. Simultaneously, the target replacement character is determined based on the current statistical information of multiple candidate characters, and the erasure of the character to be replaced and the addition of the target replacement character are automatically completed, achieving automatic updating of image characters. This improves the generation efficiency of annotated images of rare characters and can quickly generate large-scale, standardized rare character image samples in batches, effectively solving the technical problems of scarce rare character samples, insufficient manual synthesis capacity, and inability to meet model training requirements in real-world scenarios. Attached Figure Description

[0012] Figure 1 This is a flowchart of an image generation method provided in one embodiment of this specification; Figure 2 This is a comparison image showing the effect before and after processing by the first image generation method provided in one embodiment of this specification; Figure 3 This is a comparison diagram of the effects before and after processing by the second image generation method provided in one embodiment of this specification; Figure 4 This is a schematic diagram illustrating the generation process of an image generation method provided in one embodiment of this specification; Figure 5 This is a comparison diagram of the effects before and after processing by the third image generation method provided in one embodiment of this specification; Figure 6 This is an architecture diagram of an image generation system provided in one embodiment of this specification; Figure 7 This is a flowchart illustrating a method for training a rare character recognition model according to one embodiment of this specification; Figure 8 This is a flowchart illustrating a method for recognizing rare characters provided in one embodiment of this specification; Figure 9 This is a schematic diagram of the structure of an image generation apparatus provided in one embodiment of this specification; Figure 10 This is a schematic diagram of the structure of a training device for a rare character recognition model provided in one embodiment of this specification; Figure 11 This is a schematic diagram of the structure of a rare character recognition device provided in one embodiment of this specification; Figure 12 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation

[0013] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.

[0014] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to limit the scope of one or more embodiments of this specification. The singular forms “a,” “described,” and “the” as used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items. The term “at least one” as used in one or more embodiments of this specification means “one or more,” and “a plurality of” means “two or more.” The term “comprising” is an open-ended description and should be understood as “including but not limiting,” and may include other content in addition to what has been described.

[0015] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."

[0016] Furthermore, 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, data stored, data displayed, etc.) involved in one or more embodiments of this specification are obtained through open-source datasets or public datasets that comply with their license agreements, or are obtained with full authorization from the relevant parties. Moreover, the collection, use and processing of the relevant data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0017] First, the terms and concepts used in one or more embodiments of this specification will be explained.

[0018] Optical Character Recognition (OCR) is an image processing technology that uses computer vision algorithms to analyze image content and convert text regions within an image into editable text content. It can automatically extract text from documents, printed materials, and handwritten images and is the core foundational technology for text recognition models.

[0019] Image inpainting is a pixel-level image processing technique that automatically fills in removed or damaged target areas within an image based on information from the surrounding area. After restoration, the visual effect of the target area can be made consistent and unified with the surrounding image, achieving seamless removal of the original content. Among them, the LargeMask Inpainting model refers to an open-source, high-performance deep learning model for large mask image inpainting, which can achieve natural and consistent background restoration for large areas of text occlusion.

[0020] Data augmentation is a dataset augmentation technique for model training. It performs various modifications on the original labeled images, such as character replacement, geometric transformation, and color perturbation, to expand the total amount of data and sample diversity, thereby optimizing the scene generalization ability of the recognition model.

[0021] Balanced sampling is a character sampling strategy for generating datasets. It records the usage frequency of various characters in real time, prioritizes the selection of characters with lower usage frequency to participate in sample synthesis, balances the number of different characters generated, and prevents high-frequency characters from being generated repeatedly and low-frequency characters from having insufficient training samples.

[0022] Bounding Box (Bbox): Uses rectangular coordinates to define the position range of a single text character within an image. The standard coordinate format is (x1, y1, x2, y2). It can accurately divide the independent image region corresponding to each character in the image. Here, (x1, y1, x2, y2) represents the coordinate pair formed by the upper left and lower right corners of the rectangle, or it can represent the coordinate pair formed by the upper right and lower left corners of the rectangle.

[0023] Unicode Encoding Range: This is the basic encoding range for CJK Unified Ideographs defined by the Unicode encoding standard. This range contains only standard Chinese characters and can be used to accurately filter pure Chinese character areas in an image, effectively filtering out non-Chinese characters such as numbers, punctuation, letters, and special symbols. Specifically, \u4e00-\u9fff represents the complete range of the CJK Unified Ideographs basic range under Unicode hexadecimal encoding. This range only stores regular standard Chinese characters and does not contain numbers, punctuation, English letters, special symbols, or other characters. It can be used to filter pure Chinese character bounding boxes within an image and eliminate various non-Chinese character interference areas.

[0024] CJK Unified Ideographs: This is a character encoding area under the Unicode encoding standard that is specifically used to store Chinese, Japanese and Korean characters. The basic area of ​​this character set contains 20,992 standard Chinese characters, and the extended area contains a large number of low-frequency and rare Chinese characters, which are the character sources for the rare character dictionary of this invention.

[0025] GB2312 is a national standard encoding for a general simplified Chinese character set. This encoding includes most commonly used simplified Chinese characters, symbols, and letters used in daily life, covering the text range of regular printed documents and electronic documents. It is the basic encoding standard for regular Chinese character rendering and character filtering.

[0026] Generative Adversarial Networks (GANs) are a classic deep learning generative model that uses a generator and a discriminator to play against each other and train iteratively. They can automatically generate image samples with realistic styles and natural textures and can be used to assist in the synthesis of diverse text image data.

[0027] SynthText is an open-source tool for automatically generating text images in any background. It can automatically render text content with different fonts, sizes, and angles in any background image and automatically generate accurate text annotations. It is widely used for the rapid construction of OCR recognition datasets.

[0028] Text Rendering Data Generator (TRDG): A dedicated text image rendering and generation tool that supports custom parameters such as font, font size, color, noise, and deformation. It can generate high-quality printed text sample images in batches and is a commonly used tool for OCR model training data augmentation.

[0029] YOLO (You Only Look On) character detection model: YOLO is an end-to-end real-time object detection algorithm. YOLOv5 is a lightweight and efficient iterative version that can quickly and accurately locate text targets in images, output the bounding box coordinates of the text, and realize the automatic detection and extraction of character regions in document images.

[0030] Differentiable Binarization Network (DBNet) text line detection model: It is a high-precision text detection network based on the differentiable binarization mechanism. It can adaptively distinguish between text foreground and image background, and accurately extract curved, tilted and densely arranged text line regions in documents. It is the mainstream model for text region localization in OCR tasks.

[0031] OpenCV (Open Source Computer Vision Library) is a cross-platform open source computer vision tool library that integrates a large number of mature image processing interfaces such as image inpainting, threshold segmentation, and object preprocessing. It is computationally lightweight and easy to deploy, providing underlying algorithmic support for visual tasks such as text erasure and image preprocessing.

[0032] The Telea algorithm is a traditional image inpainting algorithm built into OpenCV. It uses neighborhood interpolation to fill in the area to be repaired by using the pixel information around the area. It can quickly erase the text content in a specified area of ​​the image and restore the background, achieving lightweight and efficient image restoration without leaving a trace. The cv2.inpaint algorithm refers to the program interface in the OpenCV library used to perform image inpainting operations. It can pass in the repair mode parameter to select to enable the Telea algorithm to complete pixel filling repair.

[0033] Otsu binarization (Otsu's Method) is an adaptive threshold segmentation image processing algorithm that can automatically calculate the optimal segmentation threshold based on the image's grayscale distribution, automatically dividing the image into text foreground and solid color background, simplifying the image structure and facilitating subsequent text region detection and character extraction.

[0034] Pillow (Python Imaging Library Fork) is a mainstream open-source image processing library for the Python language. It provides basic image operation capabilities such as image reading, canvas drawing, and color adjustment, and supports preprocessing workflows such as image text rendering and image modification. Among them, the ImageDraw.text interface represents a text drawing interface, which supports custom rendering of character content, font size, and font color at specified coordinates in the image. It is used to accurately draw target rare characters in the image replacement area.

[0035] The stroke_width parameter is a stroke width control parameter in the text rendering process. It is used to adjust the thickness of the outer contour of the character. By adapting to the stroke features of the original text, it can improve the style consistency and integration between the rendered character and the original document image. Here, stroke represents the stroke or outline, and width represents the width.

[0036] Diffusion model: This is a diffusion-based generative model and a mainstream high-precision generative artificial intelligence model. It generates image content through a multi-step inverse noise reduction process, and can achieve adaptive generation and fusion of character style and background texture, thus generating highly realistic text-synthesized images.

[0037] Mutex Lock (Mutual Exclusion Lock): A synchronization control mechanism in multi-process parallel computing, used to limit concurrent read and write operations of multiple processes on a shared character counting dictionary, to avoid counting errors and data anomalies caused by multiple processes modifying character frequency data at the same time, and to ensure the accuracy of character statistics and balanced sampling.

[0038] Character mapping table (cmap table, actor to glyph index mapping table): Set in the font file, it stores the correspondence between all characters that the font can render normally and their corresponding glyph indices. It can verify in advance whether the selected font supports the target uncommon characters and avoid abnormal boxes in rendering.

[0039] With the rapid development of computer vision and artificial intelligence technologies, OCR technology has been widely applied in scenarios such as document digitization, homework correction, and printed text recognition. OCR models are trained by learning the visual features of text regions in images, and their recognition accuracy highly depends on a massive amount of labeled training images. For commonly used Chinese characters within the GB2312 standard, sufficient labeled samples can be collected through various channels such as online text, scanned books, and photographed documents. However, rare characters appear very infrequently in natural text, and directly collecting labeled images containing various rare characters is costly. Therefore, data augmentation techniques are currently used to synthesize image samples containing rare characters to expand the training images.

[0040] Current data augmentation techniques mainly include: Plain text rendering directly renders target characters into complete images using font files. While this allows for precise control over the output character content, the generated images have a monotonous background and regular layout, resulting in significant domain differences compared to real handwritten or printed documents. GAN-based synthesis methods can generate text images with specific writing styles, but they struggle to precisely constrain the output character content. For rare, low-frequency characters with scarce samples, the generation quality is inconsistent. SynthText and other general-purpose text recognition synthesis methods only support rendering entire text regions, failing to achieve fine-grained replacement at the single-character level and lacking control over character usage frequency. Text recognition data generation tools like TRDG generate complete text lines from scratch, lacking the background texture, noise, and layout features inherent in the original document, resulting in a significant difference from real-world images. Simple character replacement methods only modify the text annotations without altering the original image pixels, leading to inconsistencies between the image and the annotation information, generating numerous noisy labels that interfere with model training.

[0041] Meanwhile, current technical solutions have the following problems: First, the character selection adopts a completely random strategy, failing to track the global usage frequency of various uncommon characters. This results in high-frequency characters being repeatedly used, while a large number of low-frequency characters consistently fail to obtain sufficient training samples, leading to inconsistent model recognition capabilities for different uncommon characters. Second, there is a lack of font compatibility verification. Different fonts only support a subset of Chinese characters, and directly rendering uncommon characters easily generates abnormal character shapes such as blank boxes, introducing incorrect training signals. Third, the images generated by various solutions are insufficient in terms of overall visual coordination between characters and background. Synthetic images differ significantly from real documents in visual features such as texture, noise, and color, making it difficult for the model to effectively transfer the learning effects from synthetic data to real document recognition scenarios.

[0042] In summary, existing methods for synthesizing images of rare characters are unable to produce high-quality training samples in batches that have a balanced character distribution, consistent image with annotation, and visually close to real-world scenes, which severely restricts the generalization ability of OCR models to recognize low-frequency rare characters.

[0043] This specification provides an image generation method. One or more embodiments of this specification also relate to a method for training a rare character recognition model, a rare character recognition method, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.

[0044] See Figure 1 , Figure 1 This specification shows a flowchart of an image generation method according to an embodiment, which specifically includes the following steps: Step 102: Obtain the target image, which includes multiple image characters and carries character position information.

[0045] It should be noted that a target image refers to an image containing multiple image characters, used to carry the character information of these characters. The target image can accurately obtain the information of each image character and its position. The target image can be a scanned image obtained from the digitization of a paper document, or a screenshot of an interface containing image characters taken from an electronic device screen. For example, a target image can be a scanned copy of a paper document containing multiple lines of image characters. This image is divided into image character areas and a background area. The background area can carry real-world scene features such as paper texture and ink noise, and each image character corresponds to its own unique position information.

[0046] The image character refers to an independent text unit obtained after recognition in the target image, and each image character corresponds to a single text in the target image. The image character can be a Chinese character, such as a commonly used Chinese character or a rarely-used Chinese character; it can also be an English letter, an Arabic numeral, a punctuation mark or other recognizable text symbols. For example, the image character may be each Chinese character such as "xue", "xi", and "yu" obtained after recognition in the target image.

[0047] The character position information refers to coordinate data used for representing the spatial position of the image character in the target image, and the character position information is used for establishing a mapping relationship between each image character in the target image and its corresponding spatial position. The character position information may be a coordinate representation of a rectangular bounding box, for example, a coordinate pair (x1, y1, x2, y2) formed by the top-left corner coordinate and the bottom-right corner coordinate is used to calibrate the region where the text is located; it may also be a combined representation of the center point coordinate, width and height of the text region; and it may also be any coordinate form that can uniquely determine the region where the text is located, such as polygon vertex coordinates. For example, the character position information may be the rectangular bounding box coordinates (x1, y1, x2, y2) of each individual character output after the image is detected by a character detection model.

[0048] In practical applications, there are various implementation manners for acquiring the target image, which are specifically selected according to actual situations, and no limitation is made to this in the embodiments of this specification. In a possible implementation manner of this specification, the target image may be directly read from a local storage device or a device memory, and after being read, character detection and recognition processing may be performed on the target image to obtain a plurality of image characters and character position information thereof. In another possible implementation manner of this specification, a processed target image sent by an external device may be received through a network interface, and the target image already carries a plurality of image characters and corresponding character position information, so that there is no need to perform the character detection and recognition process locally.

[0049] In an optional embodiment of this specification, the foregoing acquiring a target image may include the following steps: Acquire a target image; Perform character position detection on the target image to obtain character position information, and determine to-be-detected image regions corresponding to the character position information respectively; Perform character recognition on the to-be-detected image regions respectively to obtain a plurality of image characters.

[0050] It's important to note that character location detection refers to the process of locating characters in a target image using a character detection model. Character location detection determines the positional information of each character in the image. It can be implemented using deep learning-based object detection models, traditional image processing methods, or a combination of text line detection models and character segmentation. For example, character location detection can use the YOLO character detection model to detect characters in the target image and output the bounding box coordinates for each character.

[0051] The image region to be detected refers to the image region in the target image corresponding to the character position information. Each image region to be detected contains an independent image character. The image region to be detected can be the image region bounded by the rectangular bounding box corresponding to the character position information, or it can be the image region obtained by appropriately expanding or shrinking the rectangular bounding box. For example, the image region to be detected can be the rectangular region bounded by the bounding box coordinates (x1, y1, x2, y2) output by the character position detection model.

[0052] Character recognition refers to the process of identifying characters in an image region to be detected. Character recognition can be achieved using OCR technology, a character classification model based on a convolutional neural network, or other character recognition algorithms. For example, character recognition can involve applying OCR technology to the image region to be detected.

[0053] In practical applications, there are various ways to perform character position detection on a target image and obtain character position information. The specific method chosen depends on the actual situation, and the embodiments in this specification do not impose any limitations on this. One possible implementation in this specification is to use a deep learning-based target detection model to perform character position detection on the target image. The target image is input into the target detection model, which directly outputs the bounding box coordinates of each text unit in the image as character position information. The corresponding image region to be detected is then cropped based on these bounding box coordinates. Another possible implementation in this specification is to first use a text line detection model to determine each line of text region in the target image, and then perform character segmentation within each text line region to obtain the position information of each single character, thereby obtaining the character position information and the corresponding image region to be detected.

[0054] For example, in a homework grading scenario, the image of a student submitting a multiple-choice Chinese homework assignment is used as the target image. The YOLOv5 model is called to perform character position detection on the target image, outputting bounding boxes (x1, y1, x2, y2) corresponding to all characters in the image. The image region to be detected for each character is obtained based on the bounding box coordinates. All image regions to be detected are then batch-transmitted into an OCR system to obtain the text content corresponding to each region. All bounding box coordinates are matched one-to-one with the text content obtained from the OCR system to generate structured data in the format `matched_text`. The specific output format is as follows: { "image_path":" / path / to / document.jpg", "matched_text":" <box-0>study <box-1>habit <box-2>ng...", "filtered_bboxs":[[x1,y1,x2,y2],[x1,y1,x2,y2],...] } wherein image_path represents the storage path of the target image, the storage path is / path / to / document, and the saving format of the image is .jpg. matched_text represents the text content of each image character marked with a bounding box label, arranged in the reading order, and filtered_bboxs represents the bounding box coordinates corresponding to each image character. Through the above output, each image character in the target image carries corresponding character position information. Please refer to Figure 2 , Figure 2 which shows the effect comparison diagram before and after processing by the first image generation method provided in an embodiment of this specification. As shown in Figure 2 , the left side is the input image that has not undergone character detection and recognition processing, and all screen contents such as test paper questions, texts, and attached images are completely retained in the image. The right side is the corresponding output image after character position detection and character recognition processing are performed on the input image. In the diagram on the right, each closed rectangular border is a bounding box corresponding to the character position information, each border encloses one image character individually, and the bounding box is used to accurately define the to-be-detected image area of the image character within the target image.

[0055] By applying the solution of the embodiments of this specification, through performing character position detection on the target image, the spatial position of each image character can be automatically identified and accurately located, and then by performing character recognition on each to-be-detected image area, the image character corresponding to each position can be accurately obtained, so as to establish an accurate correspondence between the character position and the image character, such that each image character in the target image carries usable character position information.

[0056] Step 104: Determine a to-be-replaced character from the multiple image characters, and determine a to-be-replaced image area from the target image according to the character position information carried by the to-be-replaced character.

[0057] It should be noted that the to-be-replaced character refers to an image character selected from the multiple image characters that needs to undergo character replacement. The to-be-replaced character can be any image character in the target image, such as common Chinese characters, low-frequency Chinese characters, or other recognizable text symbols. The determination of the to-be-replaced character can be determined based on any one or a combination of multiple strategies such as a character type screening rule, the spatial distribution of characters in the image, and the arrangement order of the characters. For example, the to-be-replaced character may be a randomly selected Chinese character "yu" from multiple image characters in a target image containing Chinese homework content.

[0058] The to-be-replaced image region refers to an image region in the target image corresponding to the character position information carried by the to-be-replaced character. The to-be-replaced image region may be an image region framed by a bounding box directly corresponding to the character position information, or an image region obtained by expanding or shrinking the bounding box. For example, the to-be-replaced image region may be a rectangular region defined by the bounding box determined from the target image according to the bounding box coordinates (x1,y1,x2,y2) of the character "语".

[0059] In practical applications, there may be multiple implementations for determining the to-be-replaced character from a plurality of image characters, which are specifically selected according to the actual application scenario, and the embodiments of this specification do not make any limitation on this. In one possible implementation of this specification, any image character in the target image may be randomly selected as the to-be-replaced character. In another possible implementation of this specification, the spacing between adjacent image characters may be calculated according to the respective character position information of the plurality of image characters, image characters with a spacing greater than a preset spacing threshold are taken as candidate characters, and the to-be-replaced character is selected from the candidate characters.

[0060] In practical applications, there may be multiple implementations for determining the to-be-replaced image region from the target image according to the character position information carried by the to-be-replaced character, which are specifically selected according to the actual application scenario, and the embodiments of this specification do not make any limitation on this. In one possible implementation of this specification, the image character carries character position information, and after the to-be-replaced character is determined, the corresponding character position information is directly called, so that the corresponding to-be-replaced image region can be determined in the target image. In another possible implementation of this specification, character region segmentation and pixel recognition may be performed on the entire target image to match and locate the image range where the to-be-replaced character is located, so as to determine the to-be-replaced image region.

[0061] For example, in a target image containing Chinese homework content, one character "语" is randomly selected from a plurality of image characters as the to-be-replaced character, and then according to the bounding box coordinates of the character "语", the rectangular region where the character "语" is located in the target image is determined as the to-be-replaced image region.

[0062] In an optional embodiment of this specification, the foregoing determining the to-be-replaced character from a plurality of image characters may include the following steps: Determine the reading order of the plurality of image characters according to the character position information; Determine the to-be-replaced character from the plurality of image characters based on the reading order.

[0063] It should be noted that the reading order refers to the spatial arrangement of multiple image characters based on their respective character position information. The reading order characterizes the natural arrangement logic of each image character within the target image. The reading order can be based on the vertical position of the characters in the image from top to bottom and the horizontal position from left to right, or it can be arranged according to other preset directions. For example, the reading order could be obtained by first assigning each image character to its corresponding line segment using a text line detection model, then arranging the characters within each line segment from left to right according to their horizontal position, and finally arranging them from top to bottom according to the vertical position of the line segments.

[0064] For example, in the scenario of generating homework correction samples, all characters in a target image carry bounding box character position information (x1, y1, x2, y2). The character detection model directly outputs an unordered set of bounding boxes, and the arrangement order is randomly generated by the model's detection confidence, which cannot match human reading logic. To generate an ordered character sequence that conforms to document reading habits, a line segment detection process is performed based on the character position information of each image character to determine a unified reading order for all image characters. First, the DBNet text line detection model is called to infer and generate a line-level segmentation mask for the entire target image. Then, morphological dilation is performed on the generated line-level segmentation mask to widen the region corresponding to each line of text, merging the connected regions of characters whose horizontal x-coordinates belong to the same text line. Subsequently, based on the geometric inclusion relationship between each bounding box and the mask region, the bounding box corresponding to each image character is divided into the corresponding line segment. For all line segments, vertical sorting is performed based on the y-coordinate of the segment center to determine the top-to-bottom arrangement order of the text in each line. For all Bboxes within the same line segment, horizontal sorting is performed based on their respective x-coordinates to determine the left-to-right arrangement order of the characters within a single line. Overlap is determined for adjacent line segments. If the overlap between two line segments in the y-axis direction exceeds 30% and their horizontal positions are adjacent to each other, the two line segments are merged into a complete single line to eliminate the problem of text line segmentation.

[0065] After sorting all bounding boxes and generating a standard reading order, character filtering is performed based on the ordered bounding box list to determine the final characters to be replaced. The filtering rules are as follows: only bounding boxes corresponding to Chinese characters within the Unicode encoding range \u4e00-\u9fff are retained, while non-Chinese characters such as numbers and punctuation are filtered out, and bounding boxes with overlapping areas are removed. A 2-pixel (2px) safety margin is reserved between each character bounding box to avoid interference between character areas. From the ordered bounding box list, a preset number of image characters are randomly selected as characters to be replaced. For each selected character to be replaced, the bounding box coordinates of its bounding box are read, and a corresponding rectangular pixel block is divided in the target image based on the coordinate values. This block is the image area to be replaced, and each character to be replaced uniquely corresponds to an independent and non-overlapping image area to be replaced.

[0066] Please refer to Figure 3 , Figure 3 This specification shows a comparison of the effects before and after processing using the second image generation method provided in one embodiment. Figure 3 As shown, the left side is the input image without line segment sorting. The character regions corresponding to each character in the image are not marked in an ordered manner, and the character arrangement is only the result of random detection by the model. The right side is the output image after line segment sorting and character filtering based on character position information. It can be seen that all the characters in the image have been neatly arranged in a reading order from top to bottom and from left to right. At the same time, the characters in the darkened box in the image represent the characters to be replaced after filtering.

[0067] The solution implemented in this specification determines the reading order of multiple image characters based on character position information, arranging the originally disordered characters into an ordered sequence according to human reading habits. This ensures that the order of characters is consistent with the presentation order in the actual document. Then, based on the reading order, the character to be replaced is determined from the multiple image characters. This ensures that the selection of the character to be replaced conforms to the reading logic of the document and avoids the problem of unreasonable replacement positions caused by random selection.

[0068] Step 106: Determine the target replacement character based on the current statistical information of multiple candidate characters.

[0069] It should be noted that candidate characters refer to selectable characters, serving as the source of alternative content for the replacement operation. Candidate characters can be one or more characters, including rare characters or a mixture of rare and common characters. Candidate characters are used to select the target replacement character from among them to replace the character to be replaced in the image region. For example, candidate characters can be rare characters that have been filtered and meet the replacement rules.

[0070] The current statistical information refers to quantitative data on the usage status of each candidate character at the current moment, which is used to characterize the frequency or number of times each candidate character has been selected in the past processing process. The current statistical information may include the cumulative number of times each candidate character has been selected as the target replacement character and completed the replacement, and may also include information such as the frequency, proportion, or the time of the most recent use of each candidate character within a preset time period. For example, the current statistical information may be a numerical record of the number of times each candidate character has been used, for example, the rarely-used Chinese character "龘" has been used 10 times.

[0071] The target replacement character refers to the candidate character finally selected from a plurality of candidate characters, which serves as the specific content of the replacement operation and is used to replace the original to-be-replaced character in the to-be-replaced image region. The target replacement character can be any rarely-used character or common character. For example, the target replacement character may be the character "龘" that is finally selected from a plurality of candidate characters according to the current statistical information of each candidate character.

[0072] In practical applications, there may be multiple implementations for determining the target replacement character according to the current statistical information of a plurality of candidate characters, which are specifically selected according to the actual application scenario, and the embodiments of this specification do not make any limitation on this. In a possible implementation of this specification, the current statistical information respectively corresponding to the plurality of candidate characters may be compared, and the candidate character with the lowest current statistical information value may be directly determined as the target replacement character, that is, the candidate character with the least number of uses is preferentially selected. In another possible implementation of this specification, one may be randomly selected from the first N candidate characters with the lowest current statistical information values as the target replacement character, where N is a preset positive integer, for example, N is 10. This approach introduces a certain degree of randomness while ensuring balance, and can increase the diversity of generated images.

[0073] Exemplarily, the candidate characters are 1000 pre-screened rarely-used Chinese characters, each corresponding to a piece of current statistical information, which records the cumulative number of times the rarely-used Chinese character has been selected as the target replacement character in the current data production process. After comparing the cumulative counts of each rarely-used Chinese character, one is randomly selected from the first 10 rarely-used Chinese characters with the lowest cumulative counts. Assuming the selected character is "龘", "龘" is determined as the target replacement character.

[0074] Step 108: Erase the to-be-replaced character in the to-be-replaced image region, and add the target replacement character to the to-be-replaced image region to obtain a target generated image.

[0075] It should be noted that the target generated image refers to the image obtained after the character replacement processing is completed. The content of the image region to be replaced in the target generated image is changed from the character to be replaced to the target replacement character, while other regions in the target generated image except the image region to be replaced are consistent with the target image. For example, the target generated image may be an image containing the character "龘" obtained by erasing the region where the character "语" is located in the target image and then re-adding the character "龘".

[0076] In practical applications, there may be multiple implementations of erasing the character to be replaced in the image region to be replaced, which are specifically selected according to the actual application scenario, and the embodiments of this specification do not make any limitation on this. In a possible implementation of this specification, based on the determined image region to be replaced, the pixels of the character to be replaced in the region may be covered and erased as a whole according to the pixel range of the region. In another possible implementation of this specification, character pixels and background pixels may be distinguished through pixel comparison, only the foreground pixels of the character to be replaced are accurately removed, and the original image background texture and noise details are retained, so as to achieve fine character erasure.

[0077] In practical applications, there may be multiple implementations of adding the target replacement character to the image region to be replaced to obtain the target generated image, which are specifically selected according to the actual application scenario, and the embodiments of this specification do not make any limitation on this. In a possible implementation of this specification, the corresponding glyph data may be obtained from the font file based on the encoding of the target replacement character, the adapted font size is calculated according to the size of the image region to be replaced, and then the glyph is rendered into an image and drawn into the image region to be replaced. In another possible implementation of this specification, the image block corresponding to the target replacement character may be obtained from a pre-stored character image library, and the image block is scaled to a size adapted to the image region to be replaced and then embedded into the erased region.

[0078] Exemplarily, the image region to be replaced is a rectangular region where the character "语" is located, the character "语" in the region is erased, the target replacement character "龘" is rendered into a glyph adapted to the size of the region by using the font file, and the rendered image of the character "龘" is overlaid on the erased region, so as to finally obtain the target generated image containing the character "龘".

[0079] In an optional embodiment of this specification, the foregoing erasing the character to be replaced in the image region to be replaced may include the following steps: Parse the image region to be replaced, and determine an erased sub-region and a non-erased sub-region, where the erased sub-region is a sub-region where the character to be replaced is located in the image region to be replaced; Erase the erased sub-region according to the region attribute information of the non-erased sub-region.

[0080] It should be noted that the erase sub-region refers to the region separated from the image region to be replaced. The erase sub-region can be the area occupied by the character to be replaced, or it can be a region containing feathered pixels at the edge of the character to be replaced; the erase sub-region is used to accurately locate the area in the image that needs to be pixel-cleared. For example, the erase sub-region can be the pixel area occupied by a single black ink pixel of a Chinese character within the area to be replaced in the work image.

[0081] The non-erasable sub-region refers to the area within the image to be replaced, excluding the erasable sub-regions. The non-erasable sub-region can be the paper background area surrounding the character to be replaced, blank pixel areas, or background areas containing slight paper texture and ink noise; the non-erasable sub-region provides the original background features of the area to be replaced. For example, within a single character area of ​​the work image, the non-erasable sub-region could be the pixel area corresponding to the pure white paper background and subtle paper texture surrounding the Chinese character.

[0082] Region attribute information refers to the attribute information that can characterize non-erased sub-regions. Region attribute information can be pixel grayscale values, color channel values, texture distribution characteristics, pixel noise characteristics, background brightness parameters, etc.; region attribute information is used to objectively characterize the inherent visual features of the local image background. For example, region attribute information can be the average grayscale value of the paper background color and the subtle texture distribution characteristics of the non-erased sub-region of the work image.

[0083] In practical applications, there are various ways to erase sub-regions based on their regional attribute information. The specific method chosen depends on the actual situation, and this specification does not impose any limitations on the embodiments. One possible implementation in this specification is to use OpenCV's Telea algorithm for erasure and repair. Another possible implementation is based on a deep learning inpainting model, such as the LaMa model, which offers better repair results but suffers from slower inference speed. Yet another possible implementation uses a simple scheme of mean fill and Gaussian blur fill, which is faster but results in poorer image background consistency. This scheme can be flexibly selected based on actual computing power and image quality requirements.

[0084] For example, in the scenario of generating homework correction samples, for the single-character image region to be replaced in the test paper image, the image region is first analyzed pixel by pixel. Different pixel types within the region are distinguished by pixel threshold segmentation. The sub-region where the character to be replaced is located is determined as the erasure sub-region. The background pixel region around this region, which only contains the paper background color, paper texture and slight noise, is determined as the non-erasure sub-region. Then, the grayscale value, texture distribution, background brightness and other regional attribute information of the non-erasure sub-region are extracted. The OpenCV Telea repair algorithm, namely the cv2.inpaint algorithm, is further called to perform seamless filling and repair of the erasure sub-region. The algorithm is configured with inpaint_expand. The algorithm has two key parameters: inpaint_expand and inpaint_radius. Inpaint_expand is the number of pixels the bounding box expands, with a default value of 1, which minimizes the interference of the erasure operation on the surrounding valid characters. Inpaint_radius is the pixel search radius of the repair algorithm, with a default value of 1, which enables fast and accurate repair of local areas. The algorithm relies on the pixel information of the surrounding non-erased sub-regions to fill pixels and complete textures in the entire erased sub-region. The repaired erased sub-region can completely correspond to the background texture, color, and natural noise features of the target image. The pixel features and texture features of the repaired area and the surrounding non-erased sub-regions are consistent, and the overall image is visually coherent.

[0085] The solution implemented in this specification analyzes the image region to be replaced, accurately determining the erased sub-region where the character to be replaced is located and the non-erasable sub-region where the background is located. Then, the erased sub-region is erased according to the region attribute information of the non-erasable sub-region, so that the erasing operation can be accurately applied to the region where the character is located. At the same time, the visual characteristics of the surrounding background region are referenced during the erasing process, so that the erased region can be visually blended naturally with the surrounding background.

[0086] In one optional embodiment of this specification, before parsing the image region to be replaced and determining the erased sub-region and the non-erased sub-region, the following steps may be included: Expand the region of the image to be replaced to obtain the expanded region of the image to be replaced. For the above-mentioned image region to be replaced, determining the erased sub-region and the non-erased sub-region can include the following steps: The expanded image region to be replaced is analyzed to determine the erased and non-erased sub-regions.

[0087] It should be noted that the expanded image region to be replaced refers to the area formed by expanding the boundary of the original image region by a certain number of pixels. The expanded image region to be replaced can be a uniformly symmetrically expanded rectangular region, or an irregular region obtained by asymmetrically fine-tuning the boundaries as needed. The expanded image region to be replaced is used to expand the sampling range of the local image, covering the complete background pixels surrounding the target character. For example, the expanded image region to be replaced can be a magnified pixel region obtained by uniformly expanding the original single-character rectangular region outward by 1 pixel.

[0088] In practical applications, there are various ways to expand the image region to be replaced, and the specific method should be selected according to the actual situation. This specification does not limit the specific implementation. One possible implementation involves uniformly expanding the four boundaries of the original image region to be replaced by a fixed number of pixels to generate an expanded image region to be replaced. Another possible implementation involves adaptively calculating the expansion pixel amount based on the image resolution and character size, dynamically adjusting the expansion range for different sized regions to be replaced, and obtaining a suitable expanded image region to be replaced.

[0089] For example, in the scenario of generating homework correction samples, for the original single-character image region to be replaced in the test paper image, a region expansion operation is first performed. According to the preset inpaint_expand parameter, the original Bbox region is expanded outward by 1 pixel to obtain the expanded image region to be replaced, effectively expanding the sampling range of local background pixels. Pixel analysis is performed on the expanded image region to be replaced. Different pixel types within the region are distinguished by pixel threshold segmentation. The sub-region where the character to be replaced is located is determined as the erasure sub-region, and the background pixel region around this region containing only the paper background color, paper texture, and slight noise is determined as the non-erasure sub-region, thus completing the sub-region identification and segmentation operation of the expanded image region.

[0090] By applying the solution in the embodiments of this specification, the sampling range of local background pixels can be effectively expanded by pre-expanding the area of ​​the image to be replaced, providing more sufficient and complete information on the surrounding background pixels for image restoration, ensuring the accuracy of subsequent sub-region division and pixel erasure restoration, and further improving the natural blending effect of the image background after character erasure.

[0091] The solution described in this specification involves acquiring a target image containing multiple image characters and their positional information, filtering characters to be replaced from these characters, and determining the image region to be replaced based on the corresponding character positional information. This eliminates the need for manual character identification, thus avoiding the low efficiency of manual character selection and positioning. Simultaneously, the target replacement character is determined based on the current statistical information of multiple candidate characters, and the erasure of the character to be replaced and the addition of the target replacement character are automatically completed, achieving automatic updating of image characters. This improves the generation efficiency of annotated images for rare characters and enables the rapid batch generation of large-scale, standardized rare character image samples. It effectively solves the technical problems of scarce rare character samples, insufficient manual synthesis capacity, and inability to meet model training requirements in real-world scenarios.

[0092] In one optional embodiment of this specification, before determining the target replacement character based on the current statistical information of multiple candidate characters, the following steps may be included: Acquire an auxiliary image, wherein the auxiliary image includes multiple auxiliary characters; Frequency statistics are performed on multiple auxiliary characters to obtain statistical information corresponding to each auxiliary character. Based on statistical information, multiple candidate characters are identified from a number of auxiliary characters.

[0093] It should be noted that the auxiliary image is an image containing a large number of auxiliary characters, used for extracting these characters. The auxiliary image can be a scanned image of a dictionary containing rare characters, or it can be an image of an exam paper, ancient book, or regular text material. The auxiliary image contains a large number of common Chinese characters and various low-frequency rare Chinese characters, enabling batch extraction of individual character units within the image as the original material for selecting and replacing target characters. For example, the auxiliary image can be an image obtained by scanning a dictionary containing a large number of rare characters.

[0094] Auxiliary characters refer to independent text units extracted from auxiliary images. Auxiliary characters can be commonly used Chinese characters, low-frequency rare characters, or image text units such as numbers and punctuation marks. For example, auxiliary characters can be all rare characters identified from an image scanned from a rare character dictionary.

[0095] Statistical information refers to data obtained by quantifying the frequency of auxiliary characters within auxiliary images, used to objectively characterize the distribution of each type of auxiliary character. Statistical information can be quantitative parameters such as the total number of times each auxiliary character appears in all auxiliary images, or its percentage of occurrence frequency; it serves as the basis for selecting candidate characters. For example, statistical information could be the cumulative number of times each rare Chinese character appears in a rare character dictionary image.

[0096] In practical applications, there are various ways to perform frequency statistics on multiple auxiliary characters to obtain statistical information. The specific method should be selected based on the actual situation, and the embodiments in this specification do not impose any limitations on this. One possible implementation involves traversing all auxiliary images to identify all auxiliary characters, accumulating the occurrence count of each auxiliary character in real time during the traversal, and finally outputting the cumulative occurrence count of each character as statistical information. Another possible implementation uses a completely random sampling scheme without frequency tracking. This method is logically simple but cannot guarantee a balanced selection of various character types. Yet another possible implementation employs a course-learning sampling strategy, prioritizing high-frequency characters and gradually increasing the proportion of low-frequency characters during training.

[0097] For example, in the scenario of generating homework samples, a balanced sampling strategy based on global character usage statistics is adopted to construct a candidate character set. First, a dictionary of rare characters is constructed to determine candidate characters. The specific process is as follows: First, data collection is completed, collecting a large-scale general OCR annotated image dataset as statistical material, totaling approximately 37 million OCR image records. The dataset consists of regular image data of daily test papers, documents, and text, mainly featuring commonly used Chinese characters, without bias towards rare characters. Some extremely low-frequency characters do not appear in the dataset, which can realistically reflect the actual distribution of Chinese characters in natural scenes. Second, the total number of occurrences of each Chinese character recognized by all general OCR image data is accumulated for each character, and the total number of occurrences of each Chinese character in natural scenes is counted. A total of 21,042 different Chinese characters were counted, with a total occurrence count of approximately 1.02 billion. Third, a frequency threshold of 1000 times is preset, and Chinese characters with a total occurrence count below this threshold are judged as rare characters, that is, commonly used characters are automatically distinguished from rare characters based on data frequency. In the 37 million general material data entries, characters appearing less than 1000 times indicate extremely low exposure in real-world scenarios, classifying them as rare characters. Fourth, based on a frequency threshold, characters appearing less than 1000 times are compiled and organized, resulting in a rare character set of 16740 characters, which serves as a candidate character set for subsequent image replacement. Candidate characters can be sorted by frequency from highest to lowest and a pure character list is output for subsequent image data enhancement. This frequency threshold can be flexibly adjusted according to the total amount of material; when the overall dataset size changes, the threshold can be adaptively modified to values ​​such as 500 or 300 times. After completing the frequency statistics and filtering of all Chinese characters, multiple candidate characters are finally obtained for the subsequent balanced selection of target replacement characters, completing the construction of the rare character dictionary.

[0098] By applying the solutions of the embodiments of the present specification, through performing frequency statistics on the auxiliary characters in the auxiliary image, low-frequency characters that appear less frequently in real scenes can be identified, and then candidate characters are determined from the auxiliary characters based on the statistical information, so that the selection of candidate characters no longer relies on subjective judgment, but is based on objective filtering supported by real data, ensuring that the candidate character set can accurately cover the low-frequency characters in real scenes.

[0099] In an optional embodiment of the present specification, before adding the target replacement character to the image region to be replaced to obtain the target generated image, the following steps may further be included: The target replacement character is adjusted based on the character attribute information of the target image to obtain an adjusted target replacement character, wherein the character attribute information includes at least one of color, font, font size, and glyph; Adding the target replacement character to the image region to be replaced to obtain the target generated image may include the following steps: The adjusted target replacement character is added to the image region to be replaced to obtain the target generated image.

[0100] It should be noted that the character attribute information refers to a set of characteristic parameters that can characterize the inside of the target image. The character attribute information may be any one or a combination of multiple of text pixel color, printed font type, text size and font size, and stroke outline glyph; the character attribute information is used to completely restore the appearance characteristic reference of the text in the original image. For example, the character attribute information may be the characteristic parameters corresponding to the black ink color value, Song typeface, and 12-point font size of the printed text in the test paper image.

[0101] The adjusted target replacement character refers to a text pixel material obtained by completing adaptation and modification of appearance parameters with reference to the character attribute information of the target image. The adjusted target replacement character may be a rendered character image that matches one or more features of the color, font size, font, and glyph of the original image; the adjusted target replacement character is used to keep consistent with the visual style of the original text in the image region to be replaced. For example, the adjusted target replacement character may be a "dá" character image block rendered to match the Song typeface, 12-point font size, and black ink color value of the test paper.

[0102] In practical applications, there are various ways to adjust the target replacement character based on the character attribute information of the target image. The specific method is selected according to the actual situation, and the embodiments in this specification do not limit this. In one possible implementation, the character attribute information corresponding to the area of ​​the image to be replaced is extracted, and the target replacement character is re-rendered according to the color, font, font size, and glyph parameters corresponding to the information to obtain the adjusted target replacement character. In another possible implementation, a standard style target replacement character image is pre-rendered, and then the character image is color-mapped, scaled, and font deformed according to the character attribute information to obtain the adjusted target replacement character adapted to the style of the original image.

[0103] For example, in the scenario of generating homework correction samples, after erasing characters from the image area to be replaced, a complete character re-rendering adjustment operation is performed on the target replacement character based on the character attribute information of the target image. This operation consists of three parts: color estimation, font selection and font size adaptation, and rendering execution. The first part is color estimation. Otsu binarization is performed on the Bbox area corresponding to the image area to be replaced. The average gray value of the foreground pixels of the text in the area is used as the text color reference. A controllable random perturbation of ±12 is superimposed on this reference gray value to simulate the natural color difference of text in paper printing, thereby obtaining the text color attributes that match the original image. The second part is font selection and font size adaptation. Any font such as KaiTi, HeiTi, or FangSong is randomly selected from the local font directory as the matching font. The font size is adaptively calculated based on the length and width of the Bbox area to ensure that the rendered character completely fills the area and does not exceed the boundary range. At the same time, the character is centered inside the Bbox and a small random position offset is applied to restore the visual effect of the uneven layout of the real exam paper. The third part is the rendering execution, which calls the ImageDraw.text interface of the Pillow library to render the target replacement character to the corresponding pixel position. The stroke_width parameter can also be used to configure the character stroke thickening effect as needed. After the above process, the adjusted target replacement character is obtained, which matches the visual features of the original image in terms of font, font size, color and position. The adjusted target replacement character is then filled into the erased area of ​​the image to be replaced to obtain the target generated image.

[0104] By applying the solution of the embodiments of this specification, the target replacement character is adapted and adjusted by the character attribute information of the target image, so that the adjusted target replacement character can be consistent with the appearance of the original text in the original image in terms of font, font size, color and font shape. After the adjusted character is filled into the area of ​​the image to be replaced, the difference in visual style between the old and new text is eliminated, and the naturalness of the fusion of the local replacement area of ​​the image is improved.

[0105] In one optional embodiment of this specification, after adding the target replacement character to the image area to be replaced and obtaining the target generated image, the following steps may be further included: Based on the image attribute information of the target image, the target generated image is adjusted to obtain the adjusted target generated image, wherein the image attribute information includes at least one of image sharpness and character sharpness.

[0106] It should be noted that image attribute information refers to image parameter information that can characterize the target image. Image attribute information can be parameters such as the overall image sharpness or the edge sharpness of text, or a combination of sharpness and clarity. Image attribute information is used as a reference benchmark for post-processing optimization and adjustment of the image. For example, image attribute information can be the overall sharpness value of the target image and the edge sharpness characteristics of printed characters within the image.

[0107] In practical applications, there can be multiple ways to obtain the adjusted target generated image, and the specific choice depends on the actual application scenario. This specification does not impose any limitations on this method. In one possible implementation, the target generated image is adjusted based on the image attribute information of the target image to obtain the target generated image. In another possible implementation, a style transfer network can be used to adapt the rendered characters to the overall style of the document image. Yet another possible implementation uses a diffusion model to complete conditional image generation; however, both of these methods require the introduction of additional network models, increasing deployment dependencies and inference time.

[0108] For example, in the scenario of generating job samples, after erasing the character to be replaced and rendering and filling the target replacement character, an initial target generated image is obtained. The image attribute information of the original target image, including sharpness and character sharpness, is read. Based on the image quality features of the original image, post-processing fusion adjustment is performed on the target generated image, specifically performing three operations. First, a small Gaussian blur with a radius between 0.3 and 0.7 is applied to the character rendering area to weaken the overly sharp edges of the newly rendered characters. Second, a light Gaussian noise with a standard deviation between 1.0 and 2.0 is injected into the rendering area to replicate the sensor noise generated during the real image shooting process. Third, the Gaussian blur and noise are limited to the character rendering area, controlling the smooth transition between the processed area and the surrounding original pixels, eliminating the visual disconnect between the rendered characters and the original background. After all adjustment operations are completed, the overall image sharpness and character sharpness remain consistent with the original target image, finally obtaining an adjusted target generated image with uniform image quality and natural fusion.

[0109] By applying the solution of the embodiments in this specification, the generated image is adapted and adjusted based on the image attribute information such as the clarity and character sharpness of the original target image. This can unify the image quality features of the replacement area and the original image as a whole, eliminate the problems of harsh edges of rendered characters and inconsistent distribution of noise in the image, avoid abrupt changes in local image quality after character replacement, and improve the similarity between the synthesized image and the real captured image.

[0110] In one optional embodiment of this specification, before adding the target replacement character to the image area to be replaced and obtaining the target generated image, the following steps may be included: Lock the current statistics of the target replacement character; After adding the target replacement characters to the image area to be replaced and obtaining the target generated image, the following steps may also be included: Update the current statistics of the target replacement character, and unlock the current statistics after the update is complete.

[0111] In practical applications, there are multiple ways to lock the current statistical information of the target replacement character. The specific method should be chosen based on the actual situation, and this specification does not impose any limitations on this approach. One possible implementation in this specification is to use data field marking to add a lock flag to the statistical data corresponding to the currently selected target replacement character, prohibiting data reading, writing, and modification while the data is locked. Another possible implementation in this specification is to use a thread lock mechanism to lock the memory resources occupied by the statistical data of the target replacement character, avoiding conflicts from multiple concurrent tasks.

[0112] For example, in a scenario of parallel generation of large-scale job samples, a multi-process sharing mechanism is adopted to support large-scale parallel data production. A dictionary of rare characters is loaded into `shared_dict` maintained by `multiprocessing.Manager`, and the initial usage count for each candidate character in the dictionary is set to 0. Here, `multiprocessing.Manager` represents a multi-process shared resource management tool, and `shared_dict` represents a shared dictionary created by it that can be read and written synchronously by multiple processes.

[0113] Each time after the target replacement character is determined, the first N characters with the lowest usage counts are extracted from the shared_dict as the primary selection range for random selection, while the cmap table of the font file is parsed to verify glyph compatibility. If no available character exists, the selection range is expanded. After the target replacement character is determined and before the target generated image is produced, the statistical information of this character in the shared_dict is locked through a mutex lock to prevent concurrent modification by other processes. After the character addition is completed and the target generated image is obtained, the usage count of this character is accumulated and updated in an atomic operation relying on the mutex lock to refresh the shared_dict, and the mutex lock is unlocked after the update is completed. The entire mechanism relies on the mutex lock to ensure the atomicity of count updates, so that the multi-process statistical data is globally unified. After batch enhancement, the usage counts of various rare characters tend to be equal. For example, the usage counts of the characters "霺", "撳" and "劂" are all 3685 times, and the usage counts of the characters "駋", "赾" and "牏" are all 3684 times, which effectively overcomes the problems of excessively high repeated usage frequency of some characters and long-term idleness of some characters under the random sampling mode.

[0114] By applying the solutions of the embodiments of this specification, locking the statistical information of the target replacement character before image generation can effectively avoid the problems of statistical data conflict and abnormal data tampering during multi-task parallel processing, and ensure the accuracy of character statistical data; meanwhile, synchronously updating the statistical information and unlocking the data after image generation can update the usage frequency status of each candidate character in real time, continuously ensure the global balance of multi-character sampling, and stably realize uniform sampling of rare characters to avoid the polarization of character usage.

[0115] As an example, Figure 4 shows a schematic diagram of the generation process of an image generation method provided by an embodiment of this specification, as Figure 4 shown in the figure, the generation process of the image generation method can be divided into an input stage, a character box detection and OCR recognition stage, a line segment detection and candidate screening stage, a balanced sampling and font compatibility check stage, an image erasure stage, a rare character rendering stage, a post-processing fusion stage, and an output stage. These stages will be described respectively in the following.

[0116] Input stage: Input a real document image and corresponding text annotations as original materials for obtaining the target image.

[0117] Character box detection and OCR recognition stage: Perform character-level detection to obtain single-character Bboxes, perform batch OCR recognition to extract text content, output matched_text and filtered_bboxes, and complete the operations of detecting character positions of the target image, recognizing image characters and obtaining character position information.

[0118] Line segment detection and candidate selection stage: Group and sort by line, filter non-overlapping Chinese character boxes, sort the character layout based on character position information, and provide data support for determining the character to be replaced.

[0119] Balanced sampling and font compatibility check phase: Globally track the usage count of 21042 characters, prioritize low-frequency characters, verify font support through cmap table, ensure consistency by relying on multi-process shared dictionary, first filter candidate characters based on auxiliary character frequency statistics, then filter target replacement characters based on the current statistical information of candidate characters, and complete the balanced sampling process of locking, updating and unlocking statistical information.

[0120] Image erasure stage: Expand the region of the character Bbox, generate a binary mask and repair the image using the Telea algorithm. First, expand the region of the image to be replaced, then distinguish between the erasable sub-regions and the non-erasable sub-regions, erasing only the original characters and preserving the background texture and noise.

[0121] In the rare character rendering stage: color estimation is performed using the Otsu algorithm, adaptive font size is applied, multiple fonts are randomly selected, characters are centered and aligned with a slight offset to simulate real typesetting, and the target replacement characters are adapted and adjusted based on the character attribute information such as color, font, font size, and font shape of the target image.

[0122] Post-processing fusion stage: Apply Gaussian blur (radius 0.3 to 0.7) and superimpose Gaussian noise (standard deviation 1 to 2) to the rendering area to allow the rendering area to transition naturally with the background. Optimize and adjust the generated image uniformly with reference to image attribute information such as the clarity of the target image and the sharpness of the characters.

[0123] Output stage: The adjusted target replacement characters are filled into the image area to be replaced to obtain the target generated image. The final output includes the enhanced image, updated annotations, and usage statistics. Please refer to [link / reference]. Figure 5 , Figure 5 This specification shows a comparison of the effects before and after processing using the third image generation method provided in one embodiment. Figure 5 As shown, the first column is the input image, representing the target image without character replacement processing. It fully preserves the original layout, pinyin, question numbers, common Chinese characters, and various visual elements of the exercises, containing only commonly used Chinese character images. The second column is the output image after erasing and adding uncommon characters, representing the target generated image obtained by erasing the original characters to be replaced and filling in the target replacement characters. Only the common Chinese characters in the corresponding area to be replaced are replaced with uncommon characters; the background, layout, symbols, and other content remain consistent with the input image on the left. The third column represents the uncommon characters, indicating the low-frequency uncommon character candidate set used in each set of exercise replacement operations.

[0124] The image generation method proposed in the embodiments of this specification can be applied to, for example, Figure 6 The image generation system shown is not limited to this. See also Figure 6 , Figure 6 This specification illustrates an architecture diagram of an image generation system according to one embodiment of the present specification. The image generation system may include a client 602 and a server 604. Client 602 is used to send the target image to server 604; Server 604 is used to obtain a target image, wherein the target image includes multiple image characters, and the image characters carry character position information; determine the character to be replaced from the multiple image characters, and determine the image region to be replaced from the target image based on the character position information carried by the character to be replaced; determine the target replacement character based on the current statistical information of multiple candidate characters; erase the character to be replaced from the image region to be replaced, and add the target replacement character to the image region to be replaced to obtain the target generated image; and send the target generated image to client 602. like Figure 6 As shown, server 604 can connect to one or more clients 602 via a local area network (LAN), wide area network (WAN), internet connection, or other types of data network. Client 602 can include, but is not limited to, smartphones, tablets, laptops, PDAs, personal computers, smart home devices, and in-vehicle devices. Client 602 can also interact with the user through a graphical user interface to invoke task processing models, thereby implementing the image generation method provided in the embodiments of this specification.

[0125] See Figure 7 , Figure 7 This specification shows a flowchart of a training method for a rare character recognition model according to an embodiment, which specifically includes the following steps: Step 702: Obtain a sample image, wherein the sample image includes sample rare characters. The sample image is obtained by erasing the characters to be replaced in the image region to be replaced and adding the sample rare characters to the image region to be replaced. The sample rare characters are determined based on the current statistical information of multiple candidate rare characters. The image region to be replaced is determined from the original image based on the character position information carried by the characters to be replaced. The characters to be replaced are determined from multiple image characters in the original image.

[0126] Step 704: Adjust the parameters of the initial recognition model based on the sample images and rare characters to obtain the trained rare character recognition model.

[0127] It should be noted that the sample images refer to images used for training the initial recognition model. The sample images contain rare sample characters for the initial recognition model to learn. The sample images may be text and image images generated by replacing characters in various test papers and documents, or images generated by replacing characters in screenshots of electronic texts. The sample images are used to provide training materials with real layout and background features for the rare character recognition model. For example, the sample image may be an image generated by an image generation method based on the original image of a primary school Chinese connecting exercise.

[0128] The rare sample characters refer to low-frequency character units in the sample images. The rare sample characters include characters for training the initial recognition model. The rare sample characters may be ancient Chinese characters with complex strokes and low daily use frequency, or variant and special rare Chinese characters. The rare sample characters are used as the annotation ground truth corresponding to the sample images to guide the initial recognition model to complete feature learning of rare characters. For example, the rare sample characters may be low-frequency and rare Chinese characters such as "觥, 氿, 龘".

[0129] The initial recognition model refers to a recognition model that has not been iteratively optimized with rare character samples. The initial recognition model has basic text feature extraction and recognition capabilities, but has insufficient recognition accuracy for low-frequency rare characters. The initial recognition model may be a general OCR single-character classification network, or an integrated deep learning network for text detection and recognition. The initial recognition model is configured to receive the sample images and the rare sample characters to perform iterative operations, and adapt to the rare character recognition scenario through parameter updating. For example, the initial recognition model may be a convolutional character recognition network that is only pre-trained on a common Chinese character dataset.

[0130] The rare character recognition model refers to a finished network model that is capable of recognizing rare characters after iterative parameter adjustment using the sample images. The rare character recognition model has a stable and accurate recognition effect on various low-frequency rare Chinese characters. The rare character recognition model may be a lightweight recognition model deployed on a terminal, or a cloud high-precision text recognition model. The rare character recognition model is configured to directly detect and recognize rare characters in an input document image and output character results. For example, the rare character recognition model can directly recognize various variant and complex rare Chinese characters in images of test papers and documents.

[0131] Parameter tuning can be done in one round of parameter updates for a single batch of samples, or iteratively across multiple rounds traversing the entire sample dataset. Parameter tuning of the initial recognition model continuously reduces the recognition error between the model's predicted characters and uncommon characters in the actual samples, gradually improving the model's feature extraction and classification capabilities for low-frequency uncommon characters, thus obtaining a trained uncommon character recognition model. For example, parameter tuning of the initial recognition model can involve calculating the cross-entropy loss between the model's output characters and the labeled uncommon characters for each batch of input sample images containing uncommon characters, and then using the gradient descent algorithm to correct the weight parameters of the model's convolutional and fully connected layers to obtain a trained uncommon character recognition model.

[0132] It should be noted that the method for obtaining the sample image in step 702 can refer to the image generation method described above, and will not be repeated in the embodiments of this specification.

[0133] The scheme implemented in this specification determines the image region to be replaced based on the original image, filters sample rare characters based on the current statistical information of candidate rare characters, and obtains sample images by erasing the original image characters and filling in the sample rare characters. Then, the initial recognition model is trained using the sample images. This achieves automatic generation of training samples with a large number of styles that fit real documents and a balanced frequency of use for each rare character. There is no need to manually create training images for rare characters, which greatly reduces the cost of sample production. At the same time, the sample covers a uniform distribution of rare characters, which can reduce the problems of overfitting of popular characters and insufficient recognition accuracy of low-frequency characters during model training. The rare character recognition model finally trained has a more balanced and accurate recognition capability for multiple rare characters.

[0134] See Figure 8 , Figure 8 This specification shows a flowchart of a method for recognizing rare characters according to an embodiment, which specifically includes the following steps: Step 802: Obtain the image to be recognized.

[0135] Step 804: Input the image to be recognized into the rare character recognition model to obtain the rare character recognition result of the image to be recognized. The rare character recognition model is trained based on the above rare character recognition model training method.

[0136] It should be noted that the image to be recognized refers to an image on which the rare character detection and recognition operation needs to be performed. The image to be recognized contains various text characters recognized by the rare character recognition model, including rare characters that are rarely seen in daily life. The image to be recognized may be a scanned image obtained by scanning a paper document, or a real-shot image obtained by photographing a paper reading material, or an interface screenshot obtained by capturing an electronic screen. The image to be recognized is used to provide the rare character recognition model with raw image data to be parsed. For example, the image to be recognized may be a scanned image of a Chinese test paper containing rare Chinese characters.

[0137] The rare character recognition result refers to the character determination information output after the rare character recognition model parses the image to be recognized. The rare character recognition result contains the character content and spatial position information corresponding to all rare characters in the image to be recognized. The rare character recognition result may be a rare character text list, or character annotation data bound with coordinate positions. The rare character recognition result is used to intuitively feed back the content and distribution position of the rare characters present in the image to be recognized. For example, the rare character recognition result may output rare Chinese characters such as "觥, 龘, 氿" in the test paper to be recognized and the image coordinates corresponding to the rare characters.

[0138] It should be noted that for the implementation manner of acquiring the image to be recognized in step 802, reference may be made to the above image generation manner, which will not be repeated in the embodiments of this specification.

[0139] By applying the solutions of the embodiments of this specification, the image to be recognized is processed by the rare character recognition model trained with equally distributed rare character samples, and the recognition capability of the model is supported by training data with comprehensive coverage and balanced quantity of various rare character samples, so as to realize stable and accurate recognition of various low-frequency and rare characters in the image, improve the defect that the conventional recognition model has low recognition accuracy for unpopular rare characters, and enhance the comprehensiveness and reliability of overall image text recognition.

[0140] Corresponding to the above embodiments of the rare character recognition method, this specification further provides embodiments of a rare character recognition model, and the rare character recognition model may include a feature extraction layer, a feature enhancement layer, a sequence modeling layer, and a classification output layer connected in sequence.

[0141] The feature extraction layer is configured to receive an image to be recognized, extract stroke edge features, local structure features and character contour features in the image to be recognized through convolution operation, pooling operation and nonlinear activation operation, output a corresponding character local feature map, and transmit the character local feature map to the feature enhancement layer.

[0142] The feature enhancement layer receives local feature maps of characters and enhances key stroke regions, radical structure regions, and easily confused structure regions in characters through attention mechanisms or multi-scale feature fusion methods. It outputs the enhanced character semantic feature map and transmits the character semantic feature map to the sequence modeling layer.

[0143] The sequence modeling layer receives the enhanced character semantic feature map and models the contextual relationships between character strokes, components, and structures according to spatial positional relationships. It outputs a character structure feature vector that represents the overall structure of rare characters and transmits the character structure feature vector to the classification output layer.

[0144] The classification output layer receives character structure feature vectors, maps them to a preset rare character category space, outputs the confidence score for each candidate rare character category, and determines the rare character recognition result of the image to be recognized based on the confidence score.

[0145] The above is an illustrative scheme of a rare character recognition model according to this embodiment. It should be noted that the technical solution of this rare character recognition model and the technical solution of the rare character recognition method described above belong to the same concept. The rare character recognition model serves as the execution carrier of the rare character recognition method, and is used to implement the core steps of inputting the image to be recognized into the model and outputting the rare character recognition result. For details not described in detail in this rare character recognition model technical solution, please refer to the description of the technical solution of the rare character recognition method described above.

[0146] Corresponding to the above method embodiments, this specification also provides embodiments of an image generation apparatus. Figure 9 A schematic diagram of an image generation apparatus according to one embodiment of this specification is shown. Figure 9 As shown, the device includes: The first acquisition module 902 is configured to acquire a target image, wherein the target image includes multiple image characters, and the image characters carry character position information.

[0147] The first confirmation module 904 is configured to determine the character to be replaced from multiple image characters, and to determine the image region to be replaced from the target image based on the character position information carried by the character to be replaced.

[0148] The second confirmation module 906 is configured to determine the target replacement character based on the current statistical information of multiple candidate characters.

[0149] The generation module 908 is configured to erase the characters to be replaced in the image area to be replaced and add the target replacement characters to the image area to be replaced to obtain the target generated image.

[0150] Optionally, the generation module 908 is further configured to parse the image region to be replaced, determine the erased sub-region and the non-erasable sub-region, wherein the erased sub-region is the sub-region in the image region to be replaced where the character to be replaced is located; and erase the erased sub-region according to the region attribute information of the non-erasable sub-region.

[0151] Optionally, the generation module 908 is further configured to expand the image region to be replaced to obtain the expanded image region to be replaced; and to parse the image region to be replaced to determine the erased sub-regions and non-erased sub-regions, including: parsing the expanded image region to be replaced to determine the erased sub-regions and non-erased sub-regions.

[0152] Optionally, the acquisition module 902 is further configured to acquire a target image; perform character position detection on the target image to obtain character position information, and determine the image regions to be detected corresponding to the character position information; and perform character recognition on the image regions to be detected to obtain multiple image characters.

[0153] Optionally, the first confirmation module 904 is further configured to determine the reading order of multiple image characters based on character position information; and to determine the character to be replaced from the multiple image characters based on the reading order.

[0154] Optionally, the device further includes: a first adjustment module configured to adjust the target replacement character based on the character attribute information of the target image to obtain the adjusted target replacement character, wherein the character attribute information includes at least one of color, font, font size and font shape; and a generation module 908 further configured to add the adjusted target replacement character to the image area to be replaced to obtain the target generated image.

[0155] Optionally, the device further includes a second adjustment module configured to adjust the target generated image according to the image attribute information of the target image to obtain an adjusted target generated image, wherein the image attribute information includes at least one of image sharpness and character sharpness.

[0156] Optionally, the device further includes: an auxiliary module configured to acquire an auxiliary image, wherein the auxiliary image includes multiple auxiliary characters; perform frequency statistics on the multiple auxiliary characters to obtain statistical information corresponding to each of the multiple auxiliary characters; and determine multiple candidate characters from the multiple auxiliary characters based on the statistical information.

[0157] Optionally, the device further includes: a locking module configured to lock the current statistics of the target replacement character; and a generation module 908 further configured to update the current statistics of the target replacement character and release the lock on the current statistics after the update is completed.

[0158] The above is an illustrative scheme of an image generation apparatus according to this embodiment. It should be noted that the technical solution of this image generation apparatus and the technical solution of the image generation method described above belong to the same concept. For details not described in detail in the technical solution of the image generation apparatus, please refer to the description of the technical solution of the image generation method described above.

[0159] Corresponding to the above embodiments of the training method for rare character recognition models, this specification also provides embodiments of a training device for rare character recognition models. Figure 10 A schematic diagram of a training device for a rare character recognition model provided in one embodiment of this specification is shown. Figure 10 As shown, the device includes: The second acquisition module 1002 is configured to acquire a sample image, wherein the sample image includes sample rare characters. The sample image is obtained by erasing the character to be replaced in the image region to be replaced and adding the sample rare characters to the image region to be replaced. The sample rare characters are determined based on the current statistical information of multiple candidate rare characters. The image region to be replaced is determined from the original image based on the character position information carried by the character to be replaced. The character to be replaced is determined from multiple image characters in the original image.

[0160] The adjustment module 1004 is configured to adjust the parameters of the initial recognition model based on the sample image and the rare characters in the sample, so as to obtain the trained rare character recognition model.

[0161] The above is an illustrative scheme of a rare character recognition model training device according to this embodiment. It should be noted that the technical solution of this rare character recognition model training device and the technical solution of the rare character recognition model training method described above belong to the same concept. For details not described in detail in the technical solution of the rare character recognition model training device, please refer to the description of the technical solution of the rare character recognition model training method described above.

[0162] Corresponding to the above embodiments of the rare character recognition method, this specification also provides embodiments of the rare character recognition device. Figure 11 A schematic diagram of a rare character recognition device according to one embodiment of this specification is shown. Figure 11 As shown, the device includes: The third acquisition module 1102 is configured to acquire the image to be recognized.

[0163] The processing module 1104 is configured to input the image to be recognized into the rare character recognition model to obtain the rare character recognition result of the image to be recognized, wherein the rare character recognition model is trained based on the above-mentioned rare character recognition model training method.

[0164] The above is a schematic scheme of a rare character recognition device according to this embodiment. It should be noted that the technical solution of this rare character recognition device and the technical solution of the rare character recognition method described above belong to the same concept. For details not described in detail in the technical solution of the rare character recognition device, please refer to the description of the technical solution of the rare character recognition method described above.

[0165] Figure 12 A structural block diagram of a computing device according to one embodiment of this specification is shown. The components of the computing device 1200 include, but are not limited to, a memory 1210 and a processor 1220. The processor 1220 is connected to the memory 1210 via a bus 1230, and a database 1250 is used to store data.

[0166] The computing device 1200 also includes an access device 1240, which enables the computing device 1200 to communicate via one or more networks 1260. Examples of these networks include Public Switched Telephone Network (PSTN), Local Area Network (LAN), Wide Area Network (WAN), Personal Area Network (PAN), or combinations of communication networks such as the Internet. The access device 1240 may include one or more of any type of wired or wireless network interface (e.g., Network Interface Card (NIC)), such as an IEEE 802.11 Wireless Local Area Networks (WLAN) interface, a Wi-MAX (World Interoperability for Microwave Access) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, a Near Field Communication (NFC) interface, and so on.

[0167] In one embodiment of this specification, the above-described components of the computing device 1200 and Figure 12 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 12 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.

[0168] The computing device 1200 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or personal computers (PCs). The computing device 1200 can also be a mobile or stationary server.

[0169] The processor 1220 is used to execute computer programs / instructions, which, when executed by the processor, implement the steps of the above-mentioned image generation method, rare character recognition model training method, or rare character recognition method.

[0170] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device belongs to the same concept as the technical solutions of the image generation method, the rare character recognition model training method, and the rare character recognition method described above. For details not described in detail in the technical solution of the computing device, please refer to the descriptions of the technical solutions of the image generation method, the rare character recognition model training method, or the rare character recognition method described above.

[0171] An embodiment of this specification also provides a computer-readable storage medium storing a computer program / instructions that, when executed by a processor, implement the steps of the above-described image generation method, rare character recognition model training method, or rare character recognition method.

[0172] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solutions of the image generation method, the rare character recognition model training method, and the rare character recognition method described above. For details not described in detail in the technical solution of the storage medium, please refer to the descriptions of the technical solutions of the image generation method, the rare character recognition model training method, or the rare character recognition method described above.

[0173] An embodiment of this specification also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described image generation method, rare character recognition model training method, or rare character recognition method.

[0174] The above is an illustrative scheme of a computer program product according to this embodiment. It should be noted that the technical solution of this computer program product belongs to the same concept as the technical solutions of the image generation method, the rare character recognition model training method, and the rare character recognition method described above. For details not described in detail in the technical solution of the computer program product, please refer to the descriptions of the technical solutions of the image generation method, the rare character recognition model training method, or the rare character recognition method described above.

[0175] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.

[0176] Computer instructions include computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. Computer-readable media can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in computer-readable media can be appropriately added or removed according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.

[0177] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.

[0178] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.

[0179] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.

Claims

1. An image generation method, characterized in that, include: Acquire a target image, wherein the target image includes multiple image characters, and the image characters carry character position information; The character to be replaced is determined from the plurality of image characters, and the image region to be replaced is determined from the target image based on the character position information carried by the character to be replaced. Based on the current statistical information of multiple candidate characters, the target replacement character is determined; Erase the character to be replaced in the image area to be replaced, and add the target replacement character to the image area to be replaced to obtain the target generated image.

2. The method according to claim 1, characterized in that, The process of erasing the character to be replaced in the image area to be replaced includes: The image region to be replaced is analyzed to determine the erased sub-region and the non-erased sub-region, wherein the erased sub-region is the sub-region in the image region to be replaced where the character to be replaced is located; The erasing sub-region is erased based on the region attribute information of the non-erasing sub-region.

3. The method according to claim 2, characterized in that, Before analyzing the image region to be replaced and determining the erased sub-region and the non-erased sub-region, the process further includes: The image region to be replaced is expanded to obtain the expanded image region to be replaced; The step of parsing the image region to be replaced and determining the erased sub-region and the non-erased sub-region includes: The expanded image region to be replaced is analyzed to determine the erased sub-region and the non-erased sub-region.

4. The method according to claim 1, characterized in that, The acquisition of the target image includes: Acquire the target image; The target image is subjected to character position detection to obtain the character position information, and the image regions to be detected corresponding to the character position information are determined respectively; Character recognition is performed on the image regions to be detected to obtain the multiple image characters.

5. The method according to claim 1, characterized in that, The step of determining the character to be replaced from the plurality of image characters includes: Based on the character position information, the reading order of the multiple image characters is determined; Based on the reading order, the character to be replaced is determined from the plurality of image characters.

6. The method according to any one of claims 1 to 5, characterized in that, Before adding the target replacement character to the image region to be replaced to obtain the target generated image, the method further includes: Based on the character attribute information of the target image, the target replacement character is adjusted to obtain the adjusted target replacement character, wherein the character attribute information includes at least one of color, font, font size and font shape; The step of adding the target replacement character to the image region to be replaced to obtain the target generated image includes: The adjusted target replacement characters are added to the image area to be replaced to obtain the target generated image.

7. The method according to any one of claims 1 to 5, characterized in that, After adding the target replacement character to the image region to be replaced to obtain the target generated image, the process further includes: Based on the image attribute information of the target image, the target generated image is adjusted to obtain the adjusted target generated image, wherein the image attribute information includes at least one of image clarity and character sharpness.

8. The method according to any one of claims 1 to 5, characterized in that, Before determining the target replacement character based on the current statistical information of multiple candidate characters, the process also includes: Acquire an auxiliary image, wherein the auxiliary image includes multiple auxiliary characters; Frequency statistics are performed on the multiple auxiliary characters to obtain statistical information corresponding to each of the multiple auxiliary characters; Based on the statistical information, the multiple candidate characters are determined from the multiple auxiliary characters.

9. The method according to any one of claims 1 to 5, characterized in that, Before adding the target replacement character to the image region to be replaced to obtain the target generated image, the method further includes: Lock the current statistics of the target replacement character; After adding the target replacement character to the image region to be replaced to obtain the target generated image, the process further includes: The current statistics of the target replacement character are updated, and the current statistics are unlocked after the update is completed.

10. A method for training a rare character recognition model, characterized in that, include: A sample image is obtained, wherein the sample image includes sample rare characters. The sample image is obtained by erasing the characters to be replaced in the image region to be replaced and adding the sample rare characters to the image region to be replaced. The sample rare characters are determined based on the current statistical information of multiple candidate rare characters. The image region to be replaced is determined from the original image based on the character position information carried by the characters to be replaced. The characters to be replaced are determined from multiple image characters in the original image. Based on the sample image and the rare characters in the sample, the parameters of the initial recognition model are adjusted to obtain a trained rare character recognition model.

11. A method for recognizing rare characters, characterized in that, include: Acquire the image to be recognized; The image to be identified is input into the rare character recognition model to obtain the rare character recognition result of the image to be identified, wherein the rare character recognition model is trained based on the method described in claim 10.

12. A computing device, characterized in that, include: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions, which, when executed by the processor, implement the steps of the method according to any one of claims 1 to 11.

13. A computer-readable storage medium, characterized in that, It stores a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 11.

14. A computer program product, characterized in that, Includes a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 11.