Table structure recognition method, system and device based on cell detection
Through improved cell detection and adjacency matching algorithms, it solves the problem of cross-row and cross-column cell identification in table structure identification in natural scenes, achieves accurate recovery and identification of complex table structures, and expands application scenarios.
Patent Information
- Application Number
- CN202111540686.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-16
- Publication Date
- 2024-09-17
- Estimated Expiration
- 2041-12-16
AI Technical Summary
It is difficult for the existing technology to effectively identify the structure of photographed tables in natural scenes, especially complex cross-row and cross-column cell structures, resulting in insufficient universality of table structure recognition.
Using a method based on cell detection, through the improved SBD algorithm and cell adjacency matching algorithm, the cells in the table area are detected and the table structure is restored, which is suitable for skewed and distorted table images in natural scenes.
It achieves accurate recognition of large tables and complex table structures, solves the problem of restoring cross-row and cross-column cell structures, expands the application scenarios of table structure recognition, and has stronger universality.
Smart Images

Figure CN114359939B
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image recognition, and in particular to a table structure recognition method, system and device based on cell detection. Background Art
[0002] Tables are an important way to record and transmit information in our lives. Compared with natural language, tables provide a more compact and structured data format that can summarize a large amount of data. At the same time, tables also provide a form that is easy to find and compare information, making it easier for readers to quickly obtain effective information. Therefore, tables are widely used in various fields. With the rapid development of layout analysis and document understanding, tables, as an important part of documents, have great research value. In order to quickly obtain table information, researchers have proposed a table recognition task.
[0003] The table recognition task can be decomposed into three parts: table detection, table structure recognition and table text recognition. With the help of today's mature target detection technology and OCR technology, table detection and table text recognition tasks can be easily solved. Table structure recognition is a special part of the table recognition task and also the most important part. It is different from tasks in other fields and requires targeted design solutions.
[0004] The table recognition task has been proposed for more than 20 years. Initially, it was mostly used to process some PDF format documents and scanned image data. However, with the development of technology and the widespread popularity of smart devices such as mobile phones, it will be more convenient for people to use mobile phones to obtain table information. However, the algorithms proposed so far are relatively few for photographed tables in natural scenes. Therefore, in order to promote the development of table recognition technology, it is necessary to design a system suitable for table structure recognition of photographed tables in natural scenes.
[0005] In a table, various combinations of cells across rows and columns can form various complex table structures. How to identify the structure of cells across rows and columns has always been a difficult point in the table structure recognition task, and it is also a difficult problem that must be overcome in the table structure recognition task. Summary of the invention
[0006] In order to solve the technical problems existing in the prior art, the present invention provides a table structure recognition method, system and device based on cell detection. The present invention has a relatively simple step flow, can solve the structure recognition problems of large tables with a large number of cells and complex tables with various cell structure changes, and can solve the structure recovery problem of cells across rows and columns. Compared with the existing methods, it has stronger universality.
[0007] The first object of the present invention is to provide a table structure recognition method based on cell detection.
[0008] The second object of the present invention is to provide a table structure recognition system based on cell detection.
[0009] A third object of the present invention is to provide a computer device.
[0010] The first object of the present invention can be achieved by adopting the following technical solutions:
[0011] The table structure recognition method based on cell detection includes the following steps:
[0012] S1, table area acquisition, locate the table area from the table image through the table area detection model, and generate a new table image;
[0013] S2. Cell detection: By improving the general SBD algorithm, a cell detection model based on the improved SBD algorithm is constructed. The cell detection model detects all cells in the table area and obtains the coordinates of the four vertices of the smallest quadrilateral that wraps the cell.
[0014] S3, table structure prediction, by designing a cell adjacency matching algorithm, find the cells in the same row or column according to the coordinates of the detected cells, and predict the HTML structure corresponding to the table through the table row and column clustering results;
[0015] S4. Visual recovery of table structure: Based on the predicted table HTML structure, an editable table with the same structure as that in the table image is restored.
[0016] Furthermore, step S1 specifically includes:
[0017] S11. Train a table area detection model based on the Cascade RCNN algorithm, use the trained table area detection model to detect the table image, and obtain the detection box coordinates of the table area;
[0018] S12, expanding the detection frame of the table area to obtain larger detection frame coordinates;
[0019] S13, cutting out the table from the input table image according to the larger detection frame coordinates to generate a new table image.
[0020] Furthermore, step S2 specifically includes:
[0021] S21. Modify the general SBD model, set preset boxes of more sizes, and combine the detection box regression branch of SBD and the SBD decomposition branch at the output of the SBD model to obtain the cell detection result;
[0022] S22. Train a cell detection model based on the improved SBD algorithm to obtain the four vertex coordinates of the minimum circumscribed quadrilateral that can completely enclose each independent cell area.
[0023] Specifically, step S3 includes:
[0024] S31. Design a cell adjacency matching algorithm to find the corresponding row and column for each cell in a clustering manner, that is, to aggregate cells in the same row or column together;
[0025] S32, when clustering rows, starting from a cell, find the adjacent cells on the left and the adjacent cells on the right through neighbor matching, and add the newly matched cells to the list of the same row, and further find the adjacent cells on the left and right of the newly added cells, and repeat this cycle until there are no newly added cells;
[0026] S33, when clustering a column, starting from a cell, find the adjacent cells above and below it through neighbor matching, and add the newly matched cells to the list of the same column, and further find the upper and lower adjacent cells of the newly added cells, and repeat this cycle until there are no new cells added;
[0027] S34. Predict the HTML structure corresponding to the table through the table row and column clustering results.
[0028] The second object of the present invention can be achieved by adopting the following technical solutions:
[0029] A table area acquisition module is used to locate the table area from the table image through the table area detection model and generate a new table image;
[0030] The cell detection module is used to build a cell detection model based on the improved SBD algorithm by improving the general order-independent box decomposition network (SBD) algorithm. The cell detection model detects all cells in the table area and obtains the coordinates of the four vertices of the minimum quadrilateral that wraps the cell.
[0031] The table structure prediction module is used to design a cell adjacency matching algorithm to find cells in the same row or column according to the coordinates of the detected cells, and predict the HTML structure corresponding to the table through the table row and column clustering results;
[0032] The table structure visualization recovery module is used to recover and generate an editable table with the same structure as the table in the table image based on the predicted table HTML structure.
[0033] The third object of the present invention can be achieved by adopting the following technical solutions:
[0034] A computer device comprises a processor and a memory for storing a program executable by the processor. When the processor executes the program stored in the memory, the above table structure recognition method is implemented.
[0035] Compared with the prior art, the present invention has the following advantages and beneficial effects:
[0036] 1. The present invention obtains the detection frames of all cells through cell detection, and restores the structure of the table through an adjacency matching algorithm based on the detection frames of the cells. Compared with the existing methods related to transformers and graph convolutions, the present invention has a relatively simple step flow and can solve the structural recognition problems of large tables with a large number of cells and complex tables with various cell structure changes.
[0037] 2. The present invention designs an adjacency matching algorithm to directly restore the structure of the table through the detection results of the cells. The cells adjacent to each cell can be quickly found through adjacency matching, and the cells in the same row or column are further clustered into a set to obtain the row and column information of the cells. This can solve the problem of structural recovery of cells across rows and columns, and is therefore more universal than existing methods.
[0038] 3. The present invention is applicable to table structure recognition of skewed and distorted table images obtained in natural scenes, while existing methods are almost all based on document tables in PDF format or scanned regular table images. The present invention expands the application scenarios of table structure recognition. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the structures shown in these drawings without paying creative work.
[0040] Figure 1 is a flow chart of the method in implementation 1 of the present invention;
[0041] Figure 2 This is a schematic diagram of left-right adjacency matching of cells that do not span rows in Embodiment 1 of the present invention;
[0042] Figure 3 This is a schematic diagram of left-right adjacency matching of cells spanning rows in Embodiment 1 of the present invention;
[0043] Figure 4 This is a schematic diagram of upper and lower adjacency matching of cells that do not span columns in Example 1 of the present invention;
[0044] Figure 5 This is a schematic diagram of upper and lower adjacency matching of cells spanning columns in Example 1 of the present invention;
[0045] Figure 6 It is a schematic diagram of the visualization effect of the table structure in Example 1 of the present invention. DETAILED DESCRIPTION
[0046] The technical solution of the present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is obvious that the described embodiments are part of the embodiments of the present invention, not all of the embodiments, and the implementation of the present invention is not limited to this. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0047] Embodiment 1:
[0048] like Figure 1 As shown, this embodiment discloses a table structure recognition method based on cell detection, comprising the following steps:
[0049] S1. Acquire the table area. Use the table area detection model to locate the table area from the table image and generate a new table image.
[0050] The input image of this embodiment is a photographic image of a table in a natural scene. The image has diverse forms, with complex lighting changes, background changes, and table morphology changes. That is, the table in the image may have a variety of skew angles or distorted postures. The present invention expands the application scenarios of table structure recognition in natural scenes.
[0051] Preferably, the table area detection model in this example is a table area detection model based on a cascade recurrent convolutional neural network algorithm (Cascade RCNN).
[0052] Specifically, step S1 includes the following steps:
[0053] S11. Train a table area detection model based on the Cascade RCNN algorithm, use the trained table area detection model to detect the table image, and obtain the detection box coordinates of the table area.
[0054] Specifically, the detection box of the table area is the minimum enclosing rectangle that can completely wrap the table area. Assuming that the width of the input image is w and the height is h, the detection box coordinates of the table area are obtained [Xmin, Ymin, Xmax, Ymax], where [Xmin, Ymin, Xmax, Ymax] represent the horizontal and vertical coordinates of the upper left point and the lower right point of the minimum enclosing rectangle obtained by the target table detection.
[0055] S12. Enlarging the detection frame of the table area to obtain larger detection frame coordinates, thereby reducing errors that may be caused by the table detection model.
[0056] Preferably, the coordinates of the new larger detection frame are: Xmin'=max(0,Xmin-20), Ymin'=max(0,Ymin-20), Xmax'=min(w,Xmax+20), Ymax'=min(h,Ymax+20), where the max() function is used to obtain the larger of the two numbers, and the min() function is used to obtain the smaller of the two numbers.
[0057] S13, cutting out the table from the input table image according to the larger detection frame coordinates to generate a new table image.
[0058] S2. Cell detection. By improving the general order-independent box decomposition network (SBD) algorithm, a cell detection model based on the improved SBD algorithm is constructed. The cell detection model detects all cells in the table area and obtains the four vertex coordinates of the minimum quadrilateral that wraps the cell.
[0059] S21. Modify the general SBD model, set preset boxes of more sizes, and combine the SBD detection box regression branch and the SBD decomposition branch at the output of the SBD model to obtain the cell detection results.
[0060] In the process of combining the detection box regression branch of SBD and the decomposition branch of SBD, the detection result of the SBD decomposition branch is mainly used, and the detection result of the detection box regression branch of SBD is auxiliary. Combining the outputs of multiple branches of the SBD model, a more complete cell detection result can be obtained, which can solve the problem of missed detection of cells in tables with few lines.
[0061] S22. Train a cell detection model based on the improved SBD algorithm to obtain the four vertex coordinates of the minimum circumscribed quadrilateral that can completely enclose each independent cell area.
[0062] The new table image obtained in S1 is resized. During training, the minimum side of the input image is set to 400, 600, and 800 respectively, and the longest side is set not to exceed 1000. The short side of the input image is adjusted to the closest length among 400, 600, and 800, and the long side is changed in proportion to the change of the short side, but the length of the long side does not exceed 1000, that is, when the adjusted length of the long side exceeds 1000, it is directly taken as 1000. During testing, the test image size is directly changed to 800×1000 and sent to the order-independent box decomposition network model for cell detection.
[0063] S3. Table structure prediction: By designing a cell adjacency matching algorithm, cells in the same row or column are found according to the coordinates of the detected cells, and the HTML structure corresponding to the table is predicted through the table row and column clustering results.
[0064] S31. Design a cell adjacency matching algorithm to find the corresponding row and column for each cell in a clustering manner, that is, to aggregate cells in the same row or column together, so as to solve the row and column matching of cells across rows and columns.
[0065] S32. When clustering rows, start from a cell, find its adjacent cells on the left and right through proximity matching, add the newly matched cells to the list of the same row, and further find the adjacent cells on the left and right of the newly added cells, and repeat this cycle until there are no new cells added.
[0066] S321. Sort the coordinates of the circumscribed quadrilateral of each cell obtained by the SBD model to obtain the coordinates of the cell, and calculate the coordinates of the center point of the cell through the coordinates of the cell.
[0067] Specifically, the coordinates of the circumscribed quadrilateral of each cell obtained by the SBD model are sorted so that the coordinates of the four points are arranged clockwise according to the upper left vertex, the upper right vertex, the lower right vertex, and the lower left vertex. The coordinates of cell A and cell B are: [Xa1, Ya1, Xa2, Ya2, Xa3, Ya3, Xa4, Ya4] and [Xb1, Yb1, Xb2, Yb2, Xb3, Yb3, Xb4, Yb4]. The coordinates of the center points of cell A and cell B are calculated through the coordinates of cell A and cell B.
[0068] The formula for calculating the coordinates of the center point of cell A is:
[0069]
[0070]
[0071] Among them, Xa1, Ya1, Xa2, Ya2, Xa3, Ya3, Xa4, Ya4 are the coordinates of the four points of cell A.
[0072] The formula for calculating the coordinates of the center point of cell B is:
[0073]
[0074] Among them, Xb1, Yb1, Xb2, Yb2, Xb3, Yb3, Xb4, Yb4 are the coordinates of the four points of cell B.
[0075] S322. Select a cell as the initial cell, perform horizontal left matching and horizontal right matching, and find the adjacent cells of the initial cell.
[0076] In this embodiment, horizontal left matching and horizontal right matching are collectively referred to as row matching. Horizontal left matching: select cell A as the initial cell. After cell A matches to the left with a new cell B, the new cell B continues to match to the left without performing a matching operation to the right. Horizontal right matching: after cell A matches to the right with a new cell B, the new cell B continues to match to the right without performing a matching operation to the left. The purpose of one-way matching is to reduce the amount of calculation, speed up the matching speed, and quickly find all cells in the same row as the target cell.
[0077] S323. Determine whether the adjacent cell is a cross-row cell relative to the initial cell according to the length of the adjacent sides of the initial cell and the adjacent cell; when the adjacent cell is a non-cross-row cell relative to the initial cell, directly perform a new round of horizontal adjacency matching through the adjacent cell; when the adjacent cell is a cross-row cell relative to the initial cell, the coordinates of the adjacent cell are temporarily changed relative to the coordinates of the initial cell, so that when the adjacent cell is matched to the left, a cell in the same row as the initial cell and the adjacent cell can be found, and the adjacent cell with the modified coordinates continues to match cells horizontally, and after this round of matching process is completed, the original coordinates are restored.
[0078] When cell A is matched horizontally to the left, for any detected cell B, the first step is to determine whether the center point of cell B is on the left side of cell A. The second step is to determine whether the left midpoint of cell A is between the upper right vertex and the lower right vertex of cell B. All cells that meet the conditions are obtained. When the number of cells that meet the conditions is greater than 1, the cells that meet the conditions need to be sorted according to the center point coordinates. Finally, the cell with the largest center point horizontal coordinate is selected as the left adjacent cell when cell A is matched to the left.
[0079] After finding the left neighboring cell B of cell A, determine whether cell B is a cross-row cell relative to cell A according to the length of the adjacent sides of cells A and B. When cell B is a non-cross-row cell relative to cell A, a new round of left adjacent matching is performed directly through cell B; when cell B is a cross-row cell relative to cell A, the coordinates of cell B are temporarily changed according to the coordinates of cell A, so that when cell B matches to the left, it can find a cell in the same row as cell A and cell B. After the coordinates are modified, cell B continues to match cells to the left, and after this round of matching process is completed, the original coordinates are restored.
[0080] When cell A is matched horizontally to the right, for any detected cell B, it is necessary to first determine whether the center point of cell B is on the right side of cell A, and then determine whether the right midpoint of cell A is between the upper left vertex and the lower left vertex of cell B, and obtain all cells that meet the conditions. When the number of cells that meet the conditions is greater than 1, the cells that meet the conditions need to be sorted according to the center point coordinates, and the cell with the smallest center point horizontal coordinate is the neighboring cell when cell A is matched to the right.
[0081] After finding the right adjacent cell B of cell A, determine whether cell B is a cross-row cell relative to cell A according to the length of the adjacent sides of cells A and B. When cell B is a non-cross-row cell relative to cell A, a new round of rightward adjacent matching is performed directly through cell B; when cell B is a cross-row cell relative to cell A, the coordinates of cell B are temporarily changed according to the coordinates of cell A, so that when cell B matches to the right, it can find a cell in the same row as cell A and cell B. After the coordinates are modified, cell B continues to match cells to the right, and after this round of matching process is completed, the original coordinates are restored.
[0082] like Figure 2 As shown, horizontal cell matching is performed without cells spanning rows. The specific process is as follows:
[0083] Starting from the 'start' cell, the horizontal cell matching process is divided into two directions, left and right. The first step is to match to the left and match to the cell 'left 1'. The first step is to match to the right and match to the cell 'right 1'. The new round of cell matching starts with 'left 1' and 'right 1' respectively. The 'left 1' cell continues to match to the left and matches to the cell 'left 2'. The 'right 1' cell continues to match to the right and matches to the cell 'right 2'. Finally, a new matching process starts with the 'left 2' and 'right 2' cells. If neither cell matches the new cell, the row matching process starting with the 'start' cell ends, and the matching result is to aggregate the 'start', 'left 1', 'left 2', 'right 1', 'right 2' and other cells into a row.
[0084] like Figure 3 As shown, when there are cells across rows, cells are matched horizontally. The specific process is as follows:
[0085] Starting from the 'starting' cell, the horizontal cell matching process is divided into two directions: left and right. The 'starting' cell is matched to the left in the first step, and the cell 'Left 1' is matched. It is found that it is a cross-row cell relative to the 'starting' cell, so the coordinates of the 'Left 1' cell are changed according to the coordinates of the starting cell. The changed coordinates are as follows Figure 3As shown in the figure, the 'starting' cell is matched to the right in the first step and matches the cell 'right 1'. The 'right 1' cell is a non-cross-row cell relative to the starting cell, so there is no need to change the coordinates. The new round of cell matching starts with the 'left 1' cell with the changed coordinates and the 'right 1' cell with the original coordinates. The 'left 1' cell continues to match to the left and matches the cell 'left 2'. After matching the 'left 2' cell, the 'left 1' cell returns to its original initial coordinates, and the 'right 1' cell continues to match to the right. If no new cell is matched, the right matching process ends. The next round of row matching only needs to match to the left, starting with the 'left 2' cell and continuing to match to the left. If no new cell is matched, the left matching process ends. At this point, the row matching process starting with the 'starting' cell ends, and the matching result is to aggregate the 'starting', 'left 1', 'left 2', 'right 1' and other cells into a row.
[0086] S33. When clustering columns, start from a cell, find the adjacent cells above and below it through proximity matching, add the newly matched cells to the list of the same column, and further find the upper and lower adjacent cells of the newly added cells, and repeat this cycle until there are no new cells added.
[0087] S331. Sort the coordinates of the circumscribed quadrilateral of each cell obtained by the SBD model to obtain the coordinates of the cell, and obtain the coordinates of the center point of the cell through the coordinate calculation of the cell.
[0088] Specifically, the coordinates of the four points of the circumscribed quadrilateral of each cell are arranged clockwise according to the upper left vertex, the upper right vertex, the lower right vertex, and the lower left vertex, and the coordinates of cell A and cell B are obtained as follows:
[0089] [Xa1,Ya1,Xa2,Ya2,Xa3,Ya3,Xa4,Ya4] and [Xb1,Yb1,Xb2,Yb2,Xb3,Yb3,Xb4,Yb4].
[0090] The calculation formula for the center point coordinates of the cell A and the cell B is consistent with the calculation formula for the center point coordinates of the cell A and the cell B described in step S321.
[0091] S332. Select a cell as the initial cell, perform vertical upward matching and vertical downward matching, and find the adjacent cells of the initial cell.
[0092] Vertical upward matching and vertical downward matching are collectively referred to as column matching. After cell A matches a new cell B vertically upward, the new cell B continues to match upward without performing a downward matching operation; after cell A matches a new cell B vertically downward, the new cell B continues to match downward without performing an upward matching operation.
[0093] S333. According to the lengths of the adjacent sides of the initial cell and the adjacent cells, determine whether the adjacent cell is a cross-column cell relative to the initial cell; when the adjacent cell is a non-cross-column cell relative to the initial cell, directly perform a new round of vertical adjacency matching through the adjacent cells; when the adjacent cell is a cross-column cell relative to the initial cell, the coordinates of the adjacent cell are temporarily changed relative to the coordinates of the initial cell, and the adjacent cell with the modified coordinates continues to match the cell vertically, and after this round of matching process is completed, the coordinates are restored to the original ones.
[0094] When cell A is selected for vertical matching, for any detected cell B, the first step is to determine whether the center point of cell B is on the upper side of cell A. The second step is to determine whether the upper midpoint of cell A is between the lower left vertex and the lower right vertex of cell B. All cells that meet the conditions are obtained. When the number of cells that meet the conditions is greater than 1, the cells that meet the conditions need to be sorted according to the center point coordinates. The cell with the largest center point vertical coordinate is the adjacent cell when cell A is matched upward.
[0095] After finding the upper adjacent cell B of cell A, determine whether cell B is a cross-column cell relative to cell A according to the length of the adjacent sides of cell A and cell B. When cell B is a non-cross-column cell relative to cell A, directly perform a new round of upward adjacent matching through cell B. When cell B is a cross-column cell relative to cell A, the coordinates of cell B are temporarily changed according to the coordinates of cell A, so that cell B can find a cell in the same column as cell A and cell B when matching upward. Cell B with modified coordinates continues to match cells upward, and after this round of matching process is completed, the original coordinates are restored.
[0096] When cell A is selected for vertical downward matching, for any detected cell B, the first step is to determine whether the center point of cell B is on the lower side of cell A. The second step is to determine whether the lower midpoint of cell A is between the upper left vertex and the upper corner vertex of cell B. All cells that meet the conditions are obtained. When the number of cells that meet the conditions is greater than 1, the cells that meet the conditions need to be sorted according to the center point coordinates. The cell with the smallest center point vertical coordinate is the adjacent cell when cell A is matched downward.
[0097] After finding the lower adjacent cell B of cell A, determine whether cell B is a cross-column cell relative to cell A according to the length of the adjacent sides of cell A and cell B. When cell B is a non-cross-column cell relative to cell A, a new round of downward adjacent matching is performed directly through cell B. When cell B is a cross-column cell relative to cell A, the coordinates of cell B are temporarily changed according to the coordinates of cell A, so that cell B can find a cell in the same column as cell A and cell B when matching downward. After the coordinates are modified, cell B continues to match cells downward, and after this round of matching process is completed, the original coordinates are restored.
[0098] like Figure 4 As shown, it means that the cells are matched vertically without cells spanning columns. The specific process is as follows:
[0099] Starting from the 'start' cell, the vertical cell matching process is divided into two directions, upward and downward. The first step is upward matching, matching to the cell 'up 1', and the first step is downward matching, matching to the cell 'down 1'. The new round of cell matching starts with 'up 1' and 'down 1' respectively. The 'up 1' cell continues to match upward. If no new cell is matched, the upward matching process ends. The 'down 1' cell continues to match downward and matches to the cell 'down 2'. The next round of column matching only needs to match downward, starting with the 'down 2' cell. If no new cell is matched, the downward matching process ends. At this point, the column matching process starting with the start cell ends, and the matching result is to aggregate the cells 'start', 'up 1', 'down 1', 'down 2', etc. into one column.
[0100] like Figure 5 As shown, it means that vertical cell matching is performed when there are cells across columns. The specific process is as follows:
[0101] Starting from the starting cell, the vertical cell matching process is divided into two directions, upward and downward. The first step of the starting cell is to match upward to the cell 'up 1', and it is found that it is a cross-column cell relative to the starting cell. Therefore, the coordinates of the 'up 1' cell are changed according to the coordinates of the 'starting' cell. The changed coordinates are as follows Figure 5As shown in the figure, the four black dots on the 'Upper 1' cell in the figure, the starting cell matches downward in the first step to the cell 'Lower 1', and the 'Lower 1' cell is a non-cross-column cell relative to the 'Starting' cell, so there is no need to change the coordinates. The new round of cell matching starts with the 'Upper 1' cell with the changed coordinates and the 'Lower 1' cell with the original coordinates. The 'Upper 1' cell continues to match upward to the cell 'Upper 2'. After matching the 'Upper 2' cell, the 'Upper 1' cell returns to its original initial coordinates. The 'Lower 1' cell continues to match downward to the new cell 'Lower 2'. Finally, a new column matching process starts with the 'Upper 2' and 'Lower 2' cells. If neither cell matches the new cell, the column matching process starting with the 'Starting' cell ends, and the matching result is to aggregate the 'Starting', 'Upper 1', 'Upper 2', 'Lower 1', 'Lower 2' and other cells into one column.
[0102] S34. Predict the HTML structure corresponding to the table through the table row and column clustering results.
[0103] S341. Sort the cells clustered into rows and columns by a coordinate sorting method, so as to obtain the coordinates of the rows and columns corresponding to the cells.
[0104] After row clustering, all cells are clustered into several sets. The cells in each set are in the same row. The coordinates of the center points of all cells in each set are calculated, and the average value is obtained to obtain (Xz, Yz). The average value of a center point is obtained for each set. These row sets are sorted according to the vertical coordinate of the average value of the center point. The sorted sets can obtain the corresponding row number. The set in the first position is represented as the cell set of the first row, and all the cells it contains are cells in the first row.
[0105] After column clustering, all cells are aggregated into several sets. The cells in each set are in the same column. The coordinates of the center points of all cells in each set are calculated, and the average value is obtained to obtain (Xz, Yz). The average value of a center point is obtained for each set. These row sets are sorted according to the horizontal coordinate of the average value of the center point. The sorted sets can obtain the corresponding column number. The set in the first position is represented as the cell set of the first column, and all the cells it contains are cells in the first column.
[0106] S342. Cells that span rows and columns will appear in a set of multiple cell rows and columns. The number of cells that span rows and columns is obtained by counting the number of times the cells appear in the set.
[0107] S343. Predict the HTML structure code corresponding to the table based on the row and column coordinates corresponding to the cell and the number of rows and columns spanned.
[0108] The table HTML structure code consists of [,,,,,<tdcolspan=”n”> ] and other symbols, where n is a positive integer greater than 1.
[0109] S4. Visual recovery of table structure: Based on the predicted table HTML structure, an editable table with the same structure as that in the table image is restored.
[0110] S41, inputting the obtained HTML structure sequence into the structure visualization module, the structure visualization module generates a structure image of the table according to the sequence composition, so as to facilitate intuitive analysis of the table structure recognition result and realize the structure visualization of the table.
[0111] S42, inserting text into the generated table structure image. There are two ways to insert text, the first is to add the inserted text into the structure sequence and directly display it during visualization, and the second is to click on a cell in the table structure image to manually input the added text.
[0112] like Figure 6 As shown, the structure visualization module visualizes the structure of the table through the table HTML structure prediction results. An editable spreadsheet is constructed through the structure visualization module to facilitate intuitive analysis of the table structure recognition results and to facilitate the insertion and filling of content in the recognized table results.
[0113] Embodiment 2:
[0114] This embodiment provides a table structure recognition system based on cell detection, which includes a table area acquisition module, a cell detection module, a table structure prediction module, and a table structure visualization recovery module. The specific functions of each module are as follows:
[0115] A table area acquisition module is used to locate the table area from the table image through the table area detection model and generate a new table image;
[0116] The cell detection module is used to build a cell detection model based on the improved SBD algorithm by improving the general order-independent box decomposition network (SBD) algorithm. The cell detection model detects all cells in the table area and obtains the coordinates of the four vertices of the minimum quadrilateral that wraps the cell.
[0117] The table structure prediction module is used to design a cell adjacency matching algorithm to find cells in the same row or column according to the coordinates of the detected cells, and predict the HTML structure corresponding to the table through the table row and column clustering results;
[0118] The table structure visualization recovery module is used to restore and generate an editable table with the same structure as the table in the image based on the predicted table HTML structure.
[0119] Embodiment 3:
[0120] This embodiment provides a computer device, which may be a server, a computer, etc., and includes a processor, a memory, an input device, a display, and a network interface connected through a system bus. The processor is used to provide computing and control capabilities. The memory includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program, and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. When the processor executes the computer program stored in the memory, a method for identifying a table structure in the above embodiment 1 is implemented as follows:
[0121] Table area acquisition: Use the table area detection model to locate the table area from the table image and generate a new table image;
[0122] Cell detection, by improving the general SBD algorithm, a cell detection model based on the improved SBD algorithm is constructed. The cell detection model detects all cells in the table area and obtains the coordinates of the four vertices of the smallest quadrilateral that wraps the cell;
[0123] Table structure prediction: By designing a cell adjacency matching algorithm, cells in the same row or column are found according to the coordinates of the detected cells, and the HTML structure corresponding to the table is predicted through the table row and column clustering results;
[0124] Table structure visualization recovery: Based on the predicted table HTML structure, an editable table with the same structure as the table in the image is restored.
[0125] In summary, the present invention obtains the detection frames of all cells through the cell detection module, and restores the structure of the table through the adjacency matching algorithm based on the detection frames of the cells. Compared with the existing methods related to transformers and graph convolution, the present invention has a relatively simple step flow, which can solve the structural recognition problems of large tables with a large number of cells and complex tables with various cell structure changes. By designing an adjacency matching algorithm to directly restore the structure of the table through the detection results of the cells, the present invention can quickly find the cells adjacent to each cell through adjacency matching, further cluster the cells in the same row or column into a set, and obtain the row and column information of the cells, which can solve the problem of structural recovery of cells across rows and columns, and therefore has stronger universality than the existing methods.
[0126] The present invention is applicable to table structure recognition of skewed and distorted table images obtained in natural scenes, while existing methods are almost all based on document tables in PDF format or scanned regular table images. The present invention expands the application scenarios of table structure recognition.
[0127] The above embodiments are preferred implementation modes of the present invention, but the implementation modes of the present invention are not limited to the above embodiments. Any other changes, modifications, substitutions, combinations, and simplifications that do not deviate from the spirit and principles of the present invention should be equivalent replacement methods and are included in the protection scope of the present invention.
Claims
1. Table structure recognition method based on cell detection, Features: The following steps are involved: S1, table area acquisition, locate the table area from the table image through the table area detection model, and generate a new table image; S2. Cell detection: By improving the general SBD algorithm, a cell detection model based on the improved SBD algorithm is constructed. The cell detection model detects all cells in the table area and obtains the coordinates of the four vertices of the smallest quadrilateral that wraps the cell. Step S2 specifically includes: S21. Modify the general SBD model, set preset boxes of more sizes, and combine the detection box regression branch of SBD and the SBD decomposition branch at the output of the SBD model to obtain the cell detection result; S22. Train a cell detection model based on the improved SBD algorithm to obtain the coordinates of four vertices of the minimum circumscribed quadrilateral that can completely enclose each independent cell area; S3, table structure prediction, by designing a cell adjacency matching algorithm, finding cells in the same row or column according to the coordinates of the detected cells, and predicting the HTML structure corresponding to the table through the table row and column clustering results; step S3 specifically includes: S31. Design a cell adjacency matching algorithm to find the corresponding row and column for each cell in a clustering manner, that is, to aggregate cells in the same row or column together; S32, when clustering rows, starting from a cell, find the adjacent cells on the left and the adjacent cells on the right through neighbor matching, and add the newly matched cells to the list of the same row, and further find the adjacent cells on the left and right of the newly added cells, and repeat this cycle until there are no newly added cells; S33, when clustering a column, starting from a cell, find the adjacent cells above and below it through neighbor matching, and add the newly matched cells to the list of the same column, and further find the upper and lower adjacent cells of the newly added cells, and repeat this cycle until there are no new cells added; S34, predicting the HTML structure corresponding to the table through the table row and column clustering results; S4. Visual recovery of table structure: Based on the predicted table HTML structure, an editable table with the same structure as that in the table image is restored.
2. The table structure recognition method according to claim 1, Features: Step S1 specifically includes: S11. Train a table area detection model based on the Cascade RCNN algorithm, use the trained table area detection model to detect the table image, and obtain the detection box coordinates of the table area; S12, expanding the detection frame of the table area to obtain larger detection frame coordinates; S13, cutting out the table from the input table image according to the larger detection frame coordinates to generate a new table image.
3. The table structure recognition method according to claim 1, Features: Step S32 specifically includes: S321, sorting the coordinates of the circumscribed quadrilateral of each cell obtained by the SBD model to obtain the coordinates of the cell, and obtaining the coordinates of the center point of the cell through the coordinate calculation of the cell; S322, select a cell as the initial cell, perform horizontal left matching and horizontal right matching, and find the adjacent cells of the initial cell; S323. Determine whether the adjacent cell is a cross-row cell relative to the initial cell according to the length of the adjacent sides of the initial cell and the adjacent cell; when the adjacent cell is a non-cross-row cell relative to the initial cell, directly perform a new round of horizontal adjacency matching through the adjacent cell; when the adjacent cell is a cross-row cell relative to the initial cell, the coordinates of the adjacent cell are temporarily changed relative to the coordinates of the initial cell, and the adjacent cell with the modified coordinates continues to match the cell horizontally, and after this round of matching process is completed, the coordinates are restored to the original ones.
4. The table structure recognition method according to claim 3, Features: Step S322 performs horizontal left matching and horizontal right matching, specifically including: Horizontal left matching: select a cell as the initial cell. After the initial cell matches to the left of a new cell, the new cell continues to match to the left without matching to the right. Horizontally right matching: after the initial cell matches the new cell to the right, the new cell continues to match to the right without matching to the left.
5. The table structure recognition method according to claim 1, Features: Step S33 specifically includes: S331, sorting the coordinates of the circumscribed quadrilateral of each cell obtained by the SBD model to obtain the coordinates of the cell, and obtaining the coordinates of the center point of the cell through the coordinate calculation of the cell; S332, select a cell as the initial cell, perform vertical upward matching and vertical downward matching, and find the adjacent cells of the initial cell; S333. According to the lengths of the adjacent sides of the initial cell and the adjacent cells, determine whether the adjacent cell is a cross-column cell relative to the initial cell; when the adjacent cell is a non-cross-column cell relative to the initial cell, directly perform a new round of vertical adjacency matching through the adjacent cells; when the adjacent cell is a cross-column cell relative to the initial cell, the coordinates of the adjacent cell are temporarily changed relative to the coordinates of the initial cell, and the adjacent cell with the modified coordinates continues to match the cell vertically, and after this round of matching process is completed, the coordinates are restored to the original ones.
6. The table structure recognition method according to claim 1, Features: Step S4 specifically includes: S41, inputting the obtained HTML structure sequence into the structure visualization module, and the structure visualization module generates a structure image of the table according to the sequence composition; S42: insert text into the generated table structure image.
7. Table structure recognition system based on cell detection, It is characterized in that The system comprises: A table area acquisition module is used to locate the table area from the table image through the table area detection model and generate a new table image; The cell detection module is used to build a cell detection model based on the improved SBD algorithm by improving the general order-independent box decomposition network (SBD) algorithm. The cell detection model detects all cells in the table area and obtains the coordinates of the four vertices of the minimum quadrilateral that wraps the cell. The general SBD model is modified to set preset boxes of more sizes. The output of the SBD model is combined with the SBD detection box regression branch and the SBD decomposition branch to obtain the cell detection result. A cell detection model is trained based on the improved SBD algorithm to obtain the four vertex coordinates of the minimum circumscribed quadrilateral that can completely enclose each independent cell area; The table structure prediction module is used to design a cell adjacency matching algorithm to find cells in the same row or column according to the coordinates of the detected cells, and predict the HTML structure corresponding to the table through the table row and column clustering results; Design a cell adjacency matching algorithm to find the corresponding row and column for each cell in a clustering manner, that is, to aggregate cells in the same row or column together; When clustering rows, we start with a cell and find its adjacent cells on the left and right through neighbor matching. We then add the newly matched cells to the list of the same row and further find the adjacent cells on the left and right of the newly added cells. This cycle repeats until there are no new cells. When clustering columns, start with a cell, find the adjacent cells above and below it through neighbor matching, add the newly matched cells to the list of the same column, and further find the upper and lower adjacent cells of the newly added cells, and repeat this cycle until there are no new cells added; Predict the HTML structure corresponding to the table through the table row and column clustering results; The table structure visualization recovery module is used to recover and generate an editable table with the same structure as the table in the table image based on the predicted table HTML structure.
8. A computer device comprising a processor and a memory for storing a program executable by the processor, It is characterized in that When the processor executes the program stored in the memory, the table structure recognition method described in any one of claims 1 to 6 is implemented.
