Document image batch generation method and device, electronic equipment and storage medium
By sampling from a corpus and converting it into a structured corpus to generate HTML documents, and combining style libraries and automated processing of document elements, the problems of low efficiency and insufficient diversity in document image generation are solved. This enables efficient and diverse batch generation of document images and improves the training data quality of the OCR model.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- IFLYTEK CO LTD
- Filing Date
- 2025-12-31
- Publication Date
- 2026-04-24
AI Technical Summary
Existing technologies have low automation and limited efficiency in generating document images, making it difficult to meet the needs of OCR models for massive training data. Furthermore, the generated document images are monotonous and lack diversity, which affects the generalization performance of OCR models.
By sampling target text data from the corpus corresponding to the training requirements, converting it into structured data, and using candidate values from the style library to generate target HTML documents, loading, rendering, and taking screenshots to generate document images, the system simultaneously identifies and stores the text content and annotation information of document elements, thus achieving automated batch generation.
It enables automated batch generation of document images, improves generation efficiency, enhances the visual diversity of document images and the diversity of training data, and significantly improves the training data generation efficiency and generalization performance of OCR models.
Smart Images

Figure CN121921797A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer vision technology, and in particular to a method, apparatus, electronic device, and storage medium for batch generation of document images. Background Technology
[0002] With the widespread application of deep learning technology in the field of Optical Character Recognition (OCR), the demand for training data for OCR models has increased dramatically. Traditional methods of acquiring training data mainly rely on manual collection, annotation, or simple image synthesis. These methods suffer from inefficiency and limited formatting, making it difficult to meet the needs of large-scale, diverse training data. Therefore, there is an urgent need for a technical solution that can automatically and efficiently generate a large number of diverse document images to support the training requirements of OCR models.
[0003] Currently, the industry mainly adopts the following technical approaches for document image acquisition: 1) Technicians acquire real document images through on-site photography or online collection; 2) Technicians digitize paper documents using high-resolution scanners or professional cameras to obtain document images; 3) Technicians use image processing tools to manually combine text layers, image materials, and other elements onto the background image according to a preset layout, and generate a composite document image by adjusting the visual attributes of each element; 4) Technicians use image editing software to manually stitch scattered text, images, and other visual elements onto the background canvas according to the document structure, and construct the document image by finely adjusting the spatial position, size ratio, and style attributes of each element.
[0004] The aforementioned document image acquisition paths all require technical personnel, resulting in low automation and an inability to achieve automated batch production processes. This limits generation efficiency and slows down the generation of training data, failing to meet the urgent need for massive training data in OCR models. Furthermore, the resulting document images are monotonous in style, making it difficult to simulate the rich variations in font selection, color schemes, layout, and typography styles found in real-world documents. This limitation leads to a lack of sufficient diversity in the generated training data, thereby affecting the generalization performance of the OCR model. Summary of the Invention
[0005] This invention provides a method, apparatus, electronic device, and storage medium for batch generation of document images, in order to overcome the deficiencies existing in related technologies.
[0006] This invention provides a method for batch generation of document images, comprising: Sample target text data from the corpus corresponding to the training requirements, and convert the target text data into structured data. Based on the candidate values of each style parameter in the style library, the target HTML template corresponding to the target text corpus is applied to generate the target HTML document corresponding to the structured corpus; The target HTML document is loaded and rendered, and a screenshot of the loaded page is taken to generate a document image corresponding to the target text corpus.
[0007] According to a method for batch generating document images provided by the present invention, the step of taking a screenshot of the loaded page and generating a document image corresponding to the target text corpus, followed by: Identify all target document elements within the loaded page, and obtain the text content and annotation information of each target document element; The text content and the annotation information are converted into structured data, and the structured data is associated with and stored with the document image.
[0008] According to a method for batch generating document images provided by the present invention, the annotation information includes at least one of the following: the position information of each target document element within the loaded page, the target value of each style parameter corresponding to each target document element, the element type of each target document element, and the style class name corresponding to each target document element.
[0009] According to a method for batch generation of document images provided by the present invention, the corpus construction process includes: The language and domain of the corpus are determined, as well as the document objects; the document objects include document elements or complete documents, and the document objects correspond to pre-built HTML templates; Based on the corpus language and the corpus domain, a text corpus corresponding to the document object is generated, and based on the text corpus, the corpus library corresponding to the corpus language and the corpus domain is constructed.
[0010] According to a method for batch generation of document images provided by the present invention, the document object corresponding to the target text corpus includes structured document elements; The process of converting the target text corpus into a structured corpus includes: Generate the initial structure corresponding to the structured document elements; Based on the target text corpus, the initial structure is populated with content, and the structured corpus is determined based on the hierarchical relationship corresponding to the structured document elements.
[0011] According to a method for batch generating document images provided by the present invention, the step of taking a screenshot of the loaded page includes: Take a screenshot of the loading page or a target document element within the loading page.
[0012] According to a method for batch generation of document images provided by the present invention, the document object corresponding to the target text corpus includes a complete document; The process of generating the target HTML document corresponding to the structured corpus by applying the target HTML template corresponding to the target text corpus based on the candidate values of each style parameter in the style library includes: Based on the candidate values of each style parameter in the style library, a random style dictionary is generated, and the style of the target HTML template is updated based on the random style dictionary. The chapter structure and document structure of the target HTML template are determined. Based on the chapter structure, each document element in the target text corpus is assigned to each chapter in the target HTML template. Based on the document structure, the order of each chapter is adjusted to obtain the target HTML document.
[0013] The present invention also provides a document image batch generation apparatus, comprising: The text corpus acquisition module is used to sample target text corpus from the corpus corresponding to the training requirements and convert the target text corpus into structured corpus; The HTML document generation module is used to generate the target HTML document corresponding to the structured corpus by applying the target HTML template corresponding to the target text corpus based on the candidate values of each style parameter in the style library. The document image generation module is used to load and render the target HTML document, take a screenshot of the loaded page, and generate a document image corresponding to the target text corpus.
[0014] The present invention also provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the document image batch generation method as described above.
[0015] The present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the document image batch generation method as described above.
[0016] The present invention also provides a computer program product, including a computer program that, when executed by a processor, implements the document image batch generation method as described above.
[0017] The document image batch generation method, apparatus, electronic device, and storage medium provided by this invention sample target text corpora from a corpus corresponding to training requirements, ensuring consistency between the target text corpora and training needs. Converting the target text corpus into structured corpora reduces the difficulty of generating target HTML documents. Introducing candidate values for various style parameters from a style library establishes a complete style configuration system, enabling flexible configuration of style parameters for target HTML documents, resulting in highly visually diverse generated document images and significantly improving the diversity of training data. By applying the style library and target HTML templates corresponding to the target text corpus, different style variations and different document objects can be supported without modifying the core code, exhibiting good scalability and maintainability. Furthermore, this method enables automated batch generation of document images, greatly improving generation efficiency and consequently significantly enhancing the generation efficiency of OCR model training data. This meets the urgent need for massive training data in OCR models and helps improve their generalization performance. Attached Figure Description
[0018] To more clearly illustrate the technical solutions in this invention or related technologies, the accompanying drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of this invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0019] Figure 1 This is one of the flowcharts illustrating the batch document image generation method provided by the present invention.
[0020] Figure 2 This is the second flowchart of the document image batch generation method provided by the present invention.
[0021] Figure 3 This is a schematic diagram of the structure of the document image batch generation device provided by the present invention.
[0022] Figure 4 This is a schematic diagram of the structure of the electronic device provided by the present invention. Detailed Implementation
[0023] To make the objectives, technical solutions, and advantages of this invention clearer, the technical solutions of this invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of this invention. All other embodiments obtained by those skilled in the art based on the embodiments of this invention without creative effort are within the scope of protection of this invention.
[0024] Figure 1 This is a flowchart illustrating a method for batch generating document images provided in an embodiment of the present invention, as shown below. Figure 1 As shown, the method includes: S1, sample target text data from the corpus corresponding to the training requirements, and convert the target text data into structured data; S2, based on the candidate values of each style parameter in the style library, apply the target HTML template corresponding to the target text corpus to generate the target HTML document corresponding to the structured corpus; S3, load and render the target HTML document, take a screenshot of the loaded page, and generate a document image corresponding to the target text corpus.
[0025] Specifically, the document image batch generation method provided in this embodiment of the invention is executed by a document image batch generation device, which can be configured in a computer. The computer can be a local computer or a cloud computer. The local computer can be a computer, tablet, etc., and no specific limitation is made here.
[0026] First, step S1 is executed, sampling target text data from the corpus corresponding to the training requirements. Here, the training requirements may include the target language and target domain, etc. The corpus is pre-built and may include multiple corpora, each corresponding to a different language and domain.
[0027] The language of the demand and the language of the corpus can include Chinese, English, Japanese, etc., and the domain of the demand and the domain of the corpus can include the technical field, the literary field, the academic field, etc.
[0028] Each corpus contains multiple text corpora, and the language and domain of the text corpora in each corpus are the same. Each text corpus can be generated using large language models or tools such as Faker.
[0029] Each text corpus can correspond to a document object, which can be a document element or a complete document. Document elements can be of at least one type, such as paragraph, list, heading, table, chart, or formula. Paragraphs and headings are text-based document elements; tables, formulas, and charts are structured document elements; and multi-level lists and tables of contents are complex document elements, also belonging to multi-level structured document elements.
[0030] Each document object corresponds to a pre-built, reusable HTML template. This means the HTML template can include the HTML template corresponding to a document element or the HTML template corresponding to the entire document. The HTML template corresponding to a document element can support the dynamic insertion of style parameters and content data. The HTML template corresponding to a complete document can include a complete structure such as headers, footers, titles, abstracts, body text, and references, and can support the generation of complete academic papers or document pages.
[0031] In this embodiment of the invention, the HTML template can be defined using the Jinja2 template engine. The HTML template can adopt an inheritance mechanism, where a base template containing common HTML structure and style definitions can be defined first, and the HTML templates corresponding to document elements can inherit from the base template and define specific styles and content structures.
[0032] In particular, for complex document elements such as multi-level lists and directories, the corresponding HTML templates also support recursive rendering, which can handle nested structures of any depth.
[0033] Based on the training requirements, a corpus whose language is the same as the required language and whose domain is the same as the required domain can be identified, and this corpus can be used as the corpus corresponding to the training requirements.
[0034] Furthermore, one or more text corpora are randomly sampled from the corpus corresponding to the training requirements, and these text corpora can be converted into structured corpora. These structured corpora can be in a structured format that is easily integrated into HTML templates, such as JSON format.
[0035] During random sampling, for paragraphs, the text length can be controlled, and text content that meets the length requirement can be sampled from the corpus as text corpus. For lists, the number of text items can be controlled, and a specified number of list items can be sampled from the corpus as text corpus.
[0036] Next, step S2 is executed, importing a pre-built style library. This style library can be a Cascading Style Sheets (CSS) style library, containing multiple style parameters. Each style parameter represents a visual presentation parameter of the document, such as font type, font size, font color, line spacing, character spacing, paragraph spacing, background color, text color, accent color, indentation, margins, padding, and other typography and layout parameters. Font types can include Times New Roman, Arial, SimSun, and Heiti, among others.
[0037] For element types such as lists, tables, and charts in a document object, other style parameters can also be included. For example, style parameters for lists include marker style, marker position, and marker color; style parameters for tables include border style and cell alignment; and style parameters for charts include size and position.
[0038] The candidate values for each style parameter in the style library refer to the possible values of each style parameter, such as the font type being SimSun and the font size being 5.
[0039] Then, using the candidate values of each style parameter in the style library, the style of the target HTML template corresponding to the target text corpus is updated, and the structured corpus is filled into the target HTML template to generate the target HTML document corresponding to the structured corpus.
[0040] Finally, step S3 loads and renders the target HTML document, resulting in a loading page displaying the target HTML document. By taking a screenshot of this loading page, a document image corresponding to the text corpus can be generated. This document image can be in PNG format or other image formats.
[0041] Here, the target HTML document can be loaded and rendered by the browser engine. The browser engine can be a headless browser engine.
[0042] The document image batch generation method provided in this embodiment of the invention samples target text corpora from the corpus corresponding to the training requirements, ensuring consistency between the target text corpora and the training requirements. By converting the target text corpora into structured corpora, the generation difficulty of target HTML documents can be reduced. Introducing candidate values of various style parameters from the style library allows for the establishment of a complete style configuration system, enabling flexible configuration of various style parameters of the target HTML document. This results in highly visually diverse generated document images, significantly improving the diversity of training data. Through the application of the style library and the target HTML templates corresponding to the target text corpora, different style variations and different document objects can be supported without modifying the core code, exhibiting good scalability and maintainability. Moreover, this method can achieve automated batch generation of document images, greatly improving the generation efficiency of document images and thus significantly improving the generation efficiency of training data for OCR models. This meets the urgent need of OCR models for massive training data and helps improve the generalization performance of OCR models.
[0043] In existing solutions, after acquiring document images, manual annotation is typically used to determine the annotation information. For example, after acquiring the document image, professional image annotation tools such as LabelImg and VGG Image Annotator are used to annotate the text regions and element boundaries in the document image one by one, ultimately forming a structured training dataset. This manual annotation method heavily relies on manual steps to annotate element location information, and the image generation and annotation processes are separated. This separated workflow not only increases labor costs and has a low degree of automation, but also prolongs the data preparation cycle.
[0044] Based on this, and building upon the above embodiments, the step of taking a screenshot of the loaded page and generating a document image corresponding to the target text corpus then includes: Identify all target document elements within the loaded page, and obtain the text content and annotation information of each target document element; The text content and the annotation information are converted into structured data, and the structured data is associated with and stored with the document image.
[0045] Specifically, after loading and rendering the target HTML document to obtain the loaded page, JavaScript code can be used to traverse the DOM tree of the loaded page and identify all target document elements within the loaded page, such as at least one of the following types: paragraph, list, heading, table, chart, formula, etc.
[0046] Furthermore, the text content and annotation information of each target document element can be obtained. The type of annotation information can be set as needed, and may include at least one of the following: the target document element's position within the loaded page, the target values of each style parameter corresponding to the target document element, the element type of the target document element, and the style class name corresponding to the target document element. The position information may include the coordinates and size of the bounding box corresponding to the target document element; the size of the bounding box can be represented by its width and height. The style class name is the CSS class name.
[0047] For lists, the position of the list markers also needs to be considered, so the corresponding bounding box is a complete bounding box that includes the markers.
[0048] For text-based document elements, you can iterate through the document element, calculate its precise bounding box, and exclude blank areas.
[0049] Next, the text content and annotation information can be converted into structured data, and this structured data can be associated with and stored with the document images to obtain the dataset structure. Here, the structured data can be in JSON format.
[0050] In addition, the dataset structure can be automatically adjusted according to a specific directory organization method. For example, the dataset structure can be classified and organized according to element type, style class name, language type, etc., to form a structured training dataset.
[0051] In this embodiment of the invention, while achieving efficient batch production of document images, the automatic extraction of annotation information can be completed simultaneously, providing a complete, efficient, and diversified training data generation scheme for training OCR models, and significantly reducing the preparation cost of training data.
[0052] Based on the above embodiments, the corpus construction process includes: The language and domain of the corpus are determined, as well as the document objects; the document objects include document elements or complete documents, and the document objects correspond to pre-built HTML templates; Based on the corpus language and the corpus domain, a text corpus corresponding to the document object is generated, and based on the text corpus, the corpus library corresponding to the corpus language and the corpus domain is constructed.
[0053] Specifically, in this embodiment of the invention, the corpus construction process used in step S1 may include: First, the language, domain, and document object of the corpus are determined. The language refers to the language covered by the generated text corpus, the domain refers to the domain covered by the generated text corpus, and the document object refers to the document object corresponding to the generated text corpus. For example, corresponding to a paragraph means that the text corpus is a sentence in the document; corresponding to a complete document means that the text corpus is all the content in the document. Moreover, each document object corresponds to a pre-built HTML template.
[0054] Subsequently, leveraging the corpus language and corpus domain, and using the Application Programming Interface (API) of a large language model or the Faker library, text corpora corresponding to document objects can be generated. These text corpora can include nouns, numbers, names, sentences, URLs, etc. Since document elements within a document object and the complete document belong to different granularities, multi-granularity text corpora can be generated. For example, text corpora corresponding to a single document element, text corpora corresponding to document fragments combining multiple document elements, and text corpora corresponding to complete documents, etc.
[0055] Finally, using text corpora, a corpus corresponding to the language and domain can be constructed. Furthermore, the text corpora can be categorized and organized by text length and stored in a structured format to facilitate subsequent sampling and processing.
[0056] In this embodiment of the invention, the introduction of document objects when constructing the corpus enables the generation of multi-granularity text corpora, which in turn generates document images and training data of different granularities. This allows the obtained multi-granularity training data to meet the diverse training needs of different application scenarios of the OCR model.
[0057] Based on the above embodiments, the document object corresponding to the target text corpus includes structured document elements; The process of converting the target text corpus into a structured corpus includes: Generate the initial structure corresponding to the structured document elements; Based on the target text corpus, the initial structure is populated with content, and the structured corpus is determined based on the hierarchical relationship corresponding to the structured document elements.
[0058] Specifically, the document objects corresponding to the target text corpus can include structured document elements such as tables, formulas, and charts.
[0059] In the process of converting target text corpus into structured corpus, the initial structure corresponding to the structured document elements can be randomly generated based on information such as the number of rows and columns of the table, the complexity of the formula, and the type of the chart.
[0060] Subsequently, using the target text corpus, the initial structure is populated with content according to the element type of the structured document elements, such as filling tables with numerical values or text, formulas with mathematical expressions, and charts with data points.
[0061] Finally, by utilizing the element types of structured document elements and their corresponding hierarchical relationships, the structured corpus can be determined. This structured corpus can include information such as the type identifiers, text content, and hierarchical relationships of the structured document elements.
[0062] In particular, for structured document elements with multi-level structures such as multi-level lists and directories, a tree data structure can be constructed to maintain the hierarchical and sequential relationships of each document element.
[0063] Based on the above embodiments, taking a screenshot of the loading page includes: Take a screenshot of the loading page or a target document element within the loading page.
[0064] Specifically, in this embodiment of the invention, when taking a screenshot of a loading page, the entire loading page can be captured, a specific target document element within the loading page can be captured, or a combination of multiple target document elements within the loading page can be captured. This further enables multi-granularity generation of document images.
[0065] Based on the above embodiments, the document object corresponding to the target text corpus includes a complete document; The process of generating the target HTML document corresponding to the structured corpus by applying the target HTML template corresponding to the target text corpus based on the candidate values of each style parameter in the style library includes: Based on the candidate values of each style parameter in the style library, a random style dictionary is generated, and the style of the target HTML template is updated based on the random style dictionary. The chapter structure and document structure of the target HTML template are determined. Based on the chapter structure, each document element in the target text corpus is assigned to each chapter in the target HTML template. Based on the document structure, the order of each chapter is adjusted to obtain the target HTML document.
[0066] Specifically, in the process of generating the target HTML document corresponding to the structured corpus, if the document object corresponding to the target text corpus includes a complete document, then the target HTML document is the complete document content. In this case, candidate values for each style parameter can be randomly selected from the style library to generate a random style dictionary, ensuring that each generated target HTML document has a different visual style.
[0067] Subsequently, the structured corpus and a random style dictionary are used as input, and the Jinja2 template engine is used to render and generate a complete target HTML document.
[0068] The Jinja2 template engine can use a random style dictionary to update the styles of a target HTML template and determine its chapter and document structures. The chapter structure specifies the position and level of chapter headings, while the document structure refers to the specified positions of each document element. For example, the pre-body section may contain headings, abstracts, and keywords; the body may contain multiple chapters; and the post-body section may contain references.
[0069] Subsequently, the chapter structure can be used to distribute the document elements in the target text corpus to the chapters of the target HTML template according to preset rules or random allocation. The order of the chapters can then be adjusted using the document structure to obtain the target HTML document.
[0070] Furthermore, methods such as Gaussian distribution can be used to control the content distribution of each chapter, ensuring the rationality of the chapter content distribution. This solves the problem that existing methods have difficulty in accurately controlling the proportion of various document elements in the training dataset, and enables flexible adjustment of the composition structure of the training dataset.
[0071] In this embodiment of the invention, by using methods such as chapter structure, document element allocation, and Gaussian distribution, the order and quantity of chapter titles and element content can be flexibly controlled to generate a complete target HTML document with a reasonable structure and conforming to the characteristics of a real document.
[0072] like Figure 2 As shown, based on the above embodiments, the complete process of the document image batch generation method provided in this embodiment of the invention includes: Resource preparation: Build a style library, HTML templates, and a corpus respectively; Document image generation: Sample target text data from the corpus corresponding to the training requirements, convert the target text data into structured data, and use the candidate values of each style parameter in the style library to apply the target HTML template corresponding to the target text data to generate the target HTML document corresponding to the structured data. Load and render the target HTML document, take a screenshot of the loaded page, and generate the document image corresponding to the target text data. Annotation information determination: Identify all target document elements within the loaded page, obtain the text content and annotation information of each target document element, convert the text content and annotation information into structured data, and associate and store the structured data with the document image.
[0073] like Figure 3 As shown, based on the above embodiments, this embodiment of the invention provides a document image batch generation device, including: The text corpus acquisition module 31 is used to sample target text corpus from the corpus corresponding to the training requirements and convert the target text corpus into structured corpus; HTML document generation module 32 is used to generate a target HTML document corresponding to the structured corpus by applying the target HTML template corresponding to the target text corpus based on the candidate values of each style parameter in the style library. The document image generation module 33 is used to load and render the target HTML document, take a screenshot of the loaded page, and generate a document image corresponding to the target text corpus.
[0074] Based on the above embodiments, the document image batch generation apparatus provided in this embodiment of the invention further includes a labeling information determination module, used for: Identify all target document elements within the loaded page, and obtain the text content and annotation information of each target document element; The text content and the annotation information are converted into structured data, and the structured data is associated with and stored with the document image.
[0075] Based on the above embodiments, the document image batch generation device provided in this embodiment of the invention includes at least one of the following annotation information: the position information of each target document element within the loading page, the target value of each style parameter corresponding to each target document element, the element type of each target document element, and the style class name corresponding to each target document element.
[0076] Based on the above embodiments, the document image batch generation device provided in this embodiment of the invention further includes a corpus construction module, used for: The language and domain of the corpus are determined, as well as the document objects; the document objects include document elements or complete documents, and the document objects correspond to pre-built HTML templates; Based on the corpus language and the corpus domain, a text corpus corresponding to the document object is generated, and based on the text corpus, the corpus library corresponding to the corpus language and the corpus domain is constructed.
[0077] Based on the above embodiments, the document image batch generation apparatus provided in this embodiment of the invention includes structured document elements in the document object corresponding to the target text corpus; The text corpus acquisition module is specifically used for: Generate the initial structure corresponding to the structured document elements; Based on the target text corpus, the initial structure is populated with content, and the structured corpus is determined based on the hierarchical relationship corresponding to the structured document elements.
[0078] Based on the above embodiments, the document image batch generation apparatus provided in this embodiment of the invention specifically includes a document image generation module used for: Take a screenshot of the loading page or a target document element within the loading page.
[0079] Based on the above embodiments, the document image batch generation device provided in this embodiment of the invention includes a complete document as the document object corresponding to the target text corpus; The document image generation module is specifically used for: Based on the candidate values of each style parameter in the style library, a random style dictionary is generated, and the style of the target HTML template is updated based on the random style dictionary. The chapter structure and document structure of the target HTML template are determined. Based on the chapter structure, each document element in the target text corpus is assigned to each chapter in the target HTML template. Based on the document structure, the order of each chapter is adjusted to obtain the target HTML document.
[0080] Specifically, the functions of each module in the document image batch generation device provided in this embodiment of the invention correspond one-to-one with the operation flow of each step in the above method-like embodiments, and the achieved effects are also the same. For details, please refer to the above embodiments, and this will not be repeated in this embodiment of the invention.
[0081] Figure 4 An example is a schematic diagram of the physical structure of an electronic device, such as... Figure 4 As shown, the electronic device may include a processor 810, a communications interface 820, a memory 830, and a communication bus 840, wherein the processor 810, the communications interface 820, and the memory 830 communicate with each other via the communication bus 840. The processor 810 can call logical instructions in the memory 830 to execute the document image batch generation method provided in the above embodiments.
[0082] Furthermore, the logical instructions in the aforementioned memory 830 can be implemented as software functional units and, when sold or used as independent products, can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to related technologies, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0083] On the other hand, the present invention also provides a computer program product, which includes a computer program that can be stored on a computer-readable storage medium. When the computer program is executed by a processor, the computer is able to execute the document image batch generation method provided in the above embodiments.
[0084] In another aspect, the present invention also provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, is implemented to perform the document image batch generation method provided in the above embodiments. This computer-readable storage medium can be either a non-transitory computer-readable storage medium or a transient computer-readable storage medium, and is not specifically limited herein.
[0085] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0086] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the parts that contribute to the related technology, can be embodied in the form of software products. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute the methods described in the various embodiments or some parts of the embodiments.
[0087] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method for batch generation of document images, characterized in that, include: Sample target text data from the corpus corresponding to the training requirements, and convert the target text data into structured data. Based on the candidate values of each style parameter in the style library, the target HTML template corresponding to the target text corpus is applied to generate the target HTML document corresponding to the structured corpus; The target HTML document is loaded and rendered, and a screenshot of the loaded page is taken to generate a document image corresponding to the target text corpus.
2. The method for batch generating document images according to claim 1, characterized in that, The process of taking a screenshot of the loaded page and generating a document image corresponding to the target text corpus includes: Identify all target document elements within the loaded page, and obtain the text content and annotation information of each target document element; The text content and the annotation information are converted into structured data, and the structured data is associated with and stored with the document image.
3. The method for batch generating document images according to claim 2, characterized in that, The annotation information includes at least one of the following: the position information of each target document element within the loaded page, the target value of each style parameter corresponding to each target document element, the element type of each target document element, and the style class name corresponding to each target document element.
4. The method for batch generating document images according to any one of claims 1-3, characterized in that, The corpus construction process includes: The language and domain of the corpus are determined, as well as the document objects; the document objects include document elements or complete documents, and the document objects correspond to pre-built HTML templates; Based on the corpus language and the corpus domain, a text corpus corresponding to the document object is generated, and based on the text corpus, the corpus library corresponding to the corpus language and the corpus domain is constructed.
5. The method for batch generating document images according to any one of claims 1-3, characterized in that, The document object corresponding to the target text corpus includes structured document elements; The process of converting the target text corpus into a structured corpus includes: Generate the initial structure corresponding to the structured document elements; Based on the target text corpus, the initial structure is populated with content, and the structured corpus is determined based on the hierarchical relationship corresponding to the structured document elements.
6. The method for batch generating document images according to any one of claims 1-3, characterized in that, Taking a screenshot of the loading page includes: Take a screenshot of the loading page or a target document element within the loading page.
7. The method for batch generating document images according to any one of claims 1-3, characterized in that, The document object corresponding to the target text corpus includes complete documents; The process of generating the target HTML document corresponding to the structured corpus by applying the target HTML template corresponding to the target text corpus based on the candidate values of each style parameter in the style library includes: Based on the candidate values of each style parameter in the style library, a random style dictionary is generated, and the style of the target HTML template is updated based on the random style dictionary. The chapter structure and document structure of the target HTML template are determined. Based on the chapter structure, each document element in the target text corpus is assigned to each chapter in the target HTML template. Based on the document structure, the order of each chapter is adjusted to obtain the target HTML document.
8. A document image batch generation device, characterized in that, include: The text corpus acquisition module is used to sample target text corpus from the corpus corresponding to the training requirements and convert the target text corpus into structured corpus; The HTML document generation module is used to generate the target HTML document corresponding to the structured corpus by applying the target HTML template corresponding to the target text corpus based on the candidate values of each style parameter in the style library. The document image generation module is used to load and render the target HTML document, take a screenshot of the loaded page, and generate a document image corresponding to the target text corpus.
9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the document image batch generation method as described in any one of claims 1-7.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the document image batch generation method as described in any one of claims 1-7.