Document data extraction processing method capable of customizing data structure
By customizing data structures and style templates, combined with OCR recognition technology, we solve the problems of low efficiency and insufficient structural recognition in the electronicization of paper documents, achieve efficient and accurate structured data extraction, and improve work efficiency and product ease of use. sex.
Patent Information
- Application Number
- CN202410440246.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-12
- Publication Date
- 2024-08-30
AI Technical Summary
When the existing technology digitizes paper documents, the manual excerpting efficiency is low, the general OCR recognition results lack structure, and it is difficult to adapt to multiple styles and a large number of paper documents, resulting in low work efficiency, large development volume, low economy, and lack of Technical solutions with high adaptability and ease of use.
Using a document data extraction and processing method with customizable data structure, by creating a document matching style template, including the main anchor area, reference area and target area, OCR is used to identify text information, and matrix processing and matching are performed to generate structured data.
It achieves efficient and accurate extraction of structured data, improves work efficiency, reduces the amount of repetitive labor, lowers implementation costs and technical thresholds, and significantly improves the ease of use and economy of related products.
Smart Images

Figure CN118570812A
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of document data identification and processing, and in particular to a document data extraction and processing method with a customizable data structure. Background Art
[0002] In the digital application implementation scenarios of many industries, the task of re-electronicizing the content of paper documents is involved. The electronicized data is either used for table production or needs to be entered into other software systems for subsequent processing. At present, most of the methods for re-electronicizing paper documents are still manual extraction, and a small number of them use software or API interfaces with integrated general OCR capabilities to take photos and recognize, output the text and then extract it. Obviously, manual extraction is extremely inefficient and requires a lot of repetitive work, especially when there are many documents with complex logic; and the results of text recognition only through general OCR often lack structure. For situations such as uncertain document style, large document volume, and rotation, scaling, and offset of the identified photo material content, it is difficult to output stable structured business data, which has little effect on improving work efficiency, and requires a lot of development and adaptation work, which is not economical and unsatisfactory in terms of ease of use.
[0003] Therefore, there is still a lack of a highly adaptable, economical and easy-to-use technical solution for the task of stably extracting customized structured data from a large number of diverse paper documents.
[0004] With the evolution of image recognition technology, general OCR's ability to detect and recognize text and output text objects and areas has become more mature. On this basis, if we can overcome the important issue of efficient electronicization of multiple fixed styles and large amounts of paper documents, and be able to stably output customized structured form data, it will greatly save repetitive labor input, greatly improve data entry efficiency, significantly reduce business adaptation development, and significantly improve the usability of related integrated products. Summary of the invention
[0005] In order to solve the above technical problems, the technical solution provided by the first object of the present invention is: a document data extraction and processing method with a customizable data structure, comprising the following steps:
[0006] (1) Customizing the data structure to be extracted from the document according to actual business needs, where the data structure includes at least one data group, and each data group includes at least one data key-value pair;
[0007] (2) using the customized data structure and the style and content of the actual document, creating a document matching style template, the template including a main anchor area, a reference area, and at least one target area for matching the document, each target area corresponding to a data key-value pair in the data structure, and defining the coordinate range of the target area;
[0008] (3) receiving a document image to be recognized, and locating and extracting text information of each target area in the document image according to a style template matched with the document;
[0009] (4) Matrix processing is performed on the extracted text information to form a data structure in the form of a matrix;
[0010] (5) Match the matrix data structure with the customized data structure to generate a structured data output that is isomorphic to the customized data structure.
[0011] Furthermore, the specific steps of creating a document matching style template in step (2) include:
[0012] Analyze the style and content of the actual document and determine the target area where information needs to be extracted;
[0013] Define the main anchor area in the template to determine the overall position and orientation of the document;
[0014] Define the datum area as the reference point for coordinate transformation in subsequent processing;
[0015] According to the customized data structure, at least one target area is defined in the template, each target area corresponds to a data key-value pair in the data structure;
[0016] Determine the coordinate range of each target area, including the starting coordinates and the ending coordinates.
[0017] The specific steps of customizing the data structure to be extracted from the document in step (1) include:
[0018] Determine the data fields and data types that need to be extracted based on business needs;
[0019] Create at least one data group, each data group contains at least one data key-value pair, the key in the key-value pair represents the name of the data field, and the value represents the specific content or format of the data field;
[0020] Combine the created data groups into customized data structures.
[0021] Furthermore, the specific steps of creating a document matching style template in step (2) include:
[0022] Analyze the style and content of the actual document and determine the target area where information needs to be extracted;
[0023] Define the main anchor area in the template to determine the overall position and orientation of the document;
[0024] Define the datum area as the reference point for coordinate transformation in subsequent processing;
[0025] According to the customized data structure, at least one target area is defined in the template, each target area corresponds to a data key-value pair in the data structure;
[0026] Determine the coordinate range of each target area, including the starting coordinates and the ending coordinates.
[0027] Furthermore, the specific step of receiving the document image to be recognized in step (3) is to use OCR to scan the document image, recognize the text information in the image, and output list data including text position coordinates and recognition results, each list item contains the coordinates of the four corner points of the text area and the corresponding recognized text content and recognition confidence.
[0028] Furthermore, after step (3) and before step (4), the following steps are also included: traversing the text objects in the recognition result, matching them with the main anchor X data in the preset document template, determining the template that matches successfully, and marking the text object that matches X in the actual recognition result as the main anchor x. In this embodiment, we add a key step after step (3) and before step (4), that is, traversing the text objects in the recognition result and matching them with the main anchor X data in the preset document template. Through this step, we can determine the document image that successfully matches the template and accurately mark the main anchor x text object in the actual recognition result. The success or failure of the main anchor matching directly affects the accuracy of the matrix processing and matching in the subsequent steps, so this step is crucial to the entire processing flow.
[0029] Furthermore, the matrix processing process in step (4) includes:
[0030] Take out the coordinates of the main anchor X and auxiliary anchor Y regions in the template, calculate the center coordinates of each anchor region, and generate the coordinate basis vector F(XY) pointing from the center point of the main anchor X to the center point of the auxiliary anchor Y;
[0031] The recognition result is translated as a whole, and the coordinate offset from the center point of the main anchor x region to the center point of the region of the template main anchor X is calculated, recorded as Δ(Δx, Δy), and the coordinates of all text objects in the recognition result are added to the offset Δ(Δx, Δy) to complete the overall translation;
[0032] Match the auxiliary anchor Y text object in the target template in the translated recognition result, calculate the center coordinates of the auxiliary anchor y and the translated main anchor x, and generate the basic vector f(xy) of the actual recognition result data;
[0033] Based on the vector f(xy) and the vector F(XY), the rotation angle Δ(Degree) and the scaling factor Δ(Scale) of the transformation from f(xy) to F(XY) are calculated. This embodiment describes in detail the matrix processing process in step (4), including the steps of generating the coordinate basis vector, translating the recognition result, matching the auxiliary anchors with the generation of the basis vector, and calculating the coordinate transformation. Through this series of operations, we can transform the text object area in the recognition result from the original coordinate system to a coordinate system consistent with the template. This not only helps to eliminate the image deformation problem caused by factors such as shooting angle and scaling, but also improves the accuracy and efficiency of the subsequent matching process.
[0034] Furthermore, the matching process in step (5) specifically includes: using a two-layer nested traversal operation, traversing each recognition result, translating, rotating, and scaling the four corner coordinate points of each result area area, wherein the function expression is: f(area, Δ(Δ(x), Δ(y)), Δ(Degree), Δ(Scale))), and calculating the overlapping area ratio between the operated area and the template key area. When the ratio reaches a set threshold, the corresponding recognition result data is placed in the data container corresponding to the key value.
[0035] The matrix processing process in step (4) includes:
[0036] Take out the main anchor X and auxiliary anchor Y region coordinates in the template, calculate the center coordinates of each anchor region, and generate the coordinate basis vector F(XY) pointing from the center point of the main anchor X to the center point of the auxiliary anchor Y;
[0037] The recognition result is translated as a whole, and the coordinate offset from the center point of the main anchor x region to the center point of the region of the template main anchor X is calculated, recorded as Δ(Δx, Δy), and the coordinates of all text objects in the recognition result are added to the offset Δ(Δx, Δy) to complete the overall translation;
[0038] Match the auxiliary anchor Y text object in the target template in the translated recognition result, calculate the center coordinates of the auxiliary anchor y and the translated main anchor x, and generate the basic vector f(xy) of the actual recognition result data;
[0039] Based on the vector f(xy) and the vector F(XY), calculate the rotation angle Δ(Degree) and the scaling factor Δ(Scale) of transforming f(xy) to F(XY).
[0040] Furthermore, the matching process in step (5) specifically includes: using a two-layer nested traversal operation, traversing each recognition result, performing translation, rotation, and scaling operations on the four corner coordinate points of each result area area, wherein the function expression is: f(area, Δ(Δ(x), Δ(y)), Δ(Degree), Δ(Scale)), and calculating the overlapping area ratio of the result area area after the operation and the template key area. When the ratio reaches the set threshold, the corresponding recognition result data is placed in the data container corresponding to the key value.
[0041] The advantages of the present invention compared with the prior art are: by utilizing image recognition technology and customized data structure, efficient and accurate extraction of structured data from documents is achieved. Compared with the traditional general OCR method, this method has the advantage of being highly customized, and can customize data structure and extraction rules according to actual business needs, adapt to the structured data extraction needs of various documents, and improve applicability and flexibility. At the same time, by matching the document style template and defining the area coordinates, the method can accurately extract the text information of the target area, avoiding the recognition errors or missed recognition problems caused by the uncertainty of the document style in the general OCR method, and improving the accuracy of data extraction. In addition, the use of automated image recognition technology also greatly reduces the amount of repetitive work, improves work efficiency, and reduces the implementation cost and technical threshold, and improves the ease of use and economy of related products. In summary, this method has significant advantages in solving many challenges in the process of electronicization of paper documents, and will promote the application of digital transformation in various industries. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] Figure 1 It is a flowchart of a document data extraction and processing method with a customizable data structure in the present application.
[0043] Figure 2 It is a document identification diagram of an embodiment of a document data extraction and processing method with a customizable data structure of the present application. DETAILED DESCRIPTION
[0044] The present invention is further described in detail below in conjunction with the accompanying drawings.
[0045] The specific implementation of the present invention is further described below in conjunction with the accompanying drawings, wherein the same components are represented by the same reference numerals.
[0046] It should be noted that the words "front", "rear", "left", "right", "up" and "down" used in the following description refer to directions in the drawings, and the words "inside" and "outside" refer to directions toward or away from the geometric center of a specific component, respectively.
[0047] In order to make the contents of the present invention more clearly understood, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the accompanying drawings in the embodiments of the present invention.
[0048] Combined with Figure 1 -Attached Figure 2 , a document data extraction and processing method with a customizable data structure, comprising the following steps:
[0049] (1) Customizing the data structure to be extracted from the document according to actual business needs, where the data structure includes at least one data group, and each data group includes at least one data key-value pair;
[0050] (2) using the customized data structure and the style and content of the actual document, creating a document matching style template, the template including a main anchor area, a reference area, and at least one target area for matching the document, each target area corresponding to a data key-value pair in the data structure, and defining the coordinate range of the target area;
[0051] (3) receiving a document image to be recognized, and locating and extracting text information of each target area in the document image according to a style template matched with the document;
[0052] (4) Matrix processing is performed on the extracted text information to form a data structure in the form of a matrix;
[0053] (5) Match the matrix data structure with the customized data structure to generate a structured data output that is isomorphic to the customized data structure.
[0054] In one embodiment, the specific steps of customizing the data structure to be extracted from the document in step (1) include:
[0055] Determine the data fields and data types that need to be extracted based on business needs;
[0056] Create at least one data group, each data group contains at least one data key-value pair, the key in the key-value pair represents the name of the data field, and the value represents the specific content or format of the data field;
[0057] Combine the created data groups into customized data structures.
[0058] In one embodiment, the specific steps of creating a document matching style template in step (2) include:
[0059] Analyze the style and content of the actual document and determine the target area where information needs to be extracted;
[0060] Define the main anchor area in the template to determine the overall position and orientation of the document;
[0061] Define the datum area as the reference point for coordinate transformation in subsequent processing;
[0062] According to the customized data structure, at least one target area is defined in the template, each target area corresponds to a data key-value pair in the data structure;
[0063] Determine the coordinate range of each target area, including the starting coordinates and the ending coordinates.
[0064] In one embodiment, the specific step of receiving the document image to be identified in step (3) is to scan the document image using OCR, identify the text information in the image, and output a list data including the text position coordinates and the recognition result, each list item includes the four corner point coordinates of the text area and the corresponding recognized text content and the recognition confidence. In this embodiment, we further refine the specific process of receiving the document image to be identified and extracting text information in step (3). The document image is scanned and identified using OCR (optical character recognition) technology. The OCR engine can accurately identify the text content in the image and output a list data including the text position coordinates and the recognition result. Each list item records the four corner point coordinates of the text area in detail, and these coordinate information are crucial for locating the target area in the document image later. At the same time, each list item also includes the corresponding recognized text content and the recognition confidence, which helps to evaluate and screen the quality of the recognition results.
[0065] In one embodiment, after step (3) and before step (4), the following steps are also included: traversing the text objects in the recognition results, matching them with the main anchor X data in the preset document template, determining the template that matches successfully, and marking the text object matched to X in the actual recognition result as the main anchor x.
[0066] In one embodiment, the matrix processing process in step (4) includes:
[0067] Take out the main anchor X and auxiliary anchor Y region coordinates in the template, calculate the center coordinates of each anchor region, and generate the coordinate basis vector F(XY) pointing from the center point of the main anchor X to the center point of the auxiliary anchor Y;
[0068] The recognition result is translated as a whole, and the coordinate offset from the center point of the main anchor x region to the center point of the region of the template main anchor X is calculated, recorded as Δ(Δx, Δy), and the coordinates of all text objects in the recognition result are added to the offset Δ(Δx, Δy) to complete the overall translation;
[0069] Match the auxiliary anchor Y text object in the target template in the translated recognition result, calculate the center coordinates of the auxiliary anchor y and the translated main anchor x, and generate the basic vector f(xy) of the actual recognition result data;
[0070] Based on the vector f(xy) and the vector F(XY), calculate the rotation angle Δ(Degree) and the scaling factor Δ(Scale) of transforming f(xy) to F(XY).
[0071] In one embodiment, the matching process in step (5) specifically includes: using two layers of nested traversal operations, traversing each recognition result, performing translation, rotation, and scaling operations on the four corner coordinate points of each result area area, wherein the function expression is: f(area, Δ(Δ(x), Δ(y)), Δ(Degree), Δ(Scale))), and calculating the overlap area ratio of the area after the operation and the template key area, and when the ratio reaches the set threshold, the corresponding recognition result data is placed in the data container corresponding to the key value. In this embodiment, we elaborate on the matching process in step (5). By using two layers of nested traversal operations, each recognition result is translated, rotated, scaled, etc., so that it is aligned with the key area in the template. Then, the overlap area ratio of the area after the operation and the template key area is calculated. When the ratio reaches the set threshold, it is considered that the match is successful, and the corresponding recognition result data is placed in the data container corresponding to the key value. This process ensures that the structured data finally generated is isomorphic with the customized data structure, thereby meeting the needs of actual business.
[0072] Example 1
[0073] Now take a commercial concrete delivery note for a construction project as an example (specific application example), assuming that the data group structure customized for this document is as follows:
[0074] {"pm1v1receipt":["License plate number","Cargo name","Cargo specifications","Number on board","Driver"]}
[0075] The document matching template is as follows:
[0076] {"id":"d34d9f31aa49438caf7aa0fedbaeb066","id_other":"d34d9f31aa49438caf7aa0fedbaeb045","anchor_area":{"text":"Shenzhen Heshi Concrete Co., Ltd.","region":[[523.0,148.0],[859.0,148.0],[859.0,167.0],[523.0,167.0]]},"base_a rea":{"text":"Concrete delivery note","region":[[609.0,184.0],[769.0,184.0],[769.0,212.0],[609.0,212.0]]},"targets":{"pm1v1receipt":{"License plate number":{"region":[[460.0,306.0],[540.0,306.0],[540.0,330.0],[460.0,330.0]]},"text_to _delate":""},"Number of vehicles":{"region":[[763.0,351.0],[813.0,351.0],[813.0,371.0],[763.0,371.0]],"text_to_delate":""},"Cargo name":{"region":[[454.0,414.0],[543.0,417.0],[542.0,441.0],[453.0,438.0]],"text_to_delate ":""},"Cargo Specifications":{"region":[[848.0,417.0],[1004.0,421.0],[1004.0,444.0],[848.0,439.0]],"text_to_delate":""},"Driver":{"region":[[552.0,496.0],[651.0,496.0],[651.0,520.0],[552.0,520.0]],"text_to_delate":""}}}
[0077] Use the local camera to take a photo of the document, as shown in the attached Figure 2 As shown, or pass in base64 image data, call the written program, and output structured business data:
[0078] {"pm1v1receipt":{"license plate number":["Yue B6888L"],"vehicle load quantity":["12.253"],"goods name":["early strength concrete"],"goods specification":["C35P6 (12% micro-expansion)"],"driver":["Jason Statham"]}}
[0079] By testing the multi-sample recognition and output results, it can be seen that this method can use a customized document data template and combine the "algorithm ability to calculate the position of the general OCR text detection results through matrix operations and then output structured data" to stably output structured business data, providing considerable convenience for relevant subsequent work.
[0080] This document matching template is a data extraction template for concrete delivery notes, which defines how to accurately extract specific information from the input document image. The following is a detailed interpretation of this template:
[0081] Template ID:
[0082] id: The unique identifier of the template, used to distinguish different templates.
[0083] id_other: Template identifier or alternative ID.
[0084] Main anchor area (anchor_area):
[0085] Text: The text content of the main anchor area, which is "Shenzhen He's Bi Concrete Co., Ltd." here.
[0086] Region: The coordinate range of the main anchor area, represented by the coordinates of four points to form a rectangular area. These coordinates are usually used to locate the main anchor area in the image for subsequent operations.
[0087] Reference area (base_area):
[0088] text: The text content of the reference area, which is "Concrete Delivery Note" here.
[0089] region: The coordinate range of the reference area, also represented by the coordinates of four points. The reference area is usually used to further confirm the correctness of the document or as a reference for aligning other areas.
[0090] Target area (targets):
[0091] pm1v1receipt: This is the key of the target data structure, representing a specific data group structure.
[0092] License Plate Number: Defines the coordinate range of the area where the license plate number text is located, and has a text_to_delate field, which is usually used to store characters or strings that need to be deleted from the extracted text (empty here).
[0093] Number of Vehicles Carried: Defines the coordinate range of the area where the number of vehicles carried text is located.
[0094] Goods Name: Defines the coordinate range of the area where the goods name text is located.
[0095] Goods Specification: Defines the coordinate range of the area where the goods specification text is located.
[0096] Driver: Defines the coordinate range of the area where the driver's name text is located.
[0097] Output Business Data:
[0098] This is the structured data extracted from the document picture according to the template. For example, the value of the license plate number is ['Yue B6888L'], indicating that the license plate number recognized from the document picture is "Yue B6888L".
[0099] The above describes the present invention and its implementation manners. Such description is not restrictive. What is shown in the drawings is only one of the implementation manners of the present invention, and the actual structure is not limited thereto. Generally speaking, if those of ordinary skill in the art are inspired by it and without departing from the purpose of the present invention creation, they design similar structural manners and embodiments to this technical solution without creative efforts, which shall fall within the protection scope of the present invention.
Claims
1. A document data extraction and processing method with a customizable data structure, characterized in that: The following steps are involved: (1) Customize the data structure to be extracted from the document according to actual business needs. The data structure is organized in a hierarchical form and includes at least one data group. Each data group has a unique identifier and contains at least one data key-value pair, where the key is used to identify the data type or attribute, and the value represents the specific data content; (2) using the customized data structure and the style and content of the actual document, creating a document matching style template, the template containing multiple defined regions, including a main anchor region for global positioning, a reference region for local alignment, and at least one target region corresponding to a data key-value pair, each target region having a clear coordinate range for locating and extracting corresponding text information in the document image; (3) receiving a document image to be recognized, and locating and extracting text information of each target area in the document image according to a style template matched with the document; (4) performing matrix processing on the extracted text information, combining the text information with the coordinate range of the target area to form a data structure in the form of a matrix; (5) Match the matrix data structure with the customized data structure, and generate structured data output that is isomorphic to the customized data structure by comparing key values and structures.
2. A document data extraction and processing method with a customizable data structure according to claim 1, characterized in that: in, The specific steps for customizing the data structure to be extracted from the document in step (1) include: Determine the data fields and data types that need to be extracted based on business needs; Create at least one data group, each data group contains at least one data key-value pair, the key in the key-value pair represents the name of the data field, and the value represents the specific content or format of the data field; Combine the created data groups into customized data structures.
3. A document data extraction and processing method with a customizable data structure according to claim 2, characterized in that: The specific steps for creating a document matching style template in step (2) include: Analyze the style and content of the actual document and determine the target area where information needs to be extracted; Define the main anchor area in the template to determine the overall position and orientation of the document; Define the datum area as the reference point for coordinate transformation in subsequent processing; According to the customized data structure, at least one target area is defined in the template, each target area corresponds to a data key-value pair in the data structure; Determine the coordinate range of each target area, including the starting coordinates and the ending coordinates.
4. A document data extraction and processing method with a customizable data structure according to claim 3, characterized in that: The specific steps of receiving the document image to be recognized in step (3) are to use OCR to scan the document image, recognize the text information in the image, and output list data including text position coordinates and recognition results, each list item contains the coordinates of the four corner points of the text area and the corresponding recognized text content and recognition confidence.
5. A document data extraction and processing method with a customizable data structure according to claim 4, characterized in that: After step (3) and before step (4), the following steps are also included: traverse the text objects in the recognition result, match them with the main anchor X data in the preset document template, determine the template that matches successfully, and mark the text object matched to X in the actual recognition result as the main anchor x.
6. A document data extraction and processing method with a customizable data structure according to claim 5, characterized in that: in, The matrix processing process in step (4) includes: Take out the coordinates of the main anchor X and auxiliary anchor Y regions in the template, calculate the center coordinates of each anchor region, and generate the coordinate basis vector F(XY) pointing from the center point of the main anchor X to the center point of the auxiliary anchor Y; The recognition result is translated as a whole, and the coordinate offset from the center point of the main anchor x region to the center point of the region of the template main anchor X is calculated, recorded as Δ(Δx, Δy), and the coordinates of all text objects in the recognition result are added to the offset Δ(Δx, Δy) to complete the overall translation; Match the auxiliary anchor Y text object in the target template in the translated recognition result, calculate the center coordinates of the auxiliary anchor y and the translated main anchor x, and generate the basic vector f(xy) of the actual recognition result data; Based on the vector f(xy) and the vector F(XY), calculate the rotation angle Δ(Degree) and the scaling factor Δ(Scale) of transforming f(xy) to F(XY).
7. A document data extraction and processing method with a customizable data structure according to claim 6, characterized in that: in, The matching process in step (5) specifically includes: using a two-layer nested traversal operation to traverse each recognition result, and performing translation, rotation, and scaling operations on the four corner coordinate points of each result area area, where the function expression is: f(area, Δ(Δ(x), Δ(y)), Δ(Degree), Δ(Scale)), and calculating the overlapping area ratio of the result area area after the operation and the template key area. When the ratio reaches the set threshold, the corresponding recognition result data is placed in the data container corresponding to the key value.
