A method, device and storage medium for table structure recognition of three-line tables

By recognizing three-line table structures through image preprocessing and morphological operations, the accuracy and efficiency problems of complex three-line table recognition in existing technologies are solved, and more efficient three-line table structure recognition is achieved.

CN115439866BActive Publication Date: 2025-12-12ZHEJIANG UNIV OF TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202210915421.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-31
Publication Date
2025-12-12
Estimated Expiration
2042-07-31

AI Technical Summary

Technical Problem

Existing technologies struggle to accurately identify complex three-line table structures, especially those with horizontal lines of varying lengths. Furthermore, deep learning-based methods suffer from high memory consumption and low efficiency.

Method used

A method combining image preprocessing, morphological processing, and logical operations is employed, including binarization, horizontal and vertical erosion and dilation operations, to identify the positions of the three-line table lines and cells. Cell information is obtained through traversal and segmentation to generate the table structure.

Benefits of technology

It improves the accuracy and versatility of three-line table structure recognition, reduces the problems of missed and over-detection of cells, reduces computational complexity, and does not require a large amount of training data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115439866B_ABST
    Figure CN115439866B_ABST
Patent Text Reader

Abstract

The application provides a method, device and storage medium for table structure recognition of three-line tables, and the method comprises the following steps: preprocessing a picture to obtain a binary image, performing horizontal erosion and horizontal expansion on the binary image after inversion to obtain a horizontal table line image; performing pixel logical OR on the binary image and the horizontal table line image to obtain a table line free image, performing horizontal erosion and vertical erosion on the table line free image respectively, and merging the results to obtain an initial cell mask; traversing the horizontal table line, re-segmenting the cell to obtain a final cell mask, calculating and obtaining information of all cells in the final cell mask, and obtaining a table structure representing the three-line table; the application improves the accuracy of three-line table structure recognition of various types, effectively reduces the problems of cell missed detection and multiple detection, the result contains complete and specific information, and is beneficial to subsequent table structure restoration and the like; a non-data driven method is adopted, a large amount of data is not required, and the calculation amount is small; the table structure of the three-line table can be more accurately and universally recognized.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of image processing, and in particular to a table structure recognition method for three-line tables, a device and a storage medium. BACKGROUND

[0002] The development of optical character recognition (OCR) technology has solved the task of converting text information in images into machine-readable characters, but a table is a special carrier of text information, and the information in a cell has relevance, so it cannot be simply read by an OCR technology. Therefore, extracting table structure is a necessary task for extracting table information.

[0003] Existing table structure recognition technologies based on traditional image processing are mostly for tables with fully closed cells, and are difficult to recognize three-line tables, especially complex three-line tables with different lengths of horizontal lines. For cell detection based on deep learning, there is often a phenomenon of missing cell detection due to interference such as blank cells. Moreover, the deep learning method has a strong dependence on data and requires a large amount of training data; the deep learning model often occupies a large amount of memory and the prediction speed is usually slow.

[0004] A Chinese patent with application number CN202010882990.1 discloses a paper table structure automatic recognition method and device. The method traverses the intersection points of the table, groups, filters, sorts, and processes the intersection points, generates a cell set, and thus obtains the table structure; but this method is for recognizing closed tables with solid lines, and is not suitable for recognizing open tables such as three-line tables, and has poor universality.

[0005] A Chinese patent with application number CN202010432633.5 discloses a table structure restoration method, device, equipment, system, and readable storage medium. The method uses a deep learning-based method to train two models to detect the rows and columns of the table, and combines the row and column information of the characters to restore the table structure. This method needs to use two models for prediction, uses a deep learning-based method, consumes a large amount of memory, and has low efficiency; although it does not require table lines, it is not suitable for complex tables. SUMMARY

[0006] To solve the above problems, the present application provides a table structure recognition method for three-line tables, a device and a storage medium, which solves the structure recognition of three-line tables and can also solve the structure recognition of complex three-line tables with different numbers of columns in the upper and lower cells of a table line. Through the present application, the structure of a three-line table can be more accurately and universally recognized.

[0007] To solve the above problems, the present application provides the following technical solutions:

[0008] A table structure recognition method for three-line table, comprising the following steps:

[0009] S1: reading a three-line table-containing picture to be recognized, and performing preprocessing; the horizontal table lines of the three-line table are equal in length or unequal in length;

[0010] S2: converting the preprocessed three-line table picture into an inverted binary image; specifically, reading the picture of the three-line table to be recognized, converting it into a gray-scale image, performing binaryzation to obtain a binary image img_bin, and performing an inversion operation on each pixel of the binary image to obtain an inverted binary image img_inv;

[0011] S3: performing morphological processing on the inverted binary image img_inv, which is a horizontal erosion and expansion operation, to obtain a horizontal table line image img_horizontal_lines and horizontal table line position information;

[0012] S4: performing a logical OR operation on the pixels of the binary image and the pixels of the horizontal table line image to obtain a table line-free image;

[0013] S5: performing a horizontal erosion operation and a vertical erosion operation on the table line-free image img_bitor, respectively, and combining the results of the horizontal erosion operation and the vertical erosion operation to obtain an initial cell mask img_cell;

[0014] S6: traversing the horizontal table lines, and according to the lengths of the table lines, re-segmenting the cells to obtain a final cell mask img_cell;

[0015] S7: calculating the set of cell row and column sequence information, occupied row and column number information, and cell frame coordinate information in the final cell mask to obtain a table structure representing the three-line table.

[0016] Preferably, the preprocessing comprises:

[0017] An algorithm using Hough transformation is adopted to perform angle correction on the picture to be recognized.

[0018] Preferably, the S3 comprises:

[0019] The inverted binary image is first subjected to a horizontal erosion operation for three iterations, and then subjected to a horizontal expansion operation for four iterations to obtain the horizontal table line image img_horizontal_lines, and only the horizontal table lines are retained;

[0020] Obtaining the coordinates of the horizontal table lines in the XOY coordinate system and the width and height information of the horizontal table lines in the image; the origin of the XOY coordinate system is the top left corner of the image, and the Y axis is positive from top to bottom; arranging the horizontal table lines in ascending order of Y axis coordinates.

[0021] Preferably, S5 comprises:

[0022] Obtaining the image width img_width of the image without table lines, performing a horizontal erosion operation on the image without table lines using a kernel with a size of (2*img_width, kernel_h), and obtaining an image img_horizontal;

[0023] Obtaining the image height img_height of the image without table lines, performing a vertical erosion operation on the image without table lines using a kernel with a size of (kernel_w, 2*img_height), and obtaining an image img_vertical;

[0024] kernel_h is set according to the table row spacing, and kernel_h=3 is usually taken; kernel_w is set according to the table column spacing, and kernel_w=10 is usually taken;

[0025] Merging the image img_horizontal and the image img_vertical with the same weight, performing a NOT operation on the pixels of the merged image, applying a kernel with a preset size, such as a kernel with a size of (2, 2) to perform two dilation operations, and then performing a NOT operation on the pixels, to obtain the initial cell mask img_cell.

[0026] Preferably, S6 comprises:

[0027] Step 6.1: sequentially traversing the horizontal table lines in step 3; if the lengths of all horizontal table lines are equal, taking the initial cell mask as the final cell mask; if there is a horizontal table line shorter than the first horizontal table line, re-dividing the number of cell columns within the horizontal length range above and below the current table line;

[0028] That is, taking the length of the first line as the reference of the total width of the table, if there is a line shorter than the first line, it is considered that there may be cell columns with unequal numbers above and below the table line, and at this time the number of cell columns within the length range of the table line is re-divided;

[0029] Step 6.2: determining a to-be-divided region above the current horizontal table line with the length of the current horizontal table line as the width and the distance between the current horizontal table line and the previous horizontal table line as the height; determining a to-be-divided region below the current horizontal table line with the length of the current horizontal table line as the width and the distance between the current horizontal table line and the next horizontal table line as the height;

[0030] Step 6.3: performing horizontal projection and vertical projection on the two to-be-divided regions (target regions in the image img_bitor) respectively; traversing the horizontal and vertical projection lists respectively, recording the coordinates when the projection value changes, i.e. the projection value changes from 0 or changes to 0, to obtain the coordinate sets cells_x and cells_y, wherein every two adjacent coordinate points are the start and end points of a continuous projection, and if the interval between two adjacent continuous projections is less than a certain threshold, the two adjacent coordinate points are deleted, and the threshold can be 20 in general, at which time the two adjacent coordinate points can be considered as the same continuous projection;

[0031] Step 6.4: traversing the sets cells_x and cells_y to obtain the coordinates of all cells in the to-be-divided region; updating the mask img_cell of the cells in the to-be-divided region;

[0032] Step 6.5: repeating steps 6.1 to 6.4 until the horizontal table lines are traversed to obtain the final cell mask.

[0033] Preferably, the S7 comprises:

[0034] detecting the cell contour of the final cell mask img_cell to obtain the upper-left corner coordinate (x_min, y_min) and width-height information (w, h) of each cell; creating a cell set boxes containing the cell information box(x_min, y_min, w, h) of each cell; and arranging the cell information box in the cell set boxes in ascending order of y_min;

[0035] dividing all the cells in the cell set boxes by rows, establishing n sets row corresponding to each row of table based on the total number of table rows n, taking the cells in each row as the elements in the corresponding set row, and taking all the sets row as the elements in a set rows; here, the first cell in the set is divided into the first row, and all the subsequent cells are traversed to compare the y_min of the current cell with that of the previous cell to determine whether they are in the same row, and the cells in the same row are divided into the same set row, and the sets row is composed of sets row in different rows, wherein the size of the set rows is the total number of table rows i;

[0036] Traverse the set rows, calculate the number of cells in each row, take the maximum number of cells as the total column number m of the table, and take the x_min coordinate of all cells in the row where the maximum number of cells is located as the starting x-axis coordinate of each column, to get the set column_x, where the size of the set column_x is m;

[0037] Create a two-dimensional set bounding_boxes of n rows and m columns; traverse all sets row in the set rows, in any set row, traverse all cells, compare the difference between the x_min of any cell and the starting x-axis coordinate of each column, take the set index corresponding to the minimum difference as the column where the current cell is located, and then assign the box information of the cell to the corresponding row and column position of the set bounding_boxes;

[0038] Since there may be empty sets in some row and column positions in the set bounding_boxes, traverse the set bounding_boxes, calculate the number of rows and columns occupied by each cell according to the distribution of empty sets around the current cell, to get all information of the cell, including: the starting row and column of the cell (row, column), the number of rows and columns occupied by the cell (row_num, col_num), the top-left corner coordinate of the cell (x_min, y_min), and the width and height of the cell (w, h); all information of all cells constitutes the set cells, and the set cells is the table structure of the three-line table; all information is cell(row, column, row_num, col_num, x_min, y_min, w, h).

[0039] An electronic device, comprising: a processor, a memory and a bus, the memory stores machine readable instructions executable by the processor, when the electronic device is running, the processor communicates with the memory through the bus, and the machine readable instructions are executed by the processor to execute the table structure identification method for the three-line table.

[0040] A computer readable storage medium, the computer readable storage medium stores computer executable instructions, the computer executable instructions are loaded and executed by the processor, and the computer executable instructions realize the table structure identification method for the three-line table.

[0041] The present application provides a table structure recognition method, device and storage medium for three-line tables, the three-line tables include tables formed by multiple horizontal lines, the method is more universal, improves the accuracy of recognizing various types of three-line table structures, effectively reduces the problems of missed detection and multiple detection of cells, the table structure result generated by the present application contains complete and specific information, which is beneficial to subsequent table structure restoration and other processing, and the method is non-data driven, does not require a large amount of data, and has small computational complexity. Through the present application, the table structure of a three-line table can be more accurately and universally recognized. BRIEF DESCRIPTION OF DRAWINGS

[0042] In order to more clearly illustrate the technical solutions in the embodiments, the drawings needed to be used in the embodiment description will be briefly introduced. Obviously, the drawings described below are only some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative labor.

[0043] Figure 1 A flowchart of the three-line table structure recognition method in the embodiment of the present application is shown.

[0044] Figure 2 A sample of the complex three-line table to be recognized in the embodiment of the present application is shown.

[0045] Figure 3 A sample of the three-line table without table lines processed in the embodiment of the present application is shown.

[0046] Figure 4 A flowchart of step 150 in the embodiment of the present application is shown.

[0047] Figure 5 An img_horizontal graph completed by step 152 in the embodiment of the present application is shown.

[0048] Figure 6 An img_vertical graph completed by step 153 in the embodiment of the present application is shown.

[0049] Figure 7 An initial cell mask graph after preliminary segmentation of cells in the embodiment of the present application is shown.

[0050] Figure 8 A flowchart of step 160 in the embodiment of the present application is shown.

[0051] Figure 9 A final cell mask graph after completion of segmentation of cells in the embodiment of the present application is shown.

[0052] Figure 10 A flowchart of step 170 in the embodiment of the present application is shown.

[0053] Figure 11 Fig. 1 is a schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION

[0054] In order to make the objects, technical solutions and advantages of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the drawings. The following embodiments will help those skilled in the art to further understand the present application, but do not limit the present application in any form. It should be pointed out that, for those skilled in the art, without departing from the concept of the present application, a number of modifications and improvements can be made, which are all within the protection scope of the present application.

[0055] As shown in Fig. 1, the present application provides a table structure recognition method for three-line table, which is realized based on image recognition and includes the following steps: Figure 1 Step 110: obtaining a to-be-recognized picture containing a three-line table and performing pre-processing correction.

[0056] Further, the step 110 specifically includes:

[0057] An algorithm of Hough transformation is adopted to perform angle correction on the original image; in the present embodiment, the Hough transformation is first performed on the image to detect straight lines in the image, then the inclination angles of the straight lines are calculated, and rotation correction is performed according to the inclination angles.

[0058] Step 120: as shown in Fig. 2, the picture file of the to-be-recognized three-line table is converted into a gray-scale image, and binarization processing is performed to obtain a binarization image img_bin, and an inversion operation is performed on each pixel of the binarization image to obtain an inverted binarization image img_inv.

[0059] Figure 2 The image to be recognized in the present embodiment contains only a three-line table, or a table formed by horizontal table lines only. The table structure style is not limited, and the horizontal table lines can be equal in length or not equal in length; the column numbers of the cells above and below the table lines can be equal or not equal.

[0060] Further, the image img_bin after binarization processing is white background and black characters, and the image img_inv after inversion processing is black background and white characters.

[0061] Step 130: performing horizontal erosion and inflation operations on img_inv to obtain horizontal table line position information and an image img_horizontal_lines.

[0062] Further, the specific process of obtaining the horizontal table line position information and the image is as follows:

[0063] Further, the specific process of obtaining the horizontal table line position information and the image is as follows:

[0064] ​An image width img_width is acquired, and a kernel with a size of (0.02*img_width, 1) is applied to the image to perform three erosion operations and four dilation operations in sequence, to obtain an image img_horizontal_lines that retains only horizontal table lines;

[0065] Contour detection is performed on the image img_horizontal_lines, and an outer rectangle of the contour is acquired to obtain coordinates of a top-left corner of the horizontal table line and width and height information, and the y-axis coordinates of the top-left corner are arranged in ascending order to obtain a set lines.

[0066] Step 140: Pixel or operation is performed on the binarized image img_bin and the horizontal table line image img_horizontal_lines to obtain a table image img_bitor without table lines after merging, as shown in Figure 3 .

[0067] In this embodiment, the image img_bin obtained has a white background and black table lines and characters; the image img_horizontal_lines obtained has a black background and only white table lines at corresponding positions, and the image img_bitor obtained after performing logical or operation on the two images has a white background and only black characters.

[0068] Step 150: Horizontal erosion operation and vertical erosion operation are performed on the table img_bitor without table lines, and an initial cell mask img_cell is obtained after merging, as shown in Figure 4 , and the specific process is as follows:

[0069] Step 151: An image width img_width and an image height img_height are acquired.

[0070] Step 152: Horizontal erosion is performed on the table without table lines by using a horizontal kernel, to obtain img_horizontal; the size of the horizontal kernel is (2*img_width, 3), as shown in Figure 5 .

[0071] Step 153: Vertical erosion is performed on the table without table lines by using a vertical kernel, to obtain img_vertical; the size of the vertical kernel is (10, 2*img_height), as shown in Figure 6 .

[0072] Step 154: img_horizontal and img_vertical are fused with the same weight of 0.5, to obtain img_cell.

[0073] Step 155: logical NOT operation is performed on the image img_cell;

[0074] Step 156: two dilation operations are performed on the image img_cell using a kernel with a size of (2, 2);

[0075] Step 157: logical NOT operation is performed on the image img_cell after the dilation operation;

[0076] Step 158: binaryzation is performed again, only the area where the character pixels are located is retained, and the initial cell mask img_cell is obtained, as shown in Figure 7 .

[0077] Step 160: the horizontal table lines are traversed, and according to the length of the table lines, further cell segmentation is performed on the complex three-line table to obtain the final cell mask img_cell. The specific process is shown in Figure 8 , and the implementation steps are as follows:

[0078] Step 161: the horizontal table lines lines are traversed;

[0079] Step 162: if the traversal is completed, go to step 168; otherwise, go to the next step;

[0080] Step 163: the length of the current table line is shorter than the length of the first line;

[0081] The length of the first line is taken as the reference of the total width of the table. If there is a line shorter than the first line, it is considered that there may be cells with different numbers of columns above and below the table line. At this time, the number of columns of the cells in the length range of the table line is re-divided.

[0082] Step 164: the current table line is taken as the width to determine the re-divided table area;

[0083] A to-be-divided area above the table line is determined with the length of the table line as the width and the distance of the line above the table line as the height. A to-be-divided area below the table line is determined with the length of the table line as the width and the distance of the bottom table line as the height.

[0084] Step 165: the pixels in the region are projected in the horizontal and vertical directions;

[0085] The to-be-divided region in the image img_bitor is respectively subjected to horizontal projection and vertical projection operations. If a pixel value of the to-be-divided region is 0, it is considered to be a black character in the cell, and the projection value of the corresponding coordinate is added by 1. The horizontal and vertical projection lists are respectively traversed, and when the projection value suddenly changes from 0 or to 0, the coordinates are recorded to obtain the coordinate sets cells_x and cells_y. Each adjacent two coordinate points are the start and end points of a continuous projection.

[0086] Step 166: Screen and record the coordinates of the cell in both horizontal and vertical directions by projection;

[0087] Screen the set cells_x. If the distance between two adjacent projections is less than or equal to 20 pixels, it is considered that the two projections belong to one cell. Therefore, the end point of the previous projection and the start point of the next projection are deleted. If the distance between two adjacent projections is greater than 20 pixels, it is considered that the two projections do not belong to one cell, and the midpoint of the distance is taken as the dividing point. The end point of the previous projection and the start point of the next projection are redistributed with appropriate distance. Finally, the processed set cells_x is obtained;

[0088] Screen the set cells_y. If the distance between two adjacent projections is less than or equal to 6 pixels, it is considered that the two projections belong to one cell. Therefore, the end point of the previous projection and the start point of the next projection are deleted. Finally, the processed set cells_y is obtained;

[0089] For each adjacent two points in the set cells_x, the start and end coordinates of a column cell in the region to be segmented are represented. For each adjacent two points in the set cells_y, the start and end coordinates of a row cell in the region to be segmented are represented. Therefore, by traversing the sets cells_x and cells_y, the coordinates of all cells in the region to be segmented can be obtained.

[0090] Step 167: Draw a cell mask in the region to be segmented according to the cell coordinates;

[0091] Modify the cell mask image img_cell according to the coordinates of all cells in the region to be segmented, and the result is shown in Figure 9 .

[0092] Step 168: Return the result to obtain the final cell mask img_cell.

[0093] Step 170: Calculate the cell row and column sequence information, the number of rows and columns occupied information, and the cell frame coordinate information set, which represents the table structure of the three-line table, and the specific process is shown in Figure 10 .

[0094] Step 171: Detect the cell contour to obtain the contour information;

[0095] Detect the contour in the cell mask image img_cell to determine the top-left corner coordinates and width-height information box(x_min, y_min, w, h) of each cell in img_cell. Calculate the average height of the cell mean_height.

[0096] Step 172: arrange the cells from top to bottom according to y_min of the top-left point of each cell;

[0097] According to the y-axis coordinate y_min of the top-left point of each cell, arrange the cells from top to bottom to obtain a cell set boxes; the cell set boxes contains the information of each cell box(x_min, y_min, w, h).

[0098] Step 173: calculate the row position of each cell according to y_min;

[0099] Divide all the cells in the set boxes by rows. First, divide the first cell in the set into the first row, and then traverse all the following cells. Compare the y_min of the current cell with that of the previous cell. If cur_y <= pre_y + 0.5*mean_height, it is considered that the current cell and the previous cell are in the same row. Wherein cur_y is the y-axis coordinate of the current cell, pre_y is the y-axis coordinate of the previous cell, and mean_height is the average height of the cells. Update the cell information box to box(row, x_min, y_min, w, h), and then divide the cells in the same row into the same set row. Divide the sets row into a new set rows, wherein the size of the set rows is the total number of rows i of the table.

[0100] Step 174: calculate the column position of each cell according to x_min;

[0101] Traverse the set rows to calculate the number of cells in each row. Take the maximum number of cells as the total number of columns j of the table, and take the x_min coordinate of all the cells in the row as the starting x-axis coordinate of each column to obtain a set column_x, wherein the size of the set column_x is j. In the current row set row, traverse all the cells and compare the difference between the x_min of the current cell and the starting x-axis coordinate of each column. Take the minimum value of the difference as the column where the current cell is located, and update the cell information box to box(row, column, x_min, y_min, w, h).

[0102] Step 175: construct a two-dimensional set according to the number of rows and the maximum number of columns;

[0103] Create a two-dimensional set bounding_boxes with i rows and j columns. Traverse all the rows in the set rows, and then assign the box information of the cell to the corresponding row and column position in the set bounding_boxes.

[0104] After the above steps are executed, some rows and columns in the set bounding_boxes can have empty sets. The set bounding_boxes is traversed, the rows of the two-dimensional set bounding_boxes are traversed first, and then the columns are traversed. According to the distribution of the empty sets around the current cell, the number of rows and columns occupied by the cell is calculated. For each cell in each row, the right and down directions are searched to determine whether there is a rectangular region in which only the cell is non-empty. If there is, the number of columns and rows of the region is recorded, and the empty set is filled with a specific element to prevent repetition. The specific steps are as follows:

[0105] Step 176: Traverse the rows of the two-dimensional set.

[0106] Step 177: If the traversal is completed, go to step 187; otherwise, go to the next step.

[0107] Step 178: Traverse all cells in the current row.

[0108] Step 179: If the traversal is completed, go to step 176; otherwise, go to the next step.

[0109] Step 180: Take the current cell as a target cell, and detect whether a cell in the same column is empty.

[0110] Step 181: If the current cell is empty, go to the next step; otherwise, go to step 183.

[0111] Step 182: The number of rows occupied by the target cell is incremented by 1; go to step 180.

[0112] Step 183: From the current cell, detect whether a cell in the same row is empty.

[0113] Step 184: If the current cell is empty, go to the next step; otherwise, go to step 178.

[0114] Step 185: If other cells in the column in which the target cell is located are empty, go to the next step; otherwise, go to step 183. The cells are determined by the column index of the current cell and all row indexes of the target cell. If these cells are empty, it is considered that the number of columns occupied by the target cell is incremented by 1.

[0115] Step 186: The number of columns occupied by the target cell is incremented by 1; go to step 183.

[0116] Step 187: Return the cell structure. The cell structure is increased by the number of rows and columns occupied by the cell, and the cell information box is updated to box(row, column, row_num, col_num, x_min, y_min, w, h).

[0117] Through the above steps, all information of the cell box(row, column, row_num, col_num, x_min, y_min, w, h) can be obtained; wherein (row, column) represents the starting row and column number of the cell, (row_num, col_num) represents the row and column number occupied by the cell, (x_min, y_min, w, h) represents the coordinate and width and height information of the cell bounding box. Finally, a cell set cells is generated, which represents the table structure.

[0118] Through the implementation of the above embodiments, it is not difficult to find that the method provided by the present application solves the structure recognition of three-line tables, and in particular, solves the structure recognition of complex three-line tables in which the number of cell columns above and below a certain table line is inconsistent. Through the present application, the structure of a three-line table can be more accurately and more universally recognized.

[0119] Figure 11 To realize the structure of an electronic device provided by the embodiment of the present application. As shown in Figure 11 The electronic device 200 includes a processor 201, a memory 202 and a bus 203.

[0120] The memory 202 stores machine readable instructions executable by the processor 201. When the electronic device 200 is running, the processor 201 communicates with the memory 202 through the bus 203. The machine readable instructions can execute the method for recognizing the table structure of a three-line table as described above Figures 1 to 10 The specific implementation can be referred to in the embodiment, which will not be described here.

[0121] The embodiment of the present application also provides a computer readable storage medium, which stores a computer program. When the computer program is run by a processor, it can execute the data preprocessing method of the Internet of Things edge gateway as described in the above embodiment. The specific implementation can be referred to in the embodiment.

[0122] The above is part of the embodiments of the present application. Although the content of the present application has been described in detail through the above part of the embodiments, it should be recognized that the above description should not be considered as a limitation of the present application. After reading the above content, various modifications and alternatives of the present application will be obvious to those skilled in the art. Therefore, the protection scope of the present application should be defined by the appended claims.

Claims

1. A table structure recognition method for three-line tables, characterized by, The method comprises the following steps: S1: reading a three-line table-containing picture to be recognized and performing preprocessing; the horizontal table lines of the three-line table are equal in length or unequal in length; S2: converting the three-line table-containing picture after the preprocessing into a negated binary image; S3: performing morphological processing on the negated binary image to obtain a horizontal table line image; S4: performing a logical OR operation on the pixels of the binary image and the pixels of the horizontal table line image to obtain a table line-free image; S5: performing horizontal and vertical erosion operations on the table line-free image respectively, and combining the results of the horizontal and vertical erosion operations to obtain an initial cell mask; S6: comprising: Step 6.1: sequentially traversing the horizontal table lines; if all the horizontal table lines are equal in length, taking the initial cell mask as a final cell mask; if a horizontal table line shorter than the first horizontal table line appears, re-dividing the cell column numbers in the horizontal length range above and below the current table line; Step 6.2: determining a to-be-divided region above the current horizontal table line with the length of the current horizontal table line as the width and the distance between the current horizontal table line and the previous horizontal table line as the height; determining a to-be-divided region below the current horizontal table line with the length of the current horizontal table line as the width and the distance between the current horizontal table line and the next horizontal table line as the height; Step 6.3: performing horizontal and vertical projections on the two to-be-divided regions respectively; traversing the horizontal and vertical projection lists respectively, and recording the coordinates when the projection values change to obtain coordinate sets cells_x and cells_y, wherein each two adjacent coordinate points are the start and end points of a continuous projection, and if the interval between two adjacent continuous projections is less than a certain threshold, the two adjacent coordinate points are deleted; Step 6.4: traversing the sets cells_x and cells_y to obtain the coordinates of all the cells in the to-be-divided region; and updating the mask of the cells in the to-be-divided region; Step 6.5: repeating steps 6.1 to 6.4 until all the horizontal table lines are traversed to obtain the final cell mask; S7: calculating the set of cell row and column sequence information, occupied row and column number information and cell frame coordinate information in the final cell mask to obtain a table structure representing the three-line table.

2. The table structure recognition method for three-line tables according to claim 1, characterized in that, The preprocessing comprises: An algorithm using Hough transformation is adopted to perform angle correction on the picture to be recognized.

3. The table structure recognition method for three-line tables according to claim 1, characterized in that, The S3 comprises: The negated binary image is first subjected to a horizontal erosion operation for three iterations, and then subjected to a horizontal dilation operation for four iterations to obtain the horizontal table line image; The coordinates and width and height information of the horizontal table lines in the XOY coordinate system are obtained; the origin of the XOY coordinate system is the upper left corner of the image, and the Y axis is positive from top to bottom; the horizontal table lines are arranged in ascending order according to the Y axis coordinates.

4. The table structure recognition method for three-line tables according to claim 1, characterized in that, The S5 comprises: Obtaining an image width img_width of the table-free line image, applying a kernel with a size of (2*img_width, kernel_h) to the table-free line image to perform a horizontal erosion operation, and obtaining an image img_horizontal; Obtaining an image height img_height of the table-free line image, applying a kernel with a size of (kernel_w, 2*img_height) to the table-free line image to perform a vertical erosion operation, and obtaining an image img_vertical; Merging the image img_horizontal and the image img_vertical with the same weight, performing an exclusive OR operation on pixels of the merged image, applying a kernel with a preset size to perform two dilation operations, then performing an exclusive OR operation on the pixels, and obtaining the initial cell mask.

5. The table structure recognition method for three-line tables according to claim 1, characterized in that, The S7 comprises: Detecting a cell contour of the final cell mask, obtaining a top-left corner coordinate (x_min, y_min) and width-height information (w, h) of each cell, creating a cell set boxes, the cell set boxes containing cell information box(x_min, y_min, w, h) of each cell, and arranging the cell information box in the cell set boxes in ascending order according to y_min; Dividing all cells in the cell set boxes by rows, establishing n sets row corresponding to each row table based on a total number of rows n of the table, taking cells of each row as elements in the corresponding set row, and taking all sets row as elements of a set rows; Traversing the set rows, calculating a number of cells in each row, taking a maximum number of cells as a total number of columns m of the table, and taking x_min coordinates of all cells in a row where the maximum number of cells is located as a starting x-axis coordinate of each column, to obtain a set column_x, wherein the size of the set column_x is m; Creating a two-dimensional set bounding_boxes with n rows and m columns, traversing all sets row of the set rows, traversing all cells in any set row, comparing a difference between x_min of any cell and a starting x-axis coordinate of each column, taking a set index corresponding to a minimum value of the difference as a column where the current cell is located, and assigning box information of the cell to a corresponding row-column position of the set bounding_boxes; Traversing the set bounding_boxes, calculating a number of rows and a number of columns occupied by each cell, and obtaining all information of the cell, including: a starting row and column (row, column) of the cell, a number of rows and columns (row_num, col_num) occupied by the cell, a top-left corner coordinate (x_min, y_min) of the cell, and width and height (w, h) of the cell; and all information of all cells constitutes a set cells, and the set cells is a table structure of a three-line table.

6. An electronic device, comprising: Comprise: The processor, the memory and the bus, the memory stores the machine readable instructions executable by the processor, when the electronic device runs, the processor and the memory communicate through the bus, the machine readable instructions are executed by the processor and execute the table structure identification method for three-line table as any one of claims 1 to 5.

7. A computer-readable storage medium, characterized in that, The computer readable storage medium stores computer executable instructions, the computer executable instructions are loaded and executed by the processor, and the computer executable instructions realize the table structure identification method for three-line table as any one of claims 1 to 5.

Citation Information

Patent Citations

  • Table structure restoration method, device, equipment, system and readable storage medium

    CN111626027A

  • Method and device for automatically identifying paper table structure

    CN112036294A

  • Method for extracting and organizing unstructured sheet document data under big data environment

    CN105630916A

  • Three-line table image recognition method and device

    CN113869085A