Table restoration method and device
Through the combination of the cell detection model and the text recognition model, cells are directly detected and text blocks are recognized, and table data is generated, which solves the problems of high coupling and high implementation cost of table recognition in the existing technology, and achieves high accuracy and Widely applicable table restoration effect.
Patent Information
- Application Number
- CN202310280327.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-21
- Publication Date
- 2024-08-30
AI Technical Summary
Existing table recognition solutions have problems such as high coupling, high positioning error rate and high implementation cost when identifying cells and text information in table images. In particular, the performance is poor for tables without frame lines or images with unclosed frame lines.
The cell detection model is used to directly detect cell position information and row and column expansion information, combined with the text recognition model to identify text block position information, and generate tabular data by matching cells and text blocks, which reduces the amount of preparation information for model training and is suitable for wireless applications. Frame table.
It achieves high-accuracy table restoration, reduces implementation costs, expands the scope of application, and is suitable for table images in complex and edge cases.
Smart Images

Figure CN118570826A
Abstract
Description
Technical Field
[0001] The present disclosure generally relates to the field of table recognition, and more specifically, to a table restoration method and a table restoration device. Background Art
[0002] Table restoration technology is a challenging task. It restores table images into structured tables (such as HTML, EXCEL, etc.) by identifying key information on table images, allowing users to further edit the contents of the table images.
[0003] There are two main types of table recognition solutions on the market. One is the Image2Sequence solution, which directly outputs the table structure HTML sequence and cell content based on the image. The defect of this type of solution is that the coupling degree is too high, all processes are omitted, and the HTML sequence is directly output, which makes it difficult to locate the cause of the error and the accuracy is not high. The other type is the first segmentation and then merge solution, which requires the use of pre-defined traditional machine vision rules or deep learning-based segmentation solutions to segment the row and column dividing lines of the table, and then divide the table image into multiple independent cells according to the row and column dividing lines, and then predict how to merge independent cells to restore the span information of the merged cells. Although this type of solution can decouple the table restoration process, it needs to provide complex row and column dividing line training samples and reference point training samples, and also needs to provide subsequent relationship networks to restore the merged cells. Too much preparation information leads to high implementation costs. At the same time, this type of solution performs poorly for borderless tables or table images with open borders, and has a limited scope of application. Summary of the invention
[0004] The present disclosure provides a table restoration method and a table restoration device, which are used to at least solve the above problems, or may not solve the above problems.
[0005] According to one aspect of the present disclosure, a table restoration method is provided, the table restoration method comprising: acquiring a target table image; detecting cells in the target table image using a cell detection model to obtain position information and row and column expansion information of multiple cells; identifying text blocks in the target table image using a text recognition model to obtain position information and text information of multiple text blocks; matching the position information of the multiple cells with the position information of the multiple text blocks to determine at least one text block corresponding to each of the multiple cells; generating target table data corresponding to the target table image based on the position information and row and column expansion information of the multiple cells, and the text information of the text block corresponding to each cell.
[0006] Optionally, the cell detection model is used to detect cells in the target table image to obtain position information and row and column extension information of multiple cells, including: inputting the target table image into the cell detection model to perform cell position prediction to obtain position information and predicted row and column extension information of multiple cells, the predicted row and column extension information including the number of rows and columns spanned by the cell; for cells whose number of rows and columns spanned are less than or equal to preset values, the predicted row and column extension information is used as the row and column extension information of the corresponding cell; cells whose number of rows and columns spanned is greater than the preset value are marked as merged cells, and for each of the merged cells, the predicted row and column extension information of the merged cell is corrected according to the row and column extension information of other cells adjacent to the merged cell to obtain the row and column extension information of the merged cell.
[0007] Optionally, the cell detection model is used to detect cells in the target table image to obtain location information and row and column expansion information of multiple cells, including: using the cell detection model to detect blank areas in the target table image, and if the spacing between the blank areas and adjacent cells meets a preset spacing, determining the blank areas as cells; wherein the blank areas are areas in the target table image that are not determined as cells by the cell detection model.
[0008] Optionally, the cell detection model is trained by the following steps: obtaining a sample table image and reference position information and reference row and column extension information of each cell in the sample table image; using the sample table image as a training sample and the reference position information and reference row and column extension information of each cell in the sample table image as a training target, and training to obtain the cell detection model.
[0009] Optionally, the cell detection model is at least one of the following: a real-time target detection model, a faster regional convolutional neural network model, and a detection transformer model.
[0010] Optionally, the cell position information and the text block position information both include the coordinates of the upper left vertex and the coordinates of the lower right vertex; matching the position information of the multiple cells with the position information of the multiple text blocks to determine at least one text block corresponding to each of the multiple cells includes: for each text block, traversing the multiple cells, and determining a reference distance between the text block and the current cell based on a first distance between the upper left vertex of the text block and the upper left vertex of the current cell and a second distance between the lower right vertex of the text block and the lower right vertex of the current cell; determining the cell corresponding to the text block based on the reference distance between the text block and each of the multiple cells, and reverse summarizing to obtain at least one text block corresponding to each of the multiple cells.
[0011] Optionally, determining the reference distance between the text block and the current cell based on a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell includes: calculating a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell; determining the smaller of the first distance and the second distance as a reference distance; and calculating a sum of the first distance, the second distance, and the reference distance as the reference distance between the text block and the current cell.
[0012] Optionally, determining the cell corresponding to the text block based on the reference distance between the text block and each cell in the multiple cells includes: if there is a minimum value in the reference distance between the text block and each cell in the multiple cells, determining the cell corresponding to the minimum value as the cell corresponding to the text block; if there are at least two minimum values in the reference distance between the text block and each cell in the multiple cells, determining the intersection and union ratio of the text block and at least two cells corresponding to the at least two minimum values, and determining the cell corresponding to the text block based on the intersection and union ratio of the text block and the at least two cells.
[0013] Optionally, the target table data corresponding to the target table image is generated based on the position information and row and column expansion information of the multiple cells and the text information of the text block corresponding to each cell, including: determining the reading order and line break information of the multiple cells according to the position information of the multiple cells, wherein the reading order is the order obtained by sorting the cells in the target table image row by row and column by column, and the line break information is information indicating whether the corresponding cell is a cell in the first column but not in the first row; generating the row and column expansion information of each cell and the text information of at least one corresponding text block one by one in the form of table data according to the reading order and line break information of the multiple cells to obtain the target table data corresponding to the target table image.
[0014] Optionally, determining the reading order of the multiple cells according to the position information of the multiple cells includes: determining a first reading order of the multiple cells according to the position order from top to bottom and from left to right according to the position information of the multiple cells; in response to a reading order correction instruction, inputting a cell sequence composed of the multiple cells into a feature extraction network of a cell reading order extraction model for encoding to obtain an implicit cell reading feature sequence; based on a feature adjustment network of the cell reading order extraction model, adjusting the implicit cell reading feature sequence in parallel using a time step sequence to obtain an estimated cell reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; determining an estimated cell reading sequence according to the estimated cell reading feature sequence, wherein the estimated cell reading sequence is used to represent a second reading order of the multiple cells; and determining the second reading order as the reading order of the multiple cells.
[0015] Optionally, the reading order correction instruction is an instruction input by a user; and / or the reading order correction instruction is an instruction generated when a preset verification condition is not met, and the preset verification condition is a condition indicating that the first reading order can meet the table reading requirements.
[0016] Optionally, the table restoration method further includes: for each cell, if the cell corresponds to at least two text blocks, splicing the text information of the at least two text blocks according to the reference order of the at least two text blocks. Wherein, the reference order is a position order from top to bottom and from left to right; or the reference order is obtained by the following steps: inputting the text block sequence composed of the at least two text blocks into the feature extraction network of the text block reading order extraction model for encoding to obtain an implicit text block reading feature sequence; based on the feature adjustment network of the text block reading order extraction model, adjusting the implicit text block reading feature sequence in parallel using a time step sequence to obtain an estimated text block reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; determining an estimated text block reading sequence based on the estimated text block reading feature sequence, wherein the estimated text block reading sequence is used to represent the reference order.
[0017] According to another aspect of the present disclosure, a table restoration device is provided, and the table restoration device includes: an acquisition unit, configured to acquire a target table image; a detection unit, configured to detect cells in the target table image using a cell detection model, and obtain position information and row and column expansion information of multiple cells; a recognition unit, configured to recognize text blocks in the target table image using a text recognition model, and obtain position information and text information of multiple text blocks; a matching unit, configured to match the position information of the multiple cells with the position information of the multiple text blocks, and determine at least one text block corresponding to each of the multiple cells; and a generation unit, configured to generate target table data corresponding to the target table image based on the position information and row and column expansion information of the multiple cells, and the text information of the text block corresponding to each cell.
[0018] Optionally, the detection unit is further configured to: input the target table image into the cell detection model for cell position prediction, obtain position information of multiple cells and predicted row and column extension information, the predicted row and column extension information including the number of rows and columns spanned by the cell; for cells whose number of rows and columns spanned are less than or equal to preset values, use the predicted row and column extension information as the row and column extension information of the corresponding cell; record cells whose number of rows and columns spanned is greater than the preset value as merged cells, and for each of the merged cells, correct the predicted row and column extension information of the merged cell according to the row and column extension information of other cells adjacent to the merged cell to obtain the row and column extension information of the merged cell.
[0019] Optionally, the detection unit is further configured to: use the cell detection model to detect a blank area in the target table image, and if the spacing between the blank area and adjacent cells meets a preset spacing, determine the blank area as a cell; wherein the blank area is an area in the target table image that is not determined as a cell by the cell detection model.
[0020] Optionally, the cell detection model is trained by the following steps: obtaining a sample table image and reference position information and reference row and column extension information of each cell in the sample table image; using the sample table image as a training sample and the reference position information and reference row and column extension information of each cell in the sample table image as a training target, and training to obtain the cell detection model.
[0021] Optionally, the cell detection model is at least one of the following: a real-time target detection model, a faster regional convolutional neural network model, and a detection transformer model.
[0022] Optionally, the position information of the cell and the position information of the text block both include the coordinates of the upper left corner vertex and the coordinates of the lower right corner vertex; the matching unit is further configured to: for each text block, traverse the multiple cells, and determine the reference distance between the text block and the current cell according to a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell; determine the cell corresponding to the text block according to the reference distance between the text block and each cell in the multiple cells, and reversely summarize to obtain at least one text block corresponding to each cell in the multiple cells.
[0023] Optionally, the matching unit is further configured to: calculate a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell; determine the smaller of the first distance and the second distance as a reference distance; calculate the sum of the first distance, the second distance and the reference distance as a reference distance between the text block and the current cell.
[0024] Optionally, the matching unit is further configured to: if there is a minimum value in the reference distance between the text block and each of the multiple cells, determine the cell corresponding to the minimum value as the cell corresponding to the text block; if there are at least two minimum values in the reference distance between the text block and each of the multiple cells, determine the intersection and union ratio of the text block and at least two cells corresponding to the at least two minimum values, and determine the cell corresponding to the text block based on the intersection and union ratio of the text block and the at least two cells.
[0025] Optionally, the generating unit is further configured to: determine a reading order and line break information of the multiple cells according to position information of the multiple cells, wherein the reading order is an order obtained by sorting the cells in the target table image row by row and column by column, and the line break information is information indicating whether the corresponding cell is a first-column but not-first-row cell; generate row and column extension information of each cell and text information of at least one corresponding text block one by one in the form of table data according to the reading order and line break information of the multiple cells, and obtain target table data corresponding to the target table image.
[0026] Optionally, the generation unit is further configured to: determine a first reading order of the multiple cells according to the position information of the multiple cells in a position order from top to bottom and from left to right; in response to a reading order correction instruction, input the cell sequence composed of the multiple cells into a feature extraction network of a cell reading order extraction model for encoding to obtain an implicit cell reading feature sequence; based on a feature adjustment network of the cell reading order extraction model, adjust the implicit cell reading feature sequence in parallel using a time step sequence to obtain an estimated cell reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; determine an estimated cell reading sequence according to the estimated cell reading feature sequence, wherein the estimated cell reading sequence is used to represent a second reading order of the multiple cells; and determine the second reading order as the reading order of the multiple cells.
[0027] Optionally, the reading order correction instruction is an instruction input by a user; and / or the reading order correction instruction is an instruction generated when a preset verification condition is not met, and the preset verification condition is a condition indicating that the first reading order can meet the table reading requirements.
[0028] Optionally, the table restoration device further includes a splicing unit configured to splice the text information of the at least two text blocks for each cell, according to the reference order of the at least two text blocks, if the cell corresponds to at least two text blocks. The reference order is a position order from top to bottom and from left to right; or the reference order is obtained by the following steps: inputting the text block sequence consisting of the at least two text blocks into the feature extraction network of the text block reading order extraction model for encoding to obtain an implicit text block reading feature sequence; based on the feature adjustment network of the text block reading order extraction model, adjusting the implicit text block reading feature sequence in parallel using a time step sequence to obtain an estimated text block reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; determining an estimated text block reading sequence based on the estimated text block reading feature sequence, wherein the estimated text block reading sequence is used to represent the reference order.
[0029] According to another aspect of the present disclosure, a computer-readable storage medium storing instructions is provided, wherein when the instructions are executed by at least one computing device, the at least one computing device is prompted to perform the table restoration method as described above.
[0030] According to another aspect of the present disclosure, a system is provided, including at least one computing device and at least one storage device storing instructions, wherein when the instructions are executed by the at least one computing device, the at least one computing device is prompted to perform the table restoration method as described above.
[0031] According to the table restoration method and table restoration device of the exemplary embodiment of the present disclosure, a decoupling method is used to restore table data with high accuracy. At the same time, the cell detection model is used to directly detect the cell position information and row and column expansion information, which does not rely on the row and column dividing lines, can reduce the amount of information prepared in the model training process, reduce the implementation cost, and can be applied to tables without frame lines or tables with open frame lines, greatly expanding the scope of application.
[0032] Additional aspects and / or advantages of the present general inventive concept will be set forth in part in the following description and in part will be apparent from the description or may be learned through practice of the present general inventive concept. BRIEF DESCRIPTION OF THE DRAWINGS
[0033] These and / or other aspects and advantages of the present disclosure will become clear and more easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:
[0034] Figure 1 is a flowchart illustrating a table restoration method according to an exemplary embodiment of the present disclosure;
[0035] Figure 2is a flowchart illustrating a table restoration method according to an exemplary embodiment of the present disclosure;
[0036] Figure 3 is a schematic diagram showing a target table image according to a specific embodiment of the present disclosure;
[0037] Figure 4 is a schematic diagram showing a principle of determining a reference distance according to an exemplary embodiment of the present disclosure;
[0038] Figure 5 is a schematic diagram showing the principle of determining line break information of a current text block according to an exemplary embodiment of the present disclosure;
[0039] Figure 6 is a schematic diagram showing a flow chart of generating target table data in HTML format according to an exemplary embodiment of the present disclosure;
[0040] Figure 7 is a block diagram illustrating a table restoration apparatus according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION
[0041] The following description with reference to the accompanying drawings is provided to assist in a comprehensive understanding of the embodiments of the present invention as defined by the claims and their equivalents. Various specific details are included to assist in understanding, but these details are considered to be exemplary only. Therefore, one of ordinary skill in the art will recognize that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. In addition, descriptions of well-known functions and structures are omitted for clarity and brevity.
[0042] It should be noted that the phrase "at least one of the items" in the present disclosure includes three types of parallel situations: "any one of the items", "a combination of any number of the items", and "all of the items". For example, "including at least one of A and B" includes the following three parallel situations: (1) including A; (2) including B; (3) including A and B. Another example is "executing at least one of step 1 and step 2" which means the following three parallel situations: (1) executing step 1; (2) executing step 2; (3) executing step 1 and step 2.
[0043] Refer to the following Figures 1 to 7 A table restoration method and a table restoration device according to exemplary embodiments of the present disclosure are described in detail.
[0044] Figure 1 is a flowchart illustrating a table restoration method according to an exemplary embodiment of the present disclosure. Figure 21 is a flow chart showing a table restoration method according to an exemplary embodiment of the present disclosure. The table restoration method according to an exemplary embodiment of the present disclosure can be implemented in a computing device with sufficient computing power.
[0045] Reference Figure 1 and Figure 2 , in step S101, the target table image is obtained. It should be understood that the target table image is a table image to be restored to table data, and the table data can be in HTML format or Excel format. In order to restore the table data, it is necessary to determine the information elements corresponding to each cell in the target table image, including the text information in the cell (i.e. the text content filled in the cell), the position information of the cell (i.e. the position coordinates of the cell, which can specifically include the coordinates of the upper left corner vertex and the coordinates of the lower right corner vertex of the coordinate box of the cell), and the row and column expansion information of the cell (used to indicate the merging of cells, including the number of rows n and columns m spanned by the cell, which can be in the form of nrmc, where r represents row, and c represents column, for example, when the number of rows spanned by the cell is n=1 and the number of columns is m=3, the row and column expansion information is 1r3c), etc. The present disclosure proposes a decoupling method. In order to determine this information, a series of information processing is required in subsequent steps.
[0046] In step S102, the cell detection model is used to detect the cells in the target table image to obtain the position information and row and column expansion information of multiple cells. Different from the method in the related art that relies on the row and column dividing lines, the present disclosure directly detects the position information and row and column expansion information of cells by using the cell detection model, which can reduce the amount of information prepared in the model training process, reduce the implementation cost, and can be applied to tables without frame lines or tables with open frame lines, greatly expanding the scope of application. In actual implementation, cells can be classified into n×m categories. As an example, n takes values from 1-50 and m takes values from 1-20. The role of the cell detection model is to use image recognition technology to identify the coordinate frame of the cell, determine the position information of the cell based on the coordinate frame, and further identify the category of the cell to obtain row and column expansion information.
[0047] Optionally, the cell detection model is trained by the following steps: obtaining a sample table image and reference position information and reference row and column extension information of each cell in the sample table image; using the sample table image as a training sample, using the reference position information and reference row and column extension information of each cell in the sample table image as a training target, and training to obtain a cell detection model. By directly annotating the reference position information and reference row and column extension information of each cell in the sample table image as a training sample, and then performing model training, the trained cell detection model can be made to have the ability to directly identify cells and cell position information and row and column extension information without having to rely on row and column dividing lines, thereby greatly reducing the amount of information prepared in training. As an example, a cell can be directly represented by the reference position information and reference row and column extension information of the cell, and the information of each cell can be arranged in a row-by-row and column-by-column order. Further, each cell can be configured with an ID, such as but not limited to a serial number, to assist in completing the labeling of the training sample, but in the process of training the model, these serial numbers are not used as output data of the model, so they do not participate in the training. The above is an exemplary description, and the present disclosure does not limit how to distinguish different cells.
[0048] Optionally, the cell detection model is at least one of the following: real-time target detection model (YOLO, You Only Look Once), faster regional convolutional neural network model (FasterRCNN, Faster Regions with Convolutional Neural Networks), detection transformer model (DETR, DEtection Transformer). These types of models have strong image recognition capabilities. By using these types of models as cell detection models, it is helpful to identify relatively accurate cells and their position information and row and column expansion information, providing reliable basic data for table restoration, helping to ensure the smooth progress of subsequent steps, and improving the efficiency of subsequent data processing.
[0049] Further, the applicant has analyzed and found that the row and column expansion information of small-scale cells (i.e. cells with a small number of rows and columns) detected by the cell detection model has a relatively high accuracy, while the row and column expansion information of large-scale cells (i.e. cells with a large number of rows and / or columns) may not be accurate enough. In this regard, optionally, step S102 includes: inputting the target table image into the cell detection model for cell position prediction, obtaining position information and predicted row and column expansion information of multiple cells, the predicted row and column expansion information including the number of rows and columns spanned by the cell; for cells whose number of rows and columns spanned is less than or equal to a preset value, using the predicted row and column expansion information as the row and column expansion information of the corresponding cell; recording a cell whose number of rows and columns spanned is greater than a preset value as a merged cell, and for each merged cell, correcting the predicted row and column expansion information of the merged cell according to the row and column expansion information of other cells adjacent to the merged cell, and obtaining the row and column expansion information of the merged cell. By first using the row and column expansion information of the cell detected by the cell detection model as the predicted row and column expansion information, and then further classifying the detected cells based on the preset values, for small-scale cells, directly using their predicted row and column expansion information as the row and column expansion information, and for large-scale cells (recorded as merged cells), referencing the predicted row and column expansion information of the cells adjacent to them for correction, and obtaining the final row and column expansion information, the accuracy of the row and column expansion information of the large-scale cells finally obtained can be improved, further ensuring the smooth progress of subsequent steps, and improving the subsequent data processing efficiency. It should be understood that the preset value can be reasonably configured according to the actual detection accuracy of the cell detection model adopted. A sufficiently small preset value helps to ensure information accuracy, and a sufficiently large preset value can reduce the amount of calculation caused by information correction and improve data processing efficiency. In addition, for the case where the positions of some large-scale cells are far away from the small-scale cells, we can start from the positions where the small-scale cells are concentrated, refer to the row and column extension information of the small-scale cells (equal to their predicted row and column extension information), and give priority to correcting the predicted row and column extension information of the large-scale cells that are adjacent to as many small-scale cells as possible in both the row and column dimensions, and then refer to the corrected row and column extension information of these large-scale cells to correct the predicted row and column extension information of other large-scale cells adjacent to these corrected large-scale cells, and so on gradually and recursively to achieve the correction of each large-scale cell.
[0050] Take the preset value equal to 1 as an example, refer to Figure 3According to the prediction of the cell detection model, the 1st row and 2nd column (XXXX Pharmaceutical Co., Ltd.), the 2nd row and 2nd column (AA Province BB City CC County DD Township EE Village Y Group), the 3rd row and 2nd column (AA Province BB City CC County DD Township EE Village Y Group), the 4th row and 4th column (FZR), the 5th row and 2nd column (original classification catalog: Class I; 6858 Medical cryotherapy, low temperature, refrigeration equipment and appliances; current classification catalog: Class I; 09 Physical therapy equipment), and the 6th row and 1st column (Production product list) are merged cells, and the remaining cells are small-scale cells spanning 1 row and 1 column. The predicted row and column extension information can be recorded as 1r1c. Assuming that the predicted row and column extension information of these merged cells is 1r10c, 1r10c, 1r10c, 1r2c, 1r10c, 5r1c, they need to be corrected. Since only the merged cells in the 6th row and 1st column and the 5th row and 2nd column meet the condition of being adjacent to as many small-scale cells as possible in both row and column dimensions, these two merged cells can be corrected first. The merged cell in the 6th row and 1st column has 4 small-scale cells on the right and 1 small-scale cell above, so the row and column extension information of the merged cell can be determined to be 4r1c; the merged cell in the 5th row and 2nd column has 1 small-scale cell on the left and 4 small-scale cells below, so the row and column extension information of the merged cell can be determined to be 1r4c, thereby realizing the correction of the predicted row and column extension information of these two merged cells. There are no other merged cells around the merged cell in the 6th row and 1st column. There is a merged cell in the 4th row and 4th column above the merged cell in the 5th row and 2nd column, and there are 2 small-scale cells in the same row as the merged cell in the 4th row and 4th column, so it can be determined that the number of rows spanned by the merged cell in the 4th row and 4th column is 1, and the number of columns is 4-2×1=2, so the row and column expansion information of the merged cell in the 4th row and 4th column is determined to be 1r2c, which is consistent with its predicted row and column expansion information. For the remaining three merged cells in the 3rd row and 2nd column, the 2nd row and 2nd column, and the 1st row and 2nd column, the recursive correction can be performed in the same way, and the row and column expansion information of the three is 1r4c, which will not be repeated here.
[0051] In addition, for a table without a frame or a table with an open frame, cells (especially blank cells without content) may be missed for detection. In this regard, optionally, step S102 includes: using a cell detection model to detect a blank area in the target table image, if the spacing between the blank area and the adjacent cells meets a preset spacing, the blank area is determined as a cell; wherein the blank area is an area in the target table image that is not determined as a cell by the cell detection model. By configuring a preset spacing, and judging the spacing between the blank area and the adjacent cells accordingly, the gap cells that have not been identified in the target table image can be supplemented, which helps to ensure the accuracy of cell detection. Specifically, the spacing between the blank area and the adjacent cells can be the distance between the center point of the blank area and the edge line of the coordinate box of the adjacent cell adjacent to the blank area. For the value of the preset spacing, a fixed value can be preset in advance, or it can be determined according to the size of each cell in the detected target table image, and different preset spacings can be used in combination with the positional relationship between the adjacent cells and the blank area used. As an example, half of the minimum width of all cells with row and column extension information of 1r1c detected by the cell detection model is used as the first preset spacing, and half of the minimum height of these cells is used as the second preset spacing; after detecting the blank area, determine the spacing between the center point of the blank area and the coordinate box of the adjacent cell. If the adjacent cells on the left / right side of the blank area are used, then when the spacing is greater than or equal to the first preset spacing, the blank area is determined as a cell. If the adjacent cells above / below the blank area are used, then when the spacing is greater than or equal to the second preset spacing, the blank area is determined as a cell. The above introduction to the definition of spacing, the value of the preset spacing, and how to determine the blank area as a cell is for exemplary purposes only and is not a limitation of the disclosed scheme. It should be understood that the gap cells identified by this scheme can be gap cells inside a table, for example Figure 3 The cell in the 4th row and 2nd column in the table may be detected as a blank area if there is no filled text. Whether the blank area is a cell can be determined based on the adjacent cells on its left / right side. The gap cells identified by this scheme can also be gap cells at the edge of the table, for example Figure 3 The cell in the 7th row and the 5th column in the image may be detected as a blank area, and whether the blank area is a cell can be determined based on the adjacent cells above it.
[0052] Return to reference Figure 1 and Figure 2In step S103, the text blocks in the target table image are identified using a text recognition model to obtain position information and text information of multiple text blocks. This step can be implemented using an existing text recognition model, and will not be described in detail here. In addition, similar to the position information of a cell, the position information of a text block may include the coordinates of the upper left corner vertex and the coordinates of the lower right corner vertex of the coordinate box of the text block.
[0053] In step S104, the position information of the plurality of cells is matched with the position information of the plurality of text blocks to determine at least one text block corresponding to each of the plurality of cells. This step is used to couple the cells detected in step S102 and the text blocks identified in step S103 to determine all the text blocks corresponding to each cell, thereby obtaining the main information elements required to determine the table data, specifically, obtaining the text information in the cell.
[0054] Optionally, step S104 includes: for each text block, traversing multiple cells, determining a reference distance between the text block and the current cell based on a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell; determining a cell corresponding to the text block based on the reference distance between the text block and each of the multiple cells, and reversely summarizing to obtain at least one text block corresponding to each of the multiple cells. By determining the first distance and the second distance based on the same position vertices, and then determining the reference distance between the text block and the cell, the reference distance can be used to intuitively reflect the positional relationship between the text block and the cell. Using the reference distance as a basis for determining the cell corresponding to the text block helps to improve matching accuracy. In addition, each cell may correspond to one or more text blocks (for example Figure 3 The cell in the 5th row and 2nd column in the image corresponds to multiple text blocks), while on the contrary, each text block corresponds to only one cell. By determining the cell corresponding to each text block, the uniqueness of the matching relationship can be guaranteed. Then, by reverse aggregation, all the text blocks corresponding to each cell can be obtained.
[0055] Optionally, in step S104, the step of determining the reference distance between the text block and the current cell includes: calculating a first spacing between the upper left vertex of the text block and the upper left vertex of the current cell and a second spacing between the lower right vertex of the text block and the lower right vertex of the current cell; determining the smaller of the first spacing and the second spacing as the reference spacing; calculating the sum of the first spacing, the second spacing, and the reference spacing as the reference distance between the text block and the current cell. Directly using the sum of the first spacing and the second spacing as the reference distance can basically meet the matching requirements in most cases. In particular, for the case where the text block is concentrated in a small area on the edge of the cell to which it belongs, if the size of another adjacent cell happens to be smaller, it may cause the reference distance between the text block and the adjacent cell to be smaller than the reference distance between the text block and the actual cell to which it belongs, thereby causing a misjudgment. Figure 4 For example, a text block has an upper left vertex a and a lower right vertex b. The left cell in the figure has an upper left vertex A1 and a lower right vertex B1, and the right cell has an upper left vertex A2 and a lower right vertex B2. Therefore, the first spacing and the second spacing between the text block and the left cell are L respectively. aA1 and L bB1 The first and second spacings between the text block and the right cell are L respectively. aA2 and L bB2 . It can be found through measurement that L aA1 +L bB1 Slightly smaller than L aA2 +L bB2 , which will cause the left cell to be determined as the cell corresponding to the text block. For this special case, the first and second spacings of the cells that are easily misjudged are often relatively close to the text block, while the first and second spacings of the cells to which the text block actually belongs are often quite different from the first and second spacings of the text block. Based on this, by further taking the smaller of the first spacing and the second spacing as the reference spacing, and taking the sum of the first spacing, the second spacing and the reference spacing as the reference distance, the difference in the reference distance between the text block and the two cells can be quickly widened with a minimal increase in the amount of calculation, so that the reference distance between the text block and the cell to which it actually belongs is smaller than the reference distance between the text block and the cell that is easily misjudged, thereby improving the matching reliability. Figure 4 In the example shown, the reference distance between the text block and the left cell is L aA1 +2L bB1 , the reference distance between the text block and the right cell is 2L aA2 +L bB2 , the former is greater than the latter, then it can be determined that the cell corresponding to the text block is the right cell.
[0056] Optionally, in step S104, the step of determining the cell corresponding to the text block according to the reference distance between the text block and each of the multiple cells includes: if there is a minimum value in the reference distance between the text block and each of the multiple cells, determining the cell corresponding to the minimum value as the cell corresponding to the text block; if there are at least two minimum values in the reference distance between the text block and each of the multiple cells, determining the intersection and union ratio between the text block and at least two cells corresponding to the at least two minimum values, and determining the cell corresponding to the text block according to the intersection and union ratio between the text block and the at least two cells. For a text block, if there is a unique minimum reference distance, the cell corresponding to the text block is also uniquely determined. If there are at least two minimum reference distances, it is necessary to determine one from the corresponding at least two cells as the cell corresponding to the text block. The intersection over union (IOU) is the ratio of the intersection and union of two coordinate frames, which is used to measure the accuracy of the position information of the prediction result in the target detection task. The higher the overlap of the two coordinate frames, the larger the intersection between the two, the smaller the union, and the larger the intersection over union ratio. By determining the intersection-and-union ratio (IOU) of the text block and the at least two cells, the IOU can be used to intuitively reflect the degree of overlap between the text block and the at least two cells, thereby effectively determining the cell corresponding to the text block. In addition, the amount of calculation for the reference distance is less than that for the IOU. By first determining the cell corresponding to the text block based on the reference distance, and then making a further determination based on the IOU for situations that cannot be determined, the overall amount of calculation can be effectively reduced, computing resources can be saved, and matching efficiency can be improved. In actual implementation, the IOU can be used directly to determine the cell with the largest IOU as the cell corresponding to the text block. The IOU can also be further processed to reasonably determine the cell corresponding to the text block. For example, 1-IOU is calculated, and then the cell with the smallest 1-IOU value is determined as the cell corresponding to the text block. The present disclosure does not limit this.
[0057] Return to reference Figure 1 In step S105, based on the position information and row and column expansion information of multiple cells, as well as the text information of the text block corresponding to each cell, the target table data corresponding to the target table image is generated. The above steps determine the main information elements required to determine the table data, based on which the corresponding target table data can be generated.
[0058] Optionally, refer to Figure 2, step S105 includes: determining the reading order and line break information of the multiple cells according to the position information of the multiple cells, wherein the reading order is the order obtained by sorting the cells in the target table image row by row and column by column, and the line break information is information indicating whether the corresponding cell is a cell in the first column but not in the first row; generating row and column extension information of each cell and text information of at least one corresponding text block one by one in the form of table data according to the reading order and line break information of the multiple cells, and obtaining the target table data corresponding to the target table image. The reading order reflects the sequential sequence obtained after sorting all the cells. Combined with the line break information, it is possible to determine how to divide all the cells into multiple rows, so as to obtain the complete arrangement of each cell in the target table image, and then generate the target table data to achieve reliable table restoration. As an example, the reading order can be obtained according to the coordinates of the upper left corner vertices of all the cells, in order from left to right and from top to bottom; the line break information can be obtained for each cell by comparing the position information of the current cell and the previous cell (the previous cell sorted in the reading order). For the line break information, for example, refer to Figure 5 , the previous cell has the upper left vertex A3 and the lower right vertex B3, the current cell has the upper left vertex A4 and the lower right vertex B4. According to the convention of image processing, the origin of the coordinate axis is located in the upper left of the image. The more to the right, the larger the horizontal coordinate value, and the more downward, the larger the vertical coordinate value. First determine whether the inequality y is satisfied A4 +gap>y B3 , where the size of the gap is only a few pixels. This inequality indicates that the current cell is located below the previous cell as a whole. If this inequality is satisfied, it can be determined that the current cell is the first column but not the first row cell and needs to wrap, that is, the wrap information is yes. Figure 5 As shown in the figure, A4 is obviously above B3, which does not satisfy the inequality. We need to further determine whether the inequality y is satisfied at the same time. A4 >y A3 and the inequality x B4 <x A3 Among them, the inequality y A4 >y A3 This means that A4 is below A3, and the upper edge of the coordinate box of the current cell is lower than the upper edge of the coordinate box of the previous cell. Combined with the situation where the first inequality is not satisfied, it can be determined that the upper edge of the coordinate box of the current cell is between the upper and lower edges of the coordinate box of the previous cell, and the current cell is not completely aligned with the previous cell in the row dimension. B4 <x A3 Indicates that the current cell is located on the left side of the previous cell. Since the current cell is after the previous cell, if the two cells belong to the same row, the current cell should be located on the right side of the previous cell, that is, xB3 <x A4 , or at least should satisfy x B3 <x B4 . Therefore, if it is determined at this time that the current cell is located on the left side of the previous cell as a whole, it can be determined that the two cells do not belong to the same row, and the current cell is a cell in the first column but not the first row, and needs to wrap, that is, the line break information is yes. Regarding the timing of determining the line break information, the line break information can be determined in advance before generating the target table data, or the line break information of the current cell can be determined when generating the information data of each cell one by one. The present disclosure does not limit this.
[0059] Figure 6 1 is a flow chart showing the process of generating target table data in HTML format according to an exemplary embodiment of the present disclosure. It should be noted in advance that is the start tag of a row and is the end tag of a row, which are used to define a row in an HTML table. is the start tag of a cell and is the end tag of a cell, which are used to define a standard cell in an HTML table. Figure 6 , when generating the target table data, first define html_code to represent the target table data in HTML format, and clear its content. Then use the compound operator "+=" to write new data in the form of "html_code+=". Specifically, first sort all cells in reading order to get the cell list cell_boxes, and then process each cell cell_box[i] in sequence one by one. The first step of processing one by one is to write the start tag of the row. For the first cell (i.e. i==0), the default is the first row and first column cell, and the start tag of the row is written directly; for other cells, it is necessary to determine the line break information, that is, to determine whether the current cell is the first column but not the first row cell. For details, please refer to the previous text, and combine the current cell cell_box[i] and the previous cell cell_box[i-1] to realize the judgment. If so, it is necessary to write the end tag of the row to make it clear that the data of the previous row of cells has been fully generated, and continue to write the start tag of the row to start the data generation of the new row of cells. If not, the data of the current row has not been fully generated, and no data needs to be written at this time. The second step of processing one by one is to write the start tag of the cell and the row and column extension information of the current cell. For the smallest cell of 1r1c, directly write the start tag of the cell; for other cells, you need to add row and column extension information in the start tag, specifically, the meaning of n and m refers to the previous text, in Figure 6 The third step of processing one by one is to write the text information of the current cell and the end tag of the cell. After processing one by one, write the end tag of the last row and end it with html_code=" "+html_code+" ", add at the beginning of all data , and add at the end of all data
[0060]
[0061]
[0062]
[0063]
[0064]
[0065]
[0066]
[0067]
[0068]
[0069]
[0070]
[0071] Figure 2
[0072]
[0073] Figure 7
[0074] Figure 7
[0075]
[0076]
[0077]
[0078]
[0079]
[0080]
[0081]
[0082]
[0083]
[0084]
[0085]
[0086]
[0087]
[0088]
[0089]
[0090]
[0091] Figures 1 to 7
[0092] Figure 7
[0093] Figure 1
[0094] Figure 1
[0095]
[0096] Figure 7
[0097]
[0098]
[0099]
[0100]
[0101]
[0102]
[0103]
[0104]
[0105]
[0106] Figure 1
[0107] Figure 1
[0108] , to meet the format requirements of HTML data. So far, the target table data in complete HTML format has been generated, and can be further converted into the target table data in EXCEL format. In addition, regarding the reading order, generally speaking, the reading order from left to right and from top to bottom can meet the reading requirements of the table, but for inclined text, or when there are defects in the prediction of cell positions, for example, when the vertical coordinates of the upper left corner vertices of two adjacent cells are very different, it is difficult to determine the relationship between the two in the row dimension. This simple rule often cannot meet the reading requirements. In this regard, optionally, in step S105, the step of determining the reading order of the plurality of cells according to the position information of the plurality of cells includes: determining the first reading order of the plurality of cells according to the position order from top to bottom and from left to right according to the position information of the plurality of cells; in response to the reading order correction instruction, inputting the cell sequence composed of the plurality of cells into the feature extraction network of the cell reading order extraction model for encoding to obtain an implicit cell reading feature sequence; based on the feature adjustment network of the cell reading order extraction model, adjusting the implicit cell reading feature sequence in parallel using the time step sequence to obtain an estimated cell reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; determining an estimated cell reading sequence according to the estimated cell reading feature sequence, wherein the estimated cell reading sequence is used to represent the second reading order of the plurality of cells; and determining the second reading order as the reading order of the plurality of cells. By configuring the reading order correction instruction and the cell reading order extraction model, the first reading order can be determined according to a simple rule first, reducing the amount of calculation required for determining the reading order, and then in response to the reading order correction instruction, extracting the second reading order using the cell reading order extraction model, thereby correcting the first reading order using the second reading order, thereby ensuring the reliability of the reading order. It should be understood that in the case where no reading order correction instruction is received, the first reading order is determined as the reading order of multiple cells, and there is no need to determine the second reading order. Regarding the reading order correction instruction, in one example, the reading order correction instruction is an instruction input by the user. By configuring the instruction as an instruction input by the user, the user can manually determine whether the first reading order can meet the table reading requirements, thereby ensuring the reliability of the judgment result. As an example, a reading order confirmation instruction input by the user can also be configured to indicate that the user manually determines that the first reading order can meet the table reading requirements, and then there is no need to confirm the second reading order, and the first reading order is determined as the reading order of multiple cells; for the case where the user may not input instructions for a long time, a preset waiting time can be further configured, and the timing starts from the moment the first reading order is determined. If the timing reaches the preset waiting time and the reading order correction instruction input by the user is still not received, a reading order correction instruction or a reading order confirmation instruction is automatically generated, and which instruction to generate can be set as needed.In another example, the reading order correction instruction is an instruction generated when the preset verification condition is not met, and the preset verification condition is a condition indicating that the first reading order can meet the table reading requirements. By configuring the preset verification condition, the verification of whether the first reading order meets the table reading requirements can be automatically completed, reducing user operations, and helping to save time and improve the efficiency of table restoration. It should be understood that if the preset verification condition is met, the first reading order is determined as the reading order of multiple cells. It should also be understood that since the preset verification condition is a condition indicating that the first reading order can meet the table reading requirements, it can be flexibly configured according to the problems that may exist in the table image to be restored. For example, for tilted text, there may be a situation where the table in the table image is also tilted, resulting in the first reading order not being the actual row and column order of the table. At this time, it may be necessary to redetermine the second reading order, then the preset verification condition can be configured as the text block is vertical text, so that it can be determined that the preset verification condition is not met when the text block is tilted text. For another example, if the cell position detected by the cell detection model is defective, resulting in a large difference in the ordinates of the upper left corner vertices (of course, the lower right corner vertices can also be used, for ease of explanation, the upper left corner vertices are used uniformly below) of two adjacent cells, but not exceeding the row height of the cell, it is often difficult to determine whether the two cells are in the same row. At this time, the system may randomly determine the row relationship between the two, resulting in a problem in the first reading order itself, and the second reading order needs to be re-determined. In this regard, the preset verification condition can be a condition that can clearly determine the row relationship between any two adjacent cells, that is, a condition that can determine whether the two cells are in the same row, and the preset verification condition can be specifically configured as the difference in the ordinates of the upper left corner vertices of any two adjacent cells is less than a first preset value (at this time, it can be determined that the two cells are in the same row) or greater than a second preset value (at this time, it can be determined that the two cells are in different rows), wherein the first preset value is significantly less than the row height of the cell, for example, 10% of the row height, and the second preset value is slightly less than the row height of the cell, for example, 90% of the row height. When the ordinate value of the upper left vertex of any two adjacent cells is greater than or equal to the first preset value and less than or equal to the second preset value, it is determined that it is impossible to clearly determine whether the two cells are in the same row, that is, the preset verification condition is not met. As for how to determine the row height of a cell, as an example, you can first filter out cells that span 1 row and record them as single-row cells. Then, for each single-row cell, calculate the difference between the ordinate of its upper left vertex and the ordinate of its lower right vertex as the height of the cell. Finally, the statistical value of the height of all single-row cells (for example, but not limited to, the average, mode, median) is used as the row height of the cell. In another example, the reading order correction instruction can include both instructions entered by the user and instructions generated when the preset verification condition is not met. At this time, different rules can be configured as needed to use these two instructions simultaneously.For example, two instructions may have the same priority. As long as any one of the instructions is received, it is considered that the reading order correction instruction has been received; if neither of the two instructions is received, it is considered that the reading order correction instruction has not been received, and the first reading order is determined as the reading order of multiple cells. For another example, in order to reduce the risk of misjudgment of the preset verification conditions, the instructions input by the user may have a higher priority. If the reading order correction instruction input by the user is received, it is considered that the reading order correction instruction has been received regardless of whether the preset verification conditions are met. Similarly, the reading order confirmation instruction input by the user may be configured with reference to the example in which the reading order correction instruction is the instruction input by the user in the above text. If the reading order confirmation instruction input by the user is received, it is considered that the reading order correction instruction has not been received regardless of whether the preset verification conditions are met, and the first reading order is determined as the reading order of multiple cells. Furthermore, there may be a situation where the user's intention is unclear, that is, neither the reading order correction instruction input by the user nor the reading order confirmation instruction input by the user is received. In this regard, the above text may also be referred to, and the preset waiting time may be configured, and the timing may be started from the moment the first reading order is determined. Before the timing reaches the preset waiting time, if a reading order correction instruction or a reading order confirmation instruction input by the user is received, the instruction shall prevail; different from the above, if the timing reaches the preset waiting time and the reading order correction instruction or the reading order confirmation instruction input by the user is still not received, the judgment result of the preset verification condition shall prevail. If the preset verification condition is met, the reading order correction instruction is not generated, or a reading order confirmation instruction is generated, and if the preset verification condition is not met, a reading order correction instruction is generated. For another example, when the reading order correction instruction input by the user and the reading order correction instruction generated due to failure to meet the preset verification condition are received at the same time, it is considered that the reading order correction instruction is received, otherwise it is considered that the reading order correction instruction is not received, and the first reading order is determined as the reading order of multiple cells. It should be noted that the above introduction to the reading order correction instruction is exemplary and does not constitute a limitation on the protection scope of the present disclosure. Other reasonable implementation methods also fall within the protection scope of the present disclosure. Regarding the cell reading order extraction model, the model mainly includes a feature extraction network and a feature adjustment network. By introducing a time step sequence and using the time step sequence to parallelly adjust the implicit cell reading feature sequence extracted by the feature extraction network, the estimated cell reading sequence is obtained. The cells corresponding to each reading time step can be calculated in parallel, that is, the estimated cell reading sequence is decoded in parallel, which can greatly shorten the reasoning time and help improve the extraction efficiency of the second reading order.Wherein, referring to the cell sequence input into the cell reading order extraction model, it may include the position information of each cell arranged according to the first reading order, and may further include the text information of each cell, so as to use the text information to provide more information reference for determining the second reading order. For further introduction of the cell reading order extraction model, reference may be made to the prior art, the difference being that the prior art is for text blocks, while the cell reading order extraction model of the present disclosure is for cells, which will not be elaborated here. Optionally, before step S105, the table restoration method according to the exemplary embodiment of the present disclosure further includes: for each cell, if the cell corresponds to at least two text blocks, the text information of the at least two text blocks are spliced according to the reference order of the at least two text blocks. Wherein, the reference order is the position order from top to bottom and from left to right; or the reference order is obtained by the following steps: inputting a text block sequence consisting of at least two text blocks into a feature extraction network of a text block reading order extraction model for encoding to obtain an implicit text block reading feature sequence; based on a feature adjustment network of the text block reading order extraction model, using a time step sequence to parallelly adjust the implicit text block reading feature sequence to obtain an estimated text block reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; according to the estimated text block reading feature sequence, determining an estimated text block reading sequence, wherein the estimated text block reading sequence is used to represent the reference order. For the case where a cell corresponds to at least two text blocks, by splicing the text information of these text blocks according to the reference order, the text information in the cell as a whole can be obtained, thereby improving the efficiency of generating the target table data in step S105. The reference order can be directly determined according to the positional relationship of each text block, or it can be determined using a text block reading order extraction model, which enriches the reference order determination scheme and improves the flexibility and reliability of the scheme. It should be understood that the structure of the text block reading order extraction model is similar to that of the cell reading order extraction model, which can achieve the effect of greatly shortening the reasoning time and improving the extraction efficiency of the reference order. The text block reading order extraction model can refer to the existing technology and will not be elaborated here. As an example, the reference order can be determined by default according to the positional relationship, and the reference order correction instruction can be configured with reference to the reading order correction instruction; options can also be configured for users to set the reference order determination method in advance. The present disclosure is not limited to this. is a block diagram of a table restoration device according to an exemplary embodiment of the present disclosure. Referring to it, the table restoration device 700 includes an acquisition unit 701, a detection unit 702, an identification unit 703, a matching unit 704, and a generation unit 705. The acquisition unit 701 can acquire a target table image. The detection unit 702 can use a cell detection model to detect cells in the target table image to obtain position information and row and column expansion information of multiple cells.Optionally, the detection unit 702 may also: input the target table image into the cell detection model to predict the cell position, obtain the position information of multiple cells and the predicted row and column expansion information, the predicted row and column expansion information includes the number of rows and columns spanned by the cell; for cells whose number of rows and columns spanned are less than or equal to the preset value, use the predicted row and column expansion information as the row and column expansion information of the corresponding cell; record the cell whose number of rows and columns spanned is greater than the preset value as a merged cell, and for each merged cell, correct the predicted row and column expansion information of the merged cell according to the row and column expansion information of other cells adjacent to the merged cell, and obtain the row and column expansion information of the merged cell. Optionally, the detection unit 702 may also: use the cell detection model to detect the blank area in the target table image, and if the spacing between the blank area and the adjacent cells meets the preset spacing, determine the blank area as a cell; wherein the blank area is the area in the target table image that is not determined as a cell by the cell detection model. Optionally, the cell detection model is trained by the following steps: obtaining a sample table image and reference position information and reference row and column extension information of each cell in the sample table image; taking the sample table image as a training sample, taking the reference position information and reference row and column extension information of each cell in the sample table image as a training target, and training to obtain the cell detection model. Optionally, the cell detection model is at least one of the following: a real-time target detection model, a faster regional convolutional neural network model, and a detection transformer model. The recognition unit 703 can use the text recognition model to identify text blocks in the target table image and obtain the position information and text information of multiple text blocks. The matching unit 704 can match the position information of multiple cells with the position information of multiple text blocks to determine at least one text block corresponding to each of the multiple cells. Optionally, the location information of the cell and the location information of the text block both include the coordinates of the upper left vertex and the coordinates of the lower right vertex; the matching unit 704 may also: for each text block, traverse multiple cells, and determine the reference distance between the text block and the current cell according to the first spacing between the upper left vertex of the text block and the upper left vertex of the current cell and the second spacing between the lower right vertex of the text block and the lower right vertex of the current cell; determine the cell corresponding to the text block according to the reference distance between the text block and each of the multiple cells, and reversely summarize to obtain at least one text block corresponding to each of the multiple cells. Optionally, the matching unit 704 may also: calculate the first spacing between the upper left vertex of the text block and the upper left vertex of the current cell and the second spacing between the lower right vertex of the text block and the lower right vertex of the current cell; determine the smaller of the first spacing and the second spacing as the reference spacing; calculate the sum of the first spacing, the second spacing, and the reference spacing as the reference distance between the text block and the current cell.Optionally, the matching unit 704 may also: if there is a minimum value in the reference distance between the text block and each of the multiple cells, determine the cell corresponding to the minimum value as the cell corresponding to the text block; if there are at least two minimum values in the reference distance between the text block and each of the multiple cells, determine the intersection and union ratio of the text block and at least two cells corresponding to the at least two minimum values, and determine the cell corresponding to the text block according to the intersection and union ratio of the text block and the at least two cells. The generating unit 705 may generate the target table data corresponding to the target table image based on the position information and row and column expansion information of the multiple cells and the text information of the text block corresponding to each cell. Optionally, the generating unit 705 may also: determine the reading order and line break information of the multiple cells according to the position information of the multiple cells, wherein the reading order is the order obtained by sorting the cells in the target table image row by row and column by column, and the line break information is information indicating whether the corresponding cell is a cell in the first column but not in the first row; according to the reading order and line break information of the multiple cells, generate the row and column expansion information of each cell and the text information of the corresponding at least one text block one by one in the form of table data, and obtain the target table data corresponding to the target table image. Optionally, the generating unit 705 may also: determine the first reading order of the plurality of cells according to the positional order from top to bottom and from left to right based on the positional information of the plurality of cells; in response to the reading order correction instruction, input the cell sequence composed of the plurality of cells into the feature extraction network of the cell reading order extraction model for encoding to obtain an implicit cell reading feature sequence; based on the feature adjustment network of the cell reading order extraction model, adjust the implicit cell reading feature sequence in parallel using the time step sequence to obtain an estimated cell reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; determine an estimated cell reading sequence based on the estimated cell reading feature sequence, wherein the estimated cell reading sequence is used to represent the second reading order of the plurality of cells; and determine the second reading order as the reading order of the plurality of cells. Optionally, the reading order correction instruction is an instruction input by a user; and / or the reading order correction instruction is an instruction generated when a preset verification condition is not satisfied, and the preset verification condition is a condition indicating that the first reading order can satisfy the table reading requirement. Optionally, the table restoration device 700 further includes a splicing unit (not shown in the figure), which may splice text information of at least two text blocks for each cell according to a reference order of the at least two text blocks if the cell corresponds to at least two text blocks.Wherein, the reference order is the position order from top to bottom and from left to right; or the reference order is obtained by the following steps: inputting a text block sequence consisting of at least two text blocks into a feature extraction network of a text block reading order extraction model for encoding to obtain an implicit text block reading feature sequence; based on the feature adjustment network of the text block reading order extraction model, using a time step sequence to parallelly adjust the implicit text block reading feature sequence to obtain an estimated text block reading feature sequence, wherein the time step sequence includes a plurality of reading time steps arranged in sequence; according to the estimated text block reading feature sequence, determining an estimated text block reading sequence, wherein the estimated text block reading sequence is used to represent the reference order. The table restoration method and apparatus according to the exemplary embodiment of the present disclosure have been described above with reference. Each unit in the table restoration apparatus shown can be configured as software, hardware, firmware or any combination of the above items to perform a specific function. For example, each unit can correspond to a dedicated integrated circuit, can also correspond to a pure software code, and can also correspond to a module combining software and hardware. In addition, one or more functions implemented by each unit can also be uniformly executed by components in a physical entity device (e.g., a processor, a client or a server, etc.). In addition, the table restoration method described with reference to the description can be implemented by a program (or instruction) recorded on a computer-readable storage medium. For example, according to an exemplary embodiment of the present disclosure, a computer-readable storage medium storing instructions can be provided, wherein, when the instructions are executed by at least one computing device, the at least one computing device is prompted to execute the table restoration method according to the present disclosure. The computer program in the above-mentioned computer-readable storage medium can be run in an environment deployed in a computer device such as a client, a host, an agent device, a server, etc. It should be noted that the computer program can also be used to perform additional steps in addition to the above steps or perform more specific processing when executing the above steps. The content of these additional steps and further processing has been mentioned in the description process of the relevant method, so it will not be repeated here to avoid repetition. It should be noted that the various units in the table restoration device according to the exemplary embodiment of the present disclosure can completely rely on the operation of the computer program to realize the corresponding function, that is, the various units correspond to the various steps in the functional architecture of the computer program, so that the entire system is called through a special software package (for example, lib library) to realize the corresponding function. On the other hand, the various units shown can also be implemented by hardware, software, firmware, middleware, microcode or any combination thereof. When implemented in software, firmware, middleware, or microcode, the program code or code segments for performing the corresponding operations may be stored in a computer-readable medium such as a storage medium, so that the processor may perform the corresponding operations by reading and running the corresponding program code or code segments.For example, the exemplary embodiments of the present disclosure may also be implemented as a computing device, which includes a storage component and a processor, wherein a computer executable instruction set is stored in the storage component, and when the computer executable instruction set is executed by the processor, the table restoration method according to the exemplary embodiments of the present disclosure is executed. Specifically, the computing device may be deployed in a server or a client, or may be deployed on a node device in a distributed network environment. In addition, the computing device may be a PC computer, a tablet device, a personal digital assistant, a smart phone, a web application, or other device capable of executing the above instruction set. Here, the computing device is not necessarily a single computing device, but may also be any device or circuit capable of executing the above instructions (or instruction sets) individually or jointly. The computing device may also be part of an integrated control system or a system manager, or may be configured as a portable electronic device interconnected with a local or remote (e.g., via wireless transmission) interface. In the computing device, the processor may include a central processing unit (CPU), a graphics processing unit (GPU), a programmable logic device, a dedicated processor system, a microcontroller, or a microprocessor. As an example and not limitation, the processor may also include an analog processor, a digital processor, a microprocessor, a multi-core processor, a processor array, a network processor, etc. According to the table restoration method of the exemplary embodiment of the present disclosure, some operations described in the method can be implemented by software, some operations can be implemented by hardware, and in addition, these operations can be implemented by a combination of software and hardware. The processor can run instructions or codes stored in one of the storage components, wherein the storage component can also store data. Instructions and data can also be sent and received through the network via a network interface device, wherein the network interface device can use any known transmission protocol. The storage component can be integrated with the processor, for example, RAM or flash memory is arranged in an integrated circuit microprocessor, etc. In addition, the storage component may include an independent device, such as an external disk drive, a storage array, or any other storage device that can be used by a database system. The storage component and the processor can be coupled in operation, or can communicate with each other, such as through an I / O port, a network connection, etc., so that the processor can read the file stored in the storage component. In addition, the computing device may also include a video display (such as a liquid crystal display) and a user interaction interface (such as a keyboard, a mouse, a touch input device, etc.). All components of the computing device can be connected to each other via a bus and / or a network. According to the table restoration method of the exemplary embodiment of the present disclosure, it can be described as various interconnected or coupled functional blocks or functional diagrams. However, these functional blocks or functional diagrams may be equally integrated into a single logical device or operate according to inexact boundaries. Therefore, the table reduction method described with reference to the above may be implemented by a system including at least one computing device and at least one storage device storing instructions.According to an exemplary embodiment of the present disclosure, at least one computing device is a computing device for executing a table restoration method according to an exemplary embodiment of the present disclosure, and a computer executable instruction set is stored in a storage device. When the computer executable instruction set is executed by at least one computing device, the table restoration method described with reference to the description is executed. The above describes the various exemplary embodiments of the present disclosure. It should be understood that the above description is only exemplary and not exhaustive, and the present disclosure is not limited to the disclosed exemplary embodiments. Without departing from the scope and spirit of the present disclosure, many modifications and changes are obvious to those of ordinary skill in the art. Therefore, the scope of protection of the present disclosure should be based on the scope of the claims.
Claims
1. A table restoration method, characterized in that: The table restoration method comprises: Get the target table image; Detect cells in the target table image using a cell detection model to obtain position information and row and column expansion information of multiple cells; Using a text recognition model to recognize text blocks in the target table image, and obtaining position information and text information of multiple text blocks; Matching the position information of the plurality of cells with the position information of the plurality of text blocks to determine at least one text block corresponding to each of the plurality of cells; Based on the position information and row and column expansion information of the multiple cells, and the text information of the text block corresponding to each cell, the target table data corresponding to the target table image is generated.
2. The table restoration method according to claim 1, characterized in that: The method of using the cell detection model to detect cells in the target table image and obtain position information and row and column expansion information of multiple cells includes: Inputting the target table image into the cell detection model to predict the cell position, obtaining the position information of multiple cells and predicted row and column extension information, wherein the predicted row and column extension information includes the number of rows and columns spanned by the cell; For cells whose number of rows and columns spanned are both less than or equal to a preset value, the predicted row and column extension information is used as the row and column extension information of the corresponding cell; Cells whose number of rows and columns spanned by at least one cell is greater than the preset value are recorded as merged cells. For each merged cell, the predicted row and column extension information of the merged cell is corrected according to the row and column extension information of other cells adjacent to the merged cell to obtain the row and column extension information of the merged cell.
3. The table restoration method according to claim 1, characterized in that: The method of using the cell detection model to detect cells in the target table image and obtain position information and row and column expansion information of multiple cells includes: The cell detection model is used to detect blank areas in the target table image. If the spacing between the blank areas and adjacent cells meets a preset spacing, the blank areas are determined as cells; wherein the blank areas are areas in the target table image that are not determined as cells by the cell detection model.
4. The table restoration method according to claim 1, characterized in that: The cell detection model is trained by the following steps: Acquire a sample table image and reference position information and reference row and column extension information of each cell in the sample table image; The sample table image is used as a training sample, and the reference position information and reference row and column expansion information of each cell in the sample table image are used as training targets, and the cell detection model is obtained through training.
5. The table restoration method according to claim 1, characterized in that: The cell detection model is at least one of the following: a real-time target detection model, a faster regional convolutional neural network model, and a detection transformer model.
6. The table restoration method according to claim 1, characterized in that: The cell position information and the text block position information both include the coordinates of the upper left corner vertex and the coordinates of the lower right corner vertex; The matching the position information of the plurality of cells with the position information of the plurality of text blocks to determine at least one text block corresponding to each of the plurality of cells includes: For each text block, traverse the multiple cells, and determine a reference distance between the text block and the current cell according to a first distance between an upper left corner vertex of the text block and an upper left corner vertex of a current cell and a second distance between a lower right corner vertex of the text block and a lower right corner vertex of the current cell; The cell corresponding to the text block is determined according to the reference distance between the text block and each of the multiple cells, and at least one text block corresponding to each of the multiple cells is obtained by reverse aggregation.
7. The table restoration method according to claim 6, characterized in that: The determining a reference distance between the text block and the current cell according to a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell comprises: Calculate a first distance between the upper left corner vertex of the text block and the upper left corner vertex of the current cell and a second distance between the lower right corner vertex of the text block and the lower right corner vertex of the current cell; determining a smaller one of the first spacing and the second spacing as a reference spacing; The sum of the first spacing, the second spacing, and the reference spacing is calculated as a reference distance between the text block and the current cell.
8. A table restoration device, characterized in that: The table restoration device comprises: an acquisition unit configured to acquire a target table image; A detection unit is configured to detect cells in the target table image using a cell detection model to obtain position information and row and column expansion information of multiple cells; A recognition unit configured to recognize text blocks in the target table image using a text recognition model to obtain position information and text information of multiple text blocks; a matching unit configured to match the position information of the plurality of cells with the position information of the plurality of text blocks, and determine at least one text block corresponding to each of the plurality of cells; The generating unit is configured to generate target table data corresponding to the target table image based on the position information and row and column expansion information of the plurality of cells and the text information of the text block corresponding to each cell.
9. A computer-readable storage medium storing instructions, characterized in that: When the instructions are executed by at least one computing device, the at least one computing device is prompted to perform the table restoration method according to any one of claims 1 to 7.
10. A system comprising at least one computing device and at least one storage device storing instructions, characterized in that: When the instructions are executed by the at least one computing device, the at least one computing device is prompted to perform the table restoration method according to any one of claims 1 to 7.
Citation Information
Patent Citations
A method and apparatus for detecting a table
CN109948507A
Table identification method and system, intelligent terminal and computer readable storage medium
CN114782974A
Table recognition method and device, electronic equipment and storage medium
CN114973282A
Table image recognition method and device, electronic equipment and storage medium
CN115240213A
Cited By
Table restoration method and device, electronic equipment and computer program product
CN119919951A
Table restoration method and device
CN121236784A
