Table line positioning method and system

Through the method and matrix operation based on cosine similarity, the table line positioning process is simplified, solving the problem of insufficient recognition of table structures with both pictures and text in the existing technology, achieving accurate positioning of multiple table types, and simplifying the process And reduce the amount of calculation.

CN114511861BActive Publication Date: 2024-09-06HANGZHOU WEIMING XINKE TECH CO LTD +1
View PDF 7 Cites 0 Cited by

Patent Information

Application Number
CN202111563229.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-20
Publication Date
2024-09-06
Estimated Expiration
2041-12-20

AI Technical Summary

Technical Problem

Existing table line detection algorithms are mainly aimed at wired or plain text tables. It is difficult to effectively identify table structures with both graphics and text, and there are cases of multiple or missed text boxes, resulting in inaccurate positioning of table lines and complicated and easy post-processing operations. wrong.

Method used

The method based on cosine similarity is used to distinguish the background and content in the grayscale table image, calculate the interval between adjacent content lines, and determine the position of the table line based on the threshold. The table line positioning process is simplified through matrix operations, and is suitable for a variety of table types.

Benefits of technology

It improves the applicability of the table line positioning algorithm, simplifies the process, reduces the amount of calculation, and avoids heavy post-processing operations. It is suitable for wireless, wired, mixed graphics and text, and plain text tables, and enhances the positioning accuracy.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114511861B
    Figure CN114511861B
Patent Text Reader

Abstract

The embodiment of the present application discloses a table line positioning method and system, the method comprising: using a matrix to store a grayscale table image; distinguishing the background and content in the grayscale table image based on cosine similarity to obtain a content line set; calculating the interval set of adjacent content lines based on the content line set; judging the position of the table line based on a threshold in the interval set to obtain a table line position set, wherein the table line is used to separate the content of different rows and columns in the table. The method based on cosine similarity is used to judge whether each line of the image belongs to a background line or a content line, and then the table line is used to separate the adjacent content lines to obtain the position of the table line; the problem of identifying multiple table structures is solved, and the applicability of the table line positioning algorithm is improved in a simple and efficient way.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present application relate to the field of artificial intelligence technology, and specifically to a table line positioning method and system. Background Art

[0002] Tables are a concise way to record and summarize data. They can effectively and intuitively convey information, so they are often used in data analysis and research. Table structure recognition is the basis for improving the efficiency of table use and structuring table data. Therefore, it has broad application prospects and is also a hot topic in the current image processing field. Table structure recognition is easily affected by many factors, such as the presence or absence of table lines, single or multiple table backgrounds, and whether the table content is pure text or both text and images.

[0003] Most of the existing table line detection and extraction methods are based on the binary table image, and the vertical and horizontal lines in the table image are extracted through the Hough transform line detection algorithm, and then the vertical and horizontal lines are corrected through post-processing algorithms such as interference removal and adjacent line merging, and finally the position of the table line is obtained. The above table line detection method ignores the research on wireless table structure recognition. In addition, the Hough transform involved in this method is easily interfered by the linear response brought by text, and the post-processing operation is complicated and error-prone.

[0004] There are other algorithms that use text detection models to obtain text boxes in binary table images, and then perform row clustering or column clustering on the text boxes to determine the spatial structure of the table based on the clustering results. However, this type of method is only applicable to some pure text tables, and is not applicable to tables with both text and images that are not mentioned. In addition, because text detection algorithms often have multiple or missed text boxes, they often lead to incorrect positioning of table lines.

[0005] Most of the existing table line detection algorithms are for wired tables or plain text tables. However, in actual applications, the form of tables is not limited to this, so the existing technology is slightly insufficient in structural recognition for other types of tables. In addition, in the above schemes, whether it is mainly based on morphological detection or text detection algorithm for table line detection, a large amount of post-processing process is required to finally determine the position of the table line. Summary of the invention

[0006] To this end, an embodiment of the present application provides a table line positioning method and system to solve the problem of identifying various table structures. It uses a cosine similarity-based method to determine whether each line of the image belongs to a background line or a content line, and then determines whether adjacent content lines need to be separated by table lines, and finally obtains the position of the table lines. It improves the applicability of the table line positioning algorithm in a simple and efficient way.

[0007] In order to achieve the above objectives, the embodiments of the present application provide the following technical solutions:

[0008] According to a first aspect of an embodiment of the present application, a table line positioning method is provided, the method comprising:

[0009] Use a matrix to store grayscale table images;

[0010] Distinguish the background and content in the grayscale table image based on cosine similarity to obtain a content line set;

[0011] Calculate the interval set of adjacent content lines according to the content line set;

[0012] The table line position is determined based on the threshold in the interval set to obtain a table line position set, where the table line is used to separate contents of different rows and columns in the table.

[0013] Optionally, the background and content in the grayscale table image are distinguished based on cosine similarity to obtain a content line set, including:

[0014] Calculate the cosine similarity of each line in the grayscale table image with all parallel lines in the image, and sum them up to obtain the total cosine similarity of the line; the line includes horizontal lines and vertical lines;

[0015] The total cosine similarities of all lines are sorted, and the horizontal lines and vertical lines with the largest total cosine similarities are recorded as background lines; the background lines include background horizontal lines and background vertical lines;

[0016] Lines whose cosine similarity with background lines is lower than a set threshold are counted into a content line set; the content lines include content horizontal lines and content vertical lines; the content horizontal lines in the set are arranged in the order of the horizontal lines in the image from top to bottom, and the content vertical lines are arranged in the order of the vertical lines in the image from left to right.

[0017] Optionally, the cosine similarity of each line in the grayscale table image to all parallel lines in the image is calculated, including:

[0018] Perform matrix multiplication on the matrix and its transposed matrix to obtain a matrix multiplication result with a size of L×L;

[0019] According to the calculation method of cosine similarity, the two matrices are operated modulo, and the modulus of each column of the matrix and the modulus of each row of its transposed matrix are calculated, and matrices of size L×1 and 1×L are obtained respectively. The two matrices are multiplied to obtain a matrix storing the results of the modulo operation, which is of size L×L.

[0020] Divide the matrix multiplication result by the corresponding position of the matrix storing the modular operation result to obtain a matrix of cosine similarity between each line and L lines in the grayscale table image, with a size of L×L.

[0021] Optionally, after calculating the interval set of adjacent content lines according to the content line set, the method further includes:

[0022] Filters out the values ​​that are not in the set range in an interval collection and sorts the elements of the interval collection in ascending order.

[0023] Optionally, determining the table line position in the interval set based on a threshold to obtain a table line position set includes:

[0024] Determine whether the interval between adjacent content lines is greater than a set interval line threshold;

[0025] If so, add the table line in the middle of the interval between adjacent content lines to the table line position set.

[0026] Optionally, the method further comprises:

[0027] According to the positions of the table line elements in the table line position set, the table lines are presented on the grayscale table image respectively, and the table lines include table horizontal lines and table vertical lines.

[0028] Optionally, if an adaptive method is selected to set the interval line threshold, the method includes:

[0029] Arrange all content lines in ascending order and calculate the set of intervals of all adjacent content lines;

[0030] Deleting values ​​that are not within a set range from the interval set to obtain a filtered content line interval set;

[0031] The value of the set quantile in the content line interval set is used as the table line threshold;

[0032] The middle of two adjacent content lines whose interval exceeds the table line threshold is separated by a table line, and the position of the table line is added to the table line position set.

[0033] According to a second aspect of an embodiment of the present application, a table line positioning system is provided, the system comprising:

[0034] A matrix storage module, used to store grayscale table images using a matrix;

[0035] A content line set calculation module is used to distinguish the background and content in the grayscale table image based on cosine similarity to obtain a content line set;

[0036] A content line interval calculation module, used to calculate an interval set of adjacent content lines according to a content line set;

[0037] The table line determination module is used to determine the table line position in the interval set based on the threshold value to obtain a table line position set, wherein the table line is used to separate the contents of different rows and columns in the table.

[0038] According to a third aspect of an embodiment of the present application, an electronic device is provided, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement any one of the methods described in the first aspect.

[0039] According to a fourth aspect of an embodiment of the present application, a computer-readable storage medium is provided, wherein the computer storage medium contains one or more program instructions, and the one or more program instructions are used to execute the method as described in any one of the first aspects.

[0040] In summary, the embodiments of the present application provide a table line positioning method and system, which uses a matrix to store grayscale table images; distinguishes the background and content in the grayscale table image based on cosine similarity to obtain a content line set; calculates the interval set of adjacent content lines based on the content line set; determines the position of the table line based on a threshold in the interval set to obtain a table line position set, and the table line is used to separate the content of different rows and columns in the table. The method based on cosine similarity is used to determine whether each line of the image belongs to a background line or a content line, and then the table line is used to separate the adjacent content lines to obtain the position of the table line; solves the problem of identifying multiple table structures, and improves the applicability of the table line positioning algorithm in a simple and efficient way. BRIEF DESCRIPTION OF THE DRAWINGS

[0041] In order to more clearly illustrate the implementation methods of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for the implementation methods or the description of the prior art. Obviously, the drawings in the following description are only exemplary, and for ordinary technicians in this field, other implementation drawings can be derived from the provided drawings without creative work.

[0042] The structures, proportions, sizes, etc. illustrated in this specification are only used to match the contents disclosed in the specification so as to facilitate understanding and reading by persons familiar with the technology. They are not used to limit the conditions under which the present invention can be implemented, and therefore have no substantial technical significance. Any structural modification, change in proportion or adjustment of size shall still fall within the scope of the technical contents disclosed in the present invention without affecting the effects and purposes that can be achieved by the present invention.

[0043] Figure 1 A schematic diagram of a table line positioning method flow chart provided in an embodiment of the present application;

[0044] Figure 2 The original image of the table provided in the embodiment of the present application;

[0045] Figure 3A flow chart of cosine similarity calculation provided in an embodiment of the present application;

[0046] Figure 4 A diagram showing the vertical content line set covering effect provided in an embodiment of the present application;

[0047] Figure 5 A diagram showing the covering effect of a set of horizontal content lines provided in an embodiment of the present application;

[0048] Figure 6 A flow chart of threshold selection provided in an embodiment of the present application;

[0049] Figure 7 This is a superimposed effect diagram of the adaptive threshold row and column grid positioning results provided in the embodiment of the present application;

[0050] Figure 8 This is a superimposed effect diagram of the artificial threshold row and column grid positioning results provided in the embodiment of the present application;

[0051] Fig. 9 A block diagram of a table line positioning system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0052] The following is a description of the implementation of the present invention by specific embodiments. People familiar with the art can easily understand other advantages and effects of the present invention from the contents disclosed in this specification. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0053] The table line positioning method provided in the embodiment of the present application is intended to solve the problem of identifying various table structures in the simplest possible way. The types of tables targeted include but are not limited to: wireless tables, wired tables, tables with a single background color and tables with multiple background colors, as well as pure text tables and tables with mixed text and images.

[0054] In order to solve the above-mentioned type of table structure recognition problem, the embodiment of the present application adopts a cosine similarity-based method to determine whether each horizontal line and each vertical line of the image belongs to the background line or the content line, and then uses an adaptive threshold method to determine whether adjacent content lines need to be separated by table lines, and finally obtains the positions of the horizontal table lines and the vertical table lines.

[0055] The embodiments of the present application are suitable for locating table lines of tables that are wired or wireless, have diverse or single background colors, and are mixed with graphics or pure text. The simple and effective solution improves the applicability of the table line locating algorithm and avoids a large number of complex post-processing operations.

[0056] Figure 1A schematic diagram of a table line positioning method provided in an embodiment of the present application is shown, and the method includes:

[0057] Step 101: Use a matrix to store a grayscale table image;

[0058] Step 102: Distinguish the background and content in the grayscale table image based on cosine similarity to obtain a content line set;

[0059] Step 103: Calculate the interval set of adjacent content lines according to the content line set;

[0060] Step 104: determining the table line position in the interval set based on the threshold value to obtain a table line position set, wherein the table line is used to separate the contents of different rows and columns in the table.

[0061] In a possible implementation, in step 102, the background and content in the grayscale table image are distinguished based on cosine similarity to obtain a content line set, including:

[0062] Calculate the cosine similarity of each line in the grayscale table image with all parallel lines in the image, and sum them up to obtain the total cosine similarity of the line; the line includes horizontal lines and vertical lines;

[0063] The total cosine similarities of all lines are sorted, and the horizontal lines and vertical lines with the largest total cosine similarities are recorded as background lines; the background lines include background horizontal lines and background vertical lines;

[0064] Lines whose cosine similarity with background lines is lower than a set threshold are counted into a content line set; the content lines include content horizontal lines and content vertical lines; the content horizontal lines in the set are arranged in the order of the horizontal lines in the image from top to bottom, and the content vertical lines are arranged in the order of the vertical lines in the image from left to right.

[0065] In a possible implementation, calculating the cosine similarity between each line in the grayscale table image and all parallel lines in the image includes:

[0066] Perform matrix multiplication on the matrix and its transposed matrix to obtain a matrix multiplication result with a size of L×L;

[0067] According to the calculation method of cosine similarity, the two matrices are operated modulo, and the modulus of each column of the matrix and the modulus of each row of its transposed matrix are calculated, and matrices of size L×1 and 1×L are obtained respectively. The two matrices are multiplied to obtain a matrix storing the results of the modulo operation, which is of size L×L.

[0068] Divide the matrix multiplication result by the corresponding position of the matrix storing the modular operation result to obtain a matrix of cosine similarity between each line and L lines in the grayscale table image, with a size of L×L.

[0069] In a possible implementation manner, after calculating the interval set of adjacent content lines according to the content line set, the method further includes:

[0070] Filters out the values ​​that are not in the set range in an interval collection and sorts the elements of the interval collection in ascending order.

[0071] In a possible implementation, in step 104, determining the table line position in the interval set based on the threshold to obtain the table line position set includes:

[0072] Select an adaptive method or a manual method to set the interval line threshold; determine whether the interval between adjacent content lines is greater than the set interval line threshold; if so, add the table line at the middle position of the interval between adjacent content lines to the table line position set.

[0073] In a possible implementation, after step 104, table lines are presented on the grayscale table image according to the positions of table line elements in the table line position set, and the table lines include table horizontal lines and table vertical lines.

[0074] In a possible implementation manner, if a manual method is selected to set the interval line threshold, the method includes:

[0075] A table line threshold is manually set according to the interval between content lines in the grayscale table image; the manually set table line threshold includes a manually set horizontal table line threshold and a manually set vertical table line threshold; the middle of two adjacent content lines whose interval is greater than the manually set table line threshold is separated by a table line, and the position of the table line is added to a table line position set.

[0076] In a possible implementation manner, if an adaptive method is selected to set the interval line threshold, the method includes:

[0077] Arrange all content lines in ascending order, and calculate the interval set of all adjacent content lines; delete values ​​that are not within the set range from the interval set to obtain a filtered content line interval set; set the value of the percentile in the content line interval set as the table line threshold; separate the middle of two adjacent content lines whose interval exceeds the table line threshold with a table line, and add the position of the table line to the table line position set.

[0078] The table line positioning method provided in the embodiment of the present application is further described in detail below with reference to the accompanying drawings.

[0079] The first aspect is image acquisition and storage: using matrices to store grayscale table images.

[0080] 1.1. Get the initial table image. The table image size is W×H. The original table image can be found at Figure 2 .

[0081] 1.2. Convert the initial table image into a grayscale image to generate a grayscale table image.

[0082] 1.3. Use the two-dimensional array image_array to store the pixel value corresponding to each pixel in the grayscale image data. At the same time, the data type of the array image_array needs to be converted from int32 to uint8, and the array size is W×H.

[0083] Secondly, the positions of the content lines (content horizontal lines, content vertical lines) are determined based on the cosine similarity.

[0084] 2.1 The content line is the non-background line, which contains actual content, such as text, images, symbols, etc. Determining the position of the content line in the table image needs to be divided into two parts, mainly the determination of the horizontal and vertical content line positions. It should be noted that the processes of the two parts are the same and there is no order relationship.

[0085] In this embodiment, the horizontal content line position is confirmed first. The calculation flow chart of cosine similarity can be found in Figure 3 :

[0086] Step 1: First convert the array image_array into a matrix to get the matrix image_matrix.

[0087] Step 2: To calculate the total cosine similarity of each horizontal line in the grayscale table image, you need to first perform image_matrix and its transposed matrix image_matrix T Perform matrix multiplication to obtain the result of matrix multiplication multiply_matrix_row, whose size is H×H, and the calculation formula is: image_matrix×image_matrix T =multiply_matrix_row.

[0088] Step 3: According to the calculation method of cosine similarity, it is necessary to perform a modulus operation on the two matrices to find the modulus of each column of the matrix image_matrix and the matrix image_matrix T The modulus of each row is obtained as matrices of size H×1 and 1×H respectively. These two matrices are multiplied to obtain the matrix norm_matrix_row that stores the results of the modulus operation, which is of size H×H.

[0089] Step 4: Divide the corresponding positions of the multiplication result multiply_matrix_row and the modulus operation result norm_matrix_row to obtain the matrix cosine_matrix_row of the cosine similarity between each horizontal line and the H horizontal lines in the grayscale table image. In this embodiment, the matrix is ​​as follows, with a size of H×H.

[0090]

[0091] Step 5: Sum the cosine similarity values ​​of each row in the cosine similarity matrix cosine_matrix_row as the total cosine similarity of the horizontal line in the grayscale table image. The total cosine similarities of the H horizontal lines are sorted in ascending order, and the horizontal line with the largest total cosine similarity value is identified as the first background horizontal line.

[0092] Step 6: After determining the first background horizontal line, you need to identify the content horizontal line. From the cosine similarity matrix cosine_matrix_row, get the cosine similarity between the first background horizontal line and all other horizontal lines. The horizontal lines with a cosine similarity lower than the preset threshold are recorded as content horizontal lines. In this way, we get a set of N content horizontal lines {row1, row2, row3, ..., row N}, and the horizontal lines in the set are arranged in the order of the horizontal lines in the image from top to bottom. In this embodiment, the effect diagram of N content horizontal lines presented on the grayscale table image can be referred to Figure 4 , Figure 4 This is a diagram of the vertical content line set masking effect.

[0093] 2.2 Further, determine the position of the vertical content line:

[0094] Step a: To calculate the total cosine similarity of each vertical line in the grayscale table image, you need to first transpose the image_matrix T Perform matrix multiplication with image_matrix to obtain the matrix multiplication result multiply_matrix_col, whose size is W×W. The calculation formula is: image_matrix T ×image_matrix=multiply_matrix_col.

[0095] Step b: According to the calculation method of cosine similarity, it is necessary to perform a modulus operation on the two matrices to find the modulus of each column of the matrix image_matrix and the matrix image_matrix TThe modulus of each row is obtained as matrices of size W×1 and 1×W respectively. These two matrices are multiplied to obtain the matrix norm_matrix_col that stores the results of the modulus operation, which is of size W×W.

[0096] Step c: Divide the corresponding positions of the multiplication result multiply_matrix_col and the modulus operation result norm_matrix_col to obtain the matrix cosine_matrix_col of the cosine similarity between each vertical line and W vertical lines in the grayscale table image. In this embodiment, the matrix is ​​as follows, with a size of W×W.

[0097]

[0098] Step d: sum up the cosine similarity values ​​of each row in the cosine similarity matrix cosine_matrix_col as the total cosine similarity of the vertical line in the grayscale table image. Sort the total cosine similarities of the W vertical lines in ascending order, where the vertical line with the largest total cosine similarity value is identified as the first background vertical line.

[0099] Step e: After determining the first background vertical line, it is necessary to identify the content vertical line. From the cosine similarity matrix cosine_matrix_col, obtain the cosine similarity between the first background vertical line and all other vertical lines. The vertical lines with cosine similarity to the first background vertical line lower than the preset threshold are recorded as content vertical lines. In this way, a set of M content vertical lines {col1,col2,col3,...,col M}, and the vertical lines in the set are arranged in the order of the vertical lines in the image from left to right. In this embodiment, the effect diagram of M content vertical lines presented on the grayscale table image can be referred to Figure 5 , Figure 5 A collection of horizontal content lines to cover the effect diagram.

[0100] The reason why the horizontal and vertical lines with the largest total cosine similarity are the background lines is that in most grayscale table images, the pattern of the background horizontal or vertical lines is consistent and repeated, so the pattern of the pixel value arrangement that makes up the background line is also fixed and repeated. However, the arrangement pattern of the pixel values ​​on each content line is different. This makes the total cosine similarity of the background line higher, while the total cosine similarity of the content line is lower. Therefore, in most grayscale image tables, the horizontal and vertical lines with the largest total cosine similarity can be used as background lines.

[0101] The third aspect is the positioning of table lines: the position of table lines is determined based on the threshold.

[0102] 3.1 For tables, the intervals between content lines are basically the same in the same grid. If they are not in the same grid, it means that the interval between content lines is greater than the threshold, and table lines should be used to separate two adjacent content lines into two grids. For the selection flow chart of table line positioning, please refer to Figure 6 After obtaining the content line set, it is necessary to determine whether the interval between adjacent content lines is greater than a threshold. If it is greater than the threshold, the table line is positioned in the middle of the adjacent content lines. The threshold can be determined in an adaptive manner or manually set.

[0103] 3.2 If the threshold is obtained by adaptive method;

[0104] 3.2.1 The thresholds are the horizontal line spacing threshold and the vertical line spacing threshold of the table, respectively. The two processes are consistent and have no order. In this embodiment, the horizontal line spacing threshold of the table is obtained first:

[0105] Step a: According to the content horizontal line set {row1, row2, row3, ..., row N}, get the interval set of all adjacent content horizontal lines, take row1 and row2 as an example, the interval calculation method is interval = row2-row1. And sort the elements of the set in ascending order to get the interval set interval_row.

[0106] Step b: Delete the values ​​with too small intervals from the interval set interval_row to obtain a filtered set. In this embodiment, if the interval is less than or equal to 2, it will be filtered out. It should be explained here that the reason for deleting too small intervals is that if the interval is too small, it means that the two lines belong to the same grid and should not be separated by table lines.

[0107] Step c: Using a value of a quantile in the interval set interval_row as the horizontal table line threshold. In this embodiment, the value of the fifth third quantile is used as the threshold, and the threshold is 27.

[0108] Step d: If the interval between two content lines exceeds the horizontal table line threshold, it means that there is a table line between the two content lines. a and row a+1 For example, the calculation method of the horizontal line position of the table is: Add the position of this table horizontal line to the table horizontal line position set tableline_row.

[0109] 3.2.2 Next, get the vertical line interval threshold of the table:

[0110] Step a: According to the content vertical line set {col1,col2,col3,...,col M}, get the interval set of all adjacent vertical lines of content, take col1 and col2 as an example, the interval is calculated as interval = col2-col1. And sort the elements of the set in ascending order to get the interval set interval_col.

[0111] Step b: Delete the values ​​with too small interval from the interval set interval_col to obtain a filtered set. In this embodiment, if the interval is less than or equal to 2, it will be filtered out.

[0112] Step c: Using a value of a quantile in the interval set interval_col as a threshold. In this embodiment, the value of the fifth quarter quantile is used as the vertical table line threshold, and the threshold is 21.

[0113] Step d: If the interval between two vertical content lines exceeds the vertical table line threshold, it means that there is a vertical table line between the two vertical content lines, with col a and col a+1 For example, the calculation method of the vertical line position of the table is: Add the position of this table's vertical line to the table's vertical line position set tableline_col.

[0114] 3.2.3 According to the position of the table line elements in the table horizontal line position set tableline_row and the table vertical line position set tableline_col, the table line is presented on the original image. The result can be seen in Figure 7 , Figure 7 This is an overlay effect diagram of the adaptive threshold row and column grid positioning results.

[0115] 3.3 If the threshold is obtained by manual setting;

[0116] Step a: A suitable horizontal table line threshold and vertical table line threshold can be manually set according to the interval of content lines in the grayscale table image. Specifically, in this embodiment, the horizontal table line threshold and the vertical table line threshold can be set to 27 and 27 respectively.

[0117] Step b: If the interval between adjacent content horizontal lines is greater than the manually set horizontal table line threshold 27, it means that a table horizontal line needs to be used to separate the two content horizontal lines. The table horizontal line is added to the table horizontal line position set tableline_row to finally obtain the table horizontal line position set tableline_row.

[0118] Step c: If the interval between adjacent vertical content lines is greater than the manually set vertical table line threshold 27, it means that the middle of the two vertical content lines needs to be separated by a vertical table line. The vertical table line is added to the table vertical line position set tableline_col, and finally the table vertical line position set tableline_col is obtained.

[0119] Step d: Display the table line on the original image according to the position of the table line elements in the tableline_row and tableline_col sets. The result can be found in Figure 8 , Figure 8 This is the overlay effect diagram of the manual threshold row and column grid positioning results.

[0120] The embodiments of the present application solve the problem of table line positioning for various types of tables, and greatly improve the applicability of the table line positioning algorithm. Cosine similarity is used to distinguish between content lines and background lines in grayscale table images, and then the table lines are positioned in the intervals between content lines by means of adaptive thresholds. Compared with the common table line positioning and detection algorithms that are only applicable to pure text, wired, and single-background tables, such as text detection algorithms and straight line detection algorithms, table line positioning algorithms that are applicable to various types of tables, including wired tables, wireless tables, pure text tables, tables with both text and images, tables with a single background color, and tables with multiple background colors.

[0121] In addition, the embodiment of the present application greatly simplifies the process of the table line location algorithm, making the table line location algorithm more lightweight and convenient. The cosine similarity and matrix operation are used to greatly reduce the amount of calculation in traditional table line detection.

[0122] When the table lines are automatically positioned in the future using the method provided by the embodiment of the present application, an appropriate threshold can be selected in an adaptive manner to separate the content lines. On the basis of ensuring the accuracy of the table line positioning, the heavy post-processing operation process in the previous straight line detection algorithm technology, such as interference elimination of line segments and merging of adjacent line segments, is completely eliminated, and the automatic positioning of the table lines is finally achieved. At the same time, compared with the previous solution that requires the use of a text detection algorithm, the cost of iterative training models is avoided, and it is also lighter in use.

[0123] In summary, the embodiment of the present application provides a table line positioning method, which uses a matrix to store grayscale table images; distinguishes the background and content in the grayscale table image based on cosine similarity to obtain a content line set; calculates the interval set of adjacent content lines based on the content line set; determines the position of the table line based on the threshold in the interval set to obtain a table line position set, and the table line is used to separate the content of different rows and columns in the table. The method based on cosine similarity is used to determine whether each line of the image belongs to the background line or the content line, and then the table line is used to separate the adjacent content lines to obtain the position of the table line; solves the problem of identifying multiple table structures, and improves the applicability of the table line positioning algorithm in a simple and efficient way.

[0124] Based on the same technical concept, the embodiment of the present application also provides a table line positioning system, such as Fig. 9 As shown, the system comprises:

[0125] A matrix storage module 901 is used to store grayscale table images using a matrix;

[0126] A content line set calculation module 902 is used to distinguish the background and content in the grayscale table image based on cosine similarity to obtain a content line set;

[0127] A content line interval calculation module 903, configured to calculate an interval set of adjacent content lines according to a content line set;

[0128] The table line determination module 904 is used to determine the table line position in the interval set based on the threshold value to obtain a table line position set, wherein the table line is used to separate the contents of different rows and columns in the table.

[0129] Based on the same technical concept, an embodiment of the present application also provides a device, which includes: a data acquisition device, a processor and a memory; the data acquisition device is used to collect data; the memory is used to store one or more program instructions; the processor is used to execute one or more program instructions to execute the described method.

[0130] Based on the same technical concept, an embodiment of the present application further provides a computer-readable storage medium, wherein the computer storage medium contains one or more program instructions, and the one or more program instructions are used to execute the described method.

[0131] In this specification, each embodiment of the above method is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. For relevant parts, refer to the partial description of the method embodiment.

[0132] It should be noted that, although the operations of the method of the present invention are described in a specific order in the drawings, this does not require or imply that the operations must be performed in the specific order, or that all the operations shown must be performed to achieve the desired results. Additionally or alternatively, some steps may be omitted, multiple steps may be combined into one step, and / or one step may be decomposed into multiple steps.

[0133] Although the present application provides method operation steps such as embodiments or flow charts, more or less operation steps may be included based on conventional or non-creative means. The order of steps listed in the embodiment is only one way of executing the order of many steps and does not represent a unique execution order. When the device or client product in practice is executed, it can be executed in sequence or in parallel according to the method shown in the embodiment or the accompanying drawings (for example, a parallel processor or a multi-threaded processing environment, or even a distributed data processing environment). The term "includes", "comprising" or any other variant thereof is intended to cover non-exclusive inclusion, so that the process, method, product or equipment including a series of elements includes not only those elements, but also includes other elements that are not explicitly listed, or also includes elements inherent to such process, method, product or equipment. In the absence of more restrictions, it is not excluded that there are other identical or equivalent elements in the process, method, product or equipment including the elements.

[0134] The units, devices or modules described in the above embodiments can be implemented by computer chips or entities, or by products with certain functions. For the convenience of description, the above devices are described separately by functions divided into various modules. Of course, when implementing this application, the functions of each module can be implemented in the same or more software and / or hardware, or the modules that implement the same function can be implemented by a combination of multiple sub-modules or sub-units. The device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the coupling or direct coupling or communication connection between each other shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0135] Those skilled in the art also know that, in addition to implementing the controller in a purely computer-readable program code, the controller can be made to implement the same function in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, such a controller can be considered as a hardware component, and the devices for implementing various functions included therein can also be considered as structures within the hardware component. Or even, the devices for implementing various functions can be considered as both software modules for implementing the method and structures within the hardware component.

[0136] The present application may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, classes, etc. that perform specific tasks or implement specific abstract data types. The present application may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.

[0137] It can be known from the description of the above implementation methods that those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform. Based on such an understanding, the technical solution of the present application can be essentially or partly contributed to the prior art in the form of a software product, which can be stored in a storage medium such as ROM / RAM, a magnetic disk, an optical disk, etc., and includes several instructions for enabling a computer device (which can be a personal computer, a mobile terminal, a server, or a network device, etc.) to execute the methods described in the various embodiments of the present application or certain parts of the embodiments.

[0138] The various embodiments in this specification are described in a progressive manner, and the same or similar parts between the various embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. The present application can be used in many general or special computer system environments or configurations. For example: personal computers, server computers, handheld devices or portable devices, tablet devices, multi-processor systems, microprocessor-based systems, set-top boxes, programmable electronic devices, network PCs, minicomputers, mainframe computers, distributed computing environments including any of the above systems or devices, etc.

[0139] The specific embodiments described above further illustrate the purpose, technical solutions and beneficial effects of the present application. It should be understood that the above description is only a specific embodiment of the present application and is not intended to limit the scope of protection of the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application should be included in the scope of protection of the present application.

Claims

1. A table line positioning method, characterized in that: The method comprises: Use a matrix to store grayscale table images; Distinguish the background and content in the grayscale table image based on cosine similarity to obtain a content line set; Calculate the interval set of adjacent content lines according to the content line set; Determine the position of a table line in the interval set based on a threshold value to obtain a table line position set, wherein the table line is used to separate contents of different rows and columns in the table; The background and content in the grayscale table image are distinguished based on cosine similarity to obtain a content line set, including: Calculate the cosine similarity of each line in the grayscale table image with all parallel lines in the image, and sum up to obtain the total cosine similarity of the line; the line includes horizontal lines and vertical lines; sort the total cosine similarities of all lines, and record the horizontal lines and vertical lines with the largest total cosine similarity as background lines; the background lines include background horizontal lines and background vertical lines; count the lines whose cosine similarity with the background lines is lower than a set threshold into the content line set; the content lines include content horizontal lines and content vertical lines; the content horizontal lines in the set are arranged in the order of the horizontal lines in the image from top to bottom, and the content vertical lines are arranged in the order of the vertical lines in the image from left to right.

2. The method according to claim 1, characterized in that Calculate the cosine similarity of each line in the grayscale table image with all parallel lines in the image, including: Perform matrix multiplication on the matrix and its transposed matrix to obtain a matrix multiplication result with a size of L×L; According to the calculation method of cosine similarity, the two matrices are operated modulo, and the modulus of each column of the matrix and the modulus of each row of its transposed matrix are calculated, and matrices of size L×1 and 1×L are obtained respectively. The two matrices are multiplied to obtain a matrix storing the results of the modulo operation, which is of size L×L. Divide the matrix multiplication result by the corresponding position of the matrix storing the modular operation result to obtain a matrix of cosine similarity between each line and L lines in the grayscale table image, with a size of L×L.

3. The method according to claim 1, characterized in that After calculating the interval set of adjacent content lines according to the content line set, the method further includes: Filters out the values ​​that are not in the set range in an interval collection and sorts the elements of the interval collection in ascending order.

4. The method according to claim 1, characterized in that The table line position is determined based on the threshold in the interval set to obtain a table line position set, including: Determine whether the interval between adjacent content lines is greater than a set interval line threshold; If so, add the table line in the middle of the interval between adjacent content lines to the table line position set.

5. The method according to claim 4, characterized in that The method further comprises: According to the positions of the table line elements in the table line position set, the table lines are presented on the grayscale table image respectively, and the table lines include table horizontal lines and table vertical lines.

6. The method according to claim 4, characterized in that If the adaptive method is selected to set the interval line threshold, the method includes: Arrange all content lines in ascending order and calculate the set of intervals of all adjacent content lines; Deleting values ​​that are not within a set range from the interval set to obtain a filtered content line interval set; The value of the set quantile in the content line interval set is used as the table line threshold; The middle of two adjacent content lines whose interval exceeds the table line threshold is separated by a table line, and the position of the table line is added to the table line position set.

7. A table line positioning system, characterized in that: The system comprises: A matrix storage module, used to store grayscale table images using a matrix; The content line set calculation module is used to calculate the cosine similarity of each line in the grayscale table image with all parallel lines in the image, and sum up to obtain the total cosine similarity of the line; the line includes horizontal lines and vertical lines; the total cosine similarity of all lines is sorted, and the horizontal lines and vertical lines with the largest total cosine similarity are recorded as background lines; the background lines include background horizontal lines and background vertical lines; the lines whose cosine similarity with the background lines is lower than a set threshold are counted into the content line set; the content lines include content horizontal lines and content vertical lines; the content horizontal lines in the set are arranged in the order of the horizontal lines in the image from top to bottom, and the content vertical lines are arranged in the order of the vertical lines in the image from left to right; A content line interval calculation module, used to calculate an interval set of adjacent content lines according to a content line set; The table line determination module is used to determine the table line position in the interval set based on the threshold value to obtain a table line position set, wherein the table line is used to separate the contents of different rows and columns in the table.

8. An electronic device, comprising: A memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the method according to any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and the computer-readable instructions can be executed by a processor to implement the method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Method and apparatus for recognizing boundary line in an image information

    CN101246549A

  • Form line identification method and device

    CN109858468A

  • Form recognition method and device based on contour extraction, equipment and storage medium

    CN110263682A

  • Picture table recognition method and device, electronic equipment and storage medium

    CN111860502A

  • Table information extraction method and device, equipment and storage medium

    CN113408323A