Table image cell row and column information indexing method, computer device and storage medium
By identifying the coordinates of the four vertices of a cell in a table image, generating sets of coordinates for horizontal and vertical lines, and setting dynamic thresholds, the problem of difficulty in merging cell indexes in existing technologies is solved, achieving efficient cell information acquisition and table recognition.
Patent Information
- Application Number
- CN202211603819.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-14
- Publication Date
- 2026-01-06
- Estimated Expiration
- 2042-12-14
AI Technical Summary
Existing table recognition algorithms cannot effectively reflect merged cells during the table detection and recognition process, making it difficult to obtain cell information, which affects user experience and program development efficiency.
By identifying the coordinates of the four vertices of a cell in a table image, a set of coordinates for horizontal and vertical lines is generated. A dynamic threshold is set to determine the row and column indices of the cells. Image connectivity analysis and deduplication are then used to improve cell recognition accuracy.
It achieves accurate indexing of merged cells, improves the accuracy and efficiency of table recognition, and simplifies the process of obtaining cell information.
Smart Images

Figure CN116071774B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, specifically to a method for indexing row and column information of table image cells, a computer device using the method, and a computer-readable storage medium using the method. Background Technology
[0002] Tables are common objects in various documents, and their structured organization facilitates information understanding and extraction. Tables can be categorized based on the presence or absence of borders, such as bordered tables, tables with few borders, and tables without borders. Table styles are complex and diverse, including background filling, lighting and shadows, and merged rows and columns. In the era of big data, there are numerous spreadsheet image documents. Applying table recognition technology can reduce table processing time, making table recognition an important research topic in the field of document understanding. Most tables contain merged cells. In some tables, due to a narrow column and a cell's content being much longer than other cells in the column, the cell needs to wrap, requiring multiple rows to display the content. Current table recognition algorithms, after detecting a table, simply use simple indexing or complex sequence labels, failing to reflect merged cells. For tables with multiple rows or columns of merged cells, or tables without table borders, the labeling is particularly chaotic, making it difficult for users or subsequent program developers to directly access table cell information, impacting user experience and program development efficiency. Therefore, a more optimized cell indexing calculation method is needed. Summary of the Invention
[0003] The primary objective of this invention is to provide a table image cell row and column information indexing method that can divide cells into specific rows and columns and covers more comprehensive index information.
[0004] A second objective of this invention is to provide a computer device that can divide cells into specific rows and columns, thus covering more comprehensive index information.
[0005] A third objective of this invention is to provide a computer-readable storage medium that can divide cells into specific rows and columns and covers more comprehensive index information.
[0006] To achieve the aforementioned first objective, the table image cell row and column information indexing method provided by the present invention includes: identifying all cells in the table image and obtaining the coordinates of the four vertices of each cell; generating a set of coordinates for the top horizontal line representing the top horizontal line of the cell, a set of coordinates for the bottom horizontal line representing the bottom horizontal line of the cell, a set of coordinates for the left vertical line representing the left vertical line of the cell, and a set of coordinates for the right vertical line representing the right vertical line of the cell, based on the coordinates of the four vertices of all cells; determining the dynamic threshold of the cell based on the length of the left or right vertical line of each cell, and determining the column dynamic threshold of the cell based on the length of the top or bottom horizontal line of each cell; and sequentially indexing the top horizontal line coordinates of each cell with the top horizontal line coordinates in the set of top horizontal line coordinates. The coordinates are subtracted, and the upper horizontal line corresponding to the row starting index of the cell is obtained when the absolute value of the difference is less than the row dynamic threshold. The lower horizontal line coordinate of each cell is subtracted from the lower horizontal line coordinates in the lower horizontal line coordinate set, and the lower horizontal line corresponding to the row ending index of the cell is obtained when the absolute value of the difference is less than the row dynamic threshold. The left vertical line coordinate of each cell is subtracted from the left vertical line coordinates in the left vertical line coordinate set, and the left vertical line corresponding to the column starting index of the cell is obtained when the absolute value of the difference is less than the column dynamic threshold. The right vertical line coordinate of each cell is subtracted from the right vertical line coordinates in the right vertical line coordinate set, and the right vertical line corresponding to the column ending index of the cell is obtained when the absolute value of the difference is less than the column dynamic threshold.
[0007] As can be seen from the above scheme, the table image cell row and column information indexing method of the present invention determines the row and column index information of the cell by setting a dynamic threshold based on the width and height of the cell after recognizing all cells in the table image. This avoids missing row and column information by setting a fixed threshold, effectively divides the specific row and column to which the cell belongs, covers more comprehensive index information, has less computation, simple logic, and is more convenient to implement.
[0008] In a further scheme, the steps of generating sets of coordinates representing the top horizontal line, the bottom horizontal line, the left vertical line, and the right vertical line based on the coordinates of the four vertices of all cells include: performing cluster analysis on the x-coordinates of the top left vertices of all cells to obtain the left vertical line coordinates of each left vertical line in the table, sorting them in ascending order of coordinate values to obtain the set of left vertical line coordinates; performing cluster analysis on the x-coordinates of the top right vertices of all cells to obtain the right vertical line coordinates of each right vertical line in the table, sorting them in ascending order of coordinate values to obtain the set of right vertical line coordinates; performing cluster analysis on the y-coordinates of the top left vertices of all cells to obtain the top horizontal line coordinates of each top horizontal line in the table, sorting them in ascending order of coordinate values to obtain the set of top horizontal line coordinates; and performing cluster analysis on the y-coordinates of the bottom left vertices of all cells to obtain the bottom horizontal line coordinates of each bottom horizontal line in the table, sorting them in ascending order of coordinate values to obtain the set of bottom horizontal line coordinates representing the bottom horizontal line of the cells.
[0009] Therefore, by performing cluster analysis on the coordinates and sorting them in ascending order of coordinate values, the number of horizontal and vertical lines in the table can be determined, which facilitates the subsequent confirmation of the row and column indices of the cells.
[0010] In a further embodiment, the step of determining the dynamic threshold of a cell based on the length of its left or right vertical line includes: if half the length of the left or right vertical line of the cell is within a first preset range, then half the length of the left or right vertical line of the cell is used as the dynamic threshold; if half the length of the left or right vertical line of the cell is greater than the upper limit of the first preset range, then the upper limit of the first preset range is used as the dynamic threshold; if half the length of the left or right vertical line of the cell is less than the lower limit of the first preset range, then the lower limit of the first preset range is used as the dynamic threshold.
[0011] Therefore, by judging the length of half the left or right vertical line of the cell by the first preset range, the row dynamic threshold can be determined, which can avoid the problem of the row dynamic threshold being too large or too small and improve the accuracy of the row index in the cell.
[0012] In a further embodiment, the step of determining the column dynamic threshold of a cell based on the length of the top or bottom horizontal line of each cell includes: if half the length of the top or bottom horizontal line of the cell is within a second preset range, then half the length of the top or bottom horizontal line of the cell is used as the column dynamic threshold; if half the length of the top or bottom horizontal line of the cell is greater than the upper limit of the second preset range, then the upper limit of the second preset range is used as the column dynamic threshold; if half the length of the top or bottom horizontal line of the cell is less than the lower limit of the second preset range, then the lower limit of the second preset range is used as the column dynamic threshold.
[0013] Therefore, by judging the length of half the top or bottom horizontal line of the cell by the second preset range, the column dynamic threshold can be determined, which can avoid the problem of the column dynamic threshold being too large or too small and improve the accuracy of the column index in the cell.
[0014] In a further proposed approach, the steps for identifying all cells in a table image include: identifying all table lines in the table image; and using image connectivity analysis to divide each cell.
[0015] Therefore, it can be seen that dividing the table image into individual cells by using image connectivity analysis can improve the speed of table recognition.
[0016] In a further scheme, after the step of identifying all table lines in the table image, the scheme also includes: deduplicating all table lines.
[0017] Therefore, in order to avoid recognizing one line as multiple lines in the image recognition, it is necessary to deduplicate all table lines to improve the recognition accuracy of the table.
[0018] In a further proposed solution, the steps for deduplicating all table lines include: if the distance between any two horizontal lines is less than a preset distance, then the two horizontal lines are merged into one horizontal line; if the distance between any two vertical lines is less than a preset distance, then the two vertical lines are merged into one vertical line.
[0019] Therefore, it can be seen that by judging whether the distance between two lines is less than a preset distance, it can be determined whether the two lines overlap.
[0020] In a further proposed solution, before the step of identifying all cells in the table image, the solution includes: performing angle recognition on the table image and correcting the image angle.
[0021] Therefore, since there may be issues with the angle when acquiring table images, angle recognition and image angle correction of table images can be beneficial for subsequent table recognition.
[0022] To achieve the second objective of the present invention, the present invention provides a computer device including a processor and a memory, the memory storing a computer program, which, when executed by the processor, implements the steps of the above-described table image cell row and column information indexing method.
[0023] To achieve the third objective of the present invention, the present invention provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a controller, implements the steps of the above-described table image cell row and column information indexing method. Attached Figure Description
[0024] Figure 1 This is a flowchart of an embodiment of the table image cell row and column information indexing method of the present invention.
[0025] The present invention will be further described below with reference to the accompanying drawings and embodiments. Detailed Implementation
[0026] Example of a table image cell row and column information indexing method:
[0027] The table image cell row and column information indexing method of the present invention is an application program used in a computer device to identify cells in a table image and obtain the row and column index information of the cells.
[0028] like Figure 1 As shown, the table image cell row and column information indexing method of the present invention first performs step S1 to identify the angle of the table image and correct the image angle. Since the input table image may be rotated, for example by 90 degrees, 180 degrees, or 270 degrees, there will be an issue of incorrect angle, which will make it difficult to obtain or lead to errors in the subsequent table coordinates. Therefore, it is necessary to identify and correct the angle of the input table image, which is beneficial for the subsequent table recognition. Angle identification and rotation correction of images are techniques known to those skilled in the art and will not be described in detail here.
[0029] After image angle correction, step S2 is executed to identify all cells in the table image and obtain the coordinates of the four vertices of each cell. To establish the index information of the cells in the table, it is necessary to first identify the cells in the table image. In this embodiment, the step of identifying all cells in the table image includes: identifying all table lines in the table image; and using image connected component analysis to divide each cell. When identifying all table lines in the table image, a preset deep learning model is used to identify the table lines. The preset deep learning model uses a well-known deep learning model, which is a technique known to those skilled in the art and will not be described further here. After identifying all table lines in the table image, image connected component analysis is used, employing image methods such as dilation and erosion to mark the connected components of the table image, obtaining all connected components. Based on the coordinates of the pixels in each connected component, the head and tail coordinates of the four line segments in the smallest rectangle matching each connected component are obtained, and further, the coordinates of the four vertices of each connected component corresponding to the cell are obtained, thus obtaining the coordinates of the four vertices of each cell and dividing each cell. When determining the coordinates of the four vertices of each cell, the top-left corner of the table image is taken as the origin. The horizontal coordinate values gradually increase along the right side of the table image, and the vertical coordinate values gradually increase along the bottom side. Using image connectivity analysis to divide the cells is a technique well-known to those skilled in the art and will not be elaborated upon here.
[0030] Among the identified lines, some may be short or have small spacing, interfering with cell recognition. Therefore, line filtering is necessary. To avoid misidentifying a single line as multiple lines, this embodiment, after identifying all table lines in the table image, further includes deduplication of all table lines. Deduplication improves the accuracy of table recognition. The deduplication process includes merging any two horizontal lines into one if the distance between them is less than a preset distance; similarly, merging any two vertical lines into one if the distance between them is less than a preset distance. The preset distance is set based on experimental data or manually. Furthermore, to avoid identifying short lines, this embodiment, after identifying all table lines in the table image, also includes deleting lines shorter than a preset length. The preset length can be set based on experimental data. The distance between lines and the length of a line can be obtained from the line's coordinates, a technique known to those skilled in the art and will not be elaborated upon here.
[0031] After obtaining the coordinates of the four vertices of each cell, step S3 is executed. Based on the coordinates of the four vertices of all cells, a set of coordinates representing the top horizontal line, the bottom horizontal line, the left vertical line, and the right vertical line is generated. The coordinates of the top horizontal line are sorted in ascending order, as are the coordinates of the bottom horizontal line, left vertical line, and right vertical line. After obtaining the coordinates of each cell, the starting and ending row and column of each cell need to be determined. Therefore, the row and column indices of the cells are determined by combining the sorting of the line segments in the horizontal and vertical line sets.
[0032] In this embodiment, the steps of generating sets of coordinates for the top horizontal line (representing the top line of a cell), the bottom horizontal line (representing the bottom line of a cell), the left vertical line (representing the left vertical line of a cell), and the right vertical line (representing the right vertical line of a cell) based on the coordinates of the four vertices of all cells include: performing cluster analysis on the x-coordinates of the top left vertices of all cells to obtain the left vertical line coordinates of each left vertical line in the table, sorting them in ascending order of coordinate values to obtain the set of left vertical line coordinates; performing cluster analysis on the x-coordinates of the top right vertices of all cells to obtain the right vertical line coordinates of each right vertical line in the table, sorting them in ascending order of coordinate values to obtain the set of right vertical line coordinates; performing cluster analysis on the y-coordinates of the top left vertices of all cells to obtain the top horizontal line coordinates of each top horizontal line in the table, sorting them in ascending order of coordinate values to obtain the set of top horizontal line coordinates; and performing cluster analysis on the y-coordinates of the bottom left vertices of all cells to obtain the bottom horizontal line coordinates of each bottom horizontal line in the table, sorting them in ascending order of coordinate values to obtain the set of bottom horizontal line coordinates. The x-coordinate of the top-left vertex of a cell represents the left vertical line of that cell; the x-coordinate of the top-right vertex of a cell represents the right vertical line of that cell; the y-coordinate of the top-left vertex of a cell represents the top horizontal line of that cell; and the y-coordinate of the bottom-left vertex of a cell represents the bottom horizontal line of that cell.
[0033] For a table, the bottom horizontal line of the current cell and the top horizontal line of the next cell in the row below are considered to be the same horizontal line, and the right vertical line of the current cell and the left vertical line of the next cell in the column below are considered to be the same vertical line. However, when identifying cells using the connected component method, there may be cases where the coordinate values of the same line are not equal in different cells, even after line deduplication. In addition, the top horizontal lines of all cells in the same row are the same horizontal line, and the bottom horizontal lines of all cells are also the same horizontal line. The left vertical lines of all cells in the same column are the same horizontal line, and the right vertical lines of all cells are also the same horizontal line. Therefore, further classification and filtering are needed to determine the final number of left vertical lines, right vertical lines, top horizontal lines, and bottom horizontal lines in the table.
[0034] Cluster analysis can determine the final number of left, right, top, and bottom horizontal lines in a table, as well as the coordinates representing these lines. For example, in a table, taking the coordinates of the left vertical line as an example, the x-coordinates of the top-left vertex of all cells include the following values (10, 11, 12, 30, 33, 40, 42). During cluster analysis, "10, 11, 12" are grouped together, representing the first line. The left vertical lines are grouped together: "30, 33" represent the second left vertical line, and "40, 42" represent the third left vertical line. Thus, the table has three left vertical lines. Each left vertical line uses the average of all coordinates in its category as its coordinate value. Arranging the three left vertical lines in ascending order of coordinate values yields the set of left vertical line coordinates (11, 31.5, 41). Similarly, the sets of right vertical line coordinates, upper horizontal line coordinates, and lower horizontal line coordinates can be obtained.
[0035] To ensure the consistency of coordinates for the same line within the coordinate sets of the top horizontal line, bottom horizontal line, left vertical line, and right vertical line, after obtaining these sets, the coordinate values of the bottom horizontal line of the current cell and the top horizontal line of the cell in the next row adjacent to the current cell are averaged. Similarly, the coordinate values of the right vertical line of the current cell and the left vertical line of the cell in the next column adjacent to the current cell are averaged. This process corrects the coordinate sets of the top horizontal line, bottom horizontal line, left vertical line, and right vertical line. For example, the second coordinate value of the upper horizontal line coordinate set and the first coordinate value of the lower horizontal line coordinate set represent the same horizontal line; the third coordinate value of the upper horizontal line coordinate set and the second coordinate value of the lower horizontal line coordinate set represent the same horizontal line, and so on. Therefore, by averaging the second coordinate value of the upper horizontal line coordinate set and the first coordinate value of the lower horizontal line coordinate set, and replacing the corresponding second coordinate value of the upper horizontal line coordinate set and the first coordinate value of the lower horizontal line coordinate set with the average value, the coordinates of the same horizontal line in the upper horizontal line coordinate set and the lower horizontal line coordinate set are unified.
[0036] After obtaining the coordinate sets of the top horizontal line, bottom horizontal line, left vertical line, and right vertical line, step S4 is executed. The dynamic threshold of each cell is determined based on the length of its left or right vertical line, and the column dynamic threshold is determined based on the length of its top or bottom horizontal line. To determine the starting and ending rows and columns of each cell, row and column dynamic thresholds are set. Since cell sizes vary in different images, determining the dynamic threshold of a cell based on the length of its left or right vertical line and the column dynamic threshold based on the length of its top or bottom horizontal line can accommodate tables of various sizes, without limiting the pixels of the input table image. This avoids mismatches between fixed thresholds and cell sizes, preventing the omission of row and column information.
[0037] In this embodiment, the step of determining the dynamic threshold of a cell based on the length of its left or right vertical line includes: if half the length of the left or right vertical line of the cell is within a first preset range, then half the length of the left or right vertical line of the cell is used as the row dynamic threshold; if half the length of the left or right vertical line of the cell is greater than the upper limit of the first preset range, then the upper limit of the first preset range is used as the row dynamic threshold; if half the length of the left or right vertical line of the cell is less than the lower limit of the first preset range, then the lower limit of the first preset range is used as the row dynamic threshold. The upper limit of the first preset range is the distance between two adjacent vertical lines in the table, and the lower limit of the first preset range is preset based on experimental data. Preferably, the lower limit of the first preset range can be set as a preset distance in the line deduplication step. For example, starting from the top-left vertex and moving clockwise, the coordinates of the four vertices of a cell are (x1, y1), (x2, y1), (x2, y2), and (x1, y2). The length of the left vertical line or half of the left vertical line is taken as 0.5(y2-y1). The first preset range is 5 to 20. If 0.5(y2-y1) is within the preset range, then 0.5(y2-y1) is used as the row dynamic threshold. If 0.5(y2-y1) is less than 5, then the row dynamic threshold is 5. If 0.5(y2-y1) is greater than 20, then the row dynamic threshold is 20. By judging the length of half of the left or right vertical line of the cell within the first preset range to determine the row dynamic threshold, the problem of the row dynamic threshold being too large or too small can be avoided, improving the accuracy of the row index in the cell. If the row dynamic threshold is too large, if the table height is too small, more cells will be covered when calculating the subtraction. If the row dynamic threshold is too small, there may not be any suitable cells.
[0038] In this embodiment, the step of determining the column dynamic threshold of a cell based on the length of its top or bottom horizontal line includes: if half the length of the cell's top or bottom horizontal line is within a second preset range, then half the length of the cell's top or bottom horizontal line is used as the column dynamic threshold; if half the length of the cell's top or bottom horizontal line is greater than the upper limit of the second preset range, then the upper limit of the second preset range is used as the column dynamic threshold; if half the length of the cell's top or bottom horizontal line is less than the lower limit of the second preset range, then the lower limit of the second preset range is used as the column dynamic threshold. The upper limit of the second preset range is the distance between two adjacent horizontal lines in the table, and the lower limit of the second preset range is preset based on experimental data. Preferably, the lower limit of the second preset range can be set as the preset distance in the line deduplication step. For example, starting from the top left vertex and moving clockwise, the coordinates of the four vertices of a cell are (x1, y1), (x2, y1), (x2, y2), and (x1, y2). The length of half the top or bottom horizontal line is taken as 0.5(x2-x1). The second preset range is 5 to 30. If 0.5(x2-x1) falls within the second preset range, it is used as the column dynamic threshold. If 0.5(x2-x1) is less than 5, the column dynamic threshold is 5. If 0.5(x2-x1) is greater than 30, the column dynamic threshold is 30. By determining the column dynamic threshold based on half the length of the top or bottom horizontal line within the second preset range, the problem of an excessively large or small column dynamic threshold can be avoided, improving the accuracy of column indexing within the cell.
[0039] After obtaining the row dynamic threshold and column dynamic threshold, proceed to step S5. For each cell, subtract the coordinates of the top horizontal line from the coordinates of the top horizontal line in the set of top horizontal line coordinates. Use the top horizontal line corresponding to the point where the absolute value of the difference is less than the row dynamic threshold as the row start index of that cell. Similarly, subtract the coordinates of the bottom horizontal line from the coordinates of the bottom horizontal line in the set of bottom horizontal line coordinates. Use the bottom horizontal line corresponding to the point where the absolute value of the difference is less than the row dynamic threshold as the row end index of that cell. Likewise, subtract the coordinates of the left vertical line from the coordinates of the left vertical line in the set of left vertical line coordinates. Use the left vertical line corresponding to the point where the absolute value of the difference is less than the column dynamic threshold as the column start index of that cell. Finally, subtract the coordinates of the right vertical line from the coordinates of the right vertical line in the set of right vertical line coordinates. Use the right vertical line corresponding to the point where the absolute value of the difference is less than the column dynamic threshold as the column end index of that cell. After obtaining the row and column dynamic thresholds, iterate through each cell, subtracting the coordinates of the top horizontal line from the coordinates of the top horizontal line in the set of top horizontal line coordinates to obtain the absolute value of the difference. The top horizontal line corresponding to the row dynamic threshold whose absolute value of the difference is less than the absolute value of the difference is used as the row start index of the cell. Subtracting the coordinates of the bottom horizontal line from the coordinates of the bottom horizontal line in the set of bottom horizontal line coordinates to obtain the absolute value of the difference is used as the row end index of the cell. Subtracting the coordinates of the left vertical line from the coordinates of the left vertical line in the set of left vertical line coordinates to obtain the absolute value of the difference is used as the column start index of the cell. Subtracting the coordinates of the right vertical line from the coordinates of the right vertical line in the set of right vertical line coordinates to obtain the absolute value of the difference is used as the column end index of the cell.For example, in a table, taking rows as an example, the coordinate set of the top horizontal line is [42, 105, 168, 231], and the coordinate set of the bottom horizontal line is [105, 168, 231, 288]. The preset range for the row dynamic threshold is 5 to 63. The coordinates of the four vertices of the cell whose row and column indices need to be determined are: (x1=166, y1=42), (x2=282, y1=42), (x2=282, y2=169), (x1=166, y2=169). At this time, the row dynamic threshold is calculated as 0.5(y2-y1) = 60. The row dynamic threshold is less than 63, therefore, the row dynamic threshold is set to 60. Then, y1 is sequentially compared with the coordinates of the top horizontal line in the top horizontal line coordinate set. Subtracting the coordinates, we find the upper horizontal line coordinate in the set of upper horizontal line coordinates corresponding to the row dynamic threshold value that must be less than the absolute value of the difference. The absolute value of the difference between y1 and the first position in the upper horizontal line coordinate set is 0, which is less than the row dynamic threshold of 60. Therefore, the row starting index is "1". Subtracting y1 from the lower horizontal line coordinates in the set of lower horizontal line coordinates, we find the lower horizontal line coordinate in the set of lower horizontal line coordinates corresponding to the row dynamic threshold value that must be less than the absolute value of the difference. The absolute value of the difference between y2 and the second position in the lower horizontal line coordinate set is 2, which is less than the row dynamic threshold of 60. Therefore, the row ending index is "2". Thus, we obtain the row index information [1,2] of this cell, which represents the merged first and second row cells. The column index information is obtained in the same way and will not be described in detail here.
[0040] After obtaining the row and column index information of all cells, the row and column index information of the cells in the table image can be output for subsequent applications.
[0041] As can be seen from the above, the table image cell row and column information indexing method of the present invention determines the row and column index information of the cell by setting a dynamic threshold based on the width and height of the cell after recognizing all cells in the table image. This avoids missing row and column information by setting a fixed threshold, effectively divides the specific row and column to which the cell belongs, covers more comprehensive information, requires less computation, has simple logic, and is more convenient to implement.
[0042] Computer device embodiment:
[0043] The computer device in this embodiment includes a controller, which executes a computer program to implement the steps in the above embodiment of the table image cell row and column information indexing method.
[0044] For example, a computer program can be divided into one or more modules, one or more of which are stored in memory and executed by a controller to perform the present invention. One or more modules can be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program in a computer device.
[0045] A computer device may include, but is not limited to, a controller and memory. Those skilled in the art will understand that a computer device may include more or fewer components, or a combination of certain components, or different components; for example, a computer device may also include input / output devices, network access devices, buses, etc.
[0046] For example, a controller can be a Central Processing Unit (CPU), or other general-purpose controllers, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose controller can be a microcontroller or any conventional controller. The controller is the control center of a computer device, connecting all parts of the computer device through various interfaces and lines.
[0047] The memory can be used to store computer programs and / or modules. The controller implements various functions of the computer device by running or executing the computer programs and / or modules stored in the memory, and by accessing data stored in the memory. For example, the memory may mainly include a program storage area and a data storage area. The program storage area may store the operating system, at least one application program required for a function (such as sound receiving function, sound-to-text function, etc.), etc.; the data storage area may store data created based on the use of the mobile phone (such as audio data, text data, etc.). In addition, the memory may include high-speed random access memory, and may also include non-volatile memory, such as hard disk, RAM, plug-in hard disk, SmartMediaCard (SMC), Secure Digital (SD) card, FlashCard, at least one disk storage device, flash memory device, or other volatile solid-state storage device.
[0048] Examples of computer-readable storage media:
[0049] If the modules integrated into the computer device in the above embodiments are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above embodiments of the table image cell row and column information indexing method can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a controller, it can implement the steps of the above embodiments of the table image cell row and column information indexing method. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The storage medium can include: any entity or device capable of carrying computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content contained in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, the computer-readable medium does not include electrical carrier signals and telecommunication signals.
[0050] It should be noted that the above are only preferred embodiments of the present invention, but the design concept of the invention is not limited thereto. Any non-substantial modifications made to the present invention using this concept also fall within the protection scope of the present invention.
Claims
1. A table image cell row-column information indexing method, characterized by, The method comprises the following steps: identifying all cells in a table image and obtaining coordinates of four vertices of each cell; generating a set of upper horizontal line coordinates representing upper horizontal lines of the cells, a set of lower horizontal line coordinates representing lower horizontal lines of the cells, a set of left vertical line coordinates representing left vertical lines of the cells and a set of right vertical line coordinates representing right vertical lines of the cells according to the coordinates of the four vertices of all the cells; determining a row dynamic threshold of each cell according to the length of the left vertical line or the right vertical line of the cell and determining a column dynamic threshold of each cell according to the length of the upper horizontal line or the lower horizontal line of the cell; subtracting the upper horizontal line coordinates of each cell from the upper horizontal line coordinates in the set of upper horizontal line coordinates in sequence to obtain the upper horizontal line corresponding to the row dynamic threshold with an absolute value less than the row dynamic threshold as the row start index of the cell, subtracting the lower horizontal line coordinates of each cell from the lower horizontal line coordinates in the set of lower horizontal line coordinates in sequence to obtain the lower horizontal line corresponding to the row dynamic threshold with an absolute value less than the row dynamic threshold as the row end index of the cell, subtracting the left vertical line coordinates of each cell from the left vertical line coordinates in the set of left vertical line coordinates in sequence to obtain the left vertical line corresponding to the column dynamic threshold with an absolute value less than the column dynamic threshold as the column start index of the cell, and subtracting the right vertical line coordinates of each cell from the right vertical line coordinates in the set of right vertical line coordinates in sequence to obtain the right vertical line corresponding to the column dynamic threshold with an absolute value less than the column dynamic threshold as the column end index of the cell; wherein the step of determining the row dynamic threshold of each cell according to the length of the left vertical line or the right vertical line of the cell comprises the following steps: if the half length of the left vertical line or the right vertical line of the cell is within a first preset range, taking the half length of the left vertical line or the right vertical line of the cell as the row dynamic threshold; if the half length of the left vertical line or the right vertical line of the cell is greater than the upper limit value of the first preset range, taking the upper limit value of the first preset range as the row dynamic threshold; if the half length of the left vertical line or the right vertical line of the cell is less than the lower limit value of the first preset range, taking the lower limit value of the first preset range as the row dynamic threshold.
2. The table image cell row and column information indexing method according to claim 1, wherein the step of generating a set of upper horizontal line coordinates representing upper horizontal lines of the cells, a set of lower horizontal line coordinates representing lower horizontal lines of the cells, a set of left vertical line coordinates representing left vertical lines of the cells and a set of right vertical line coordinates representing right vertical lines of the cells according to the coordinates of the four vertices of all the cells comprises the following steps: The horizontal coordinates of the top-left vertices of all the cells are subjected to cluster analysis to obtain the left vertical line coordinates of each left vertical line in the table, and the left vertical line coordinates are sorted in ascending order of coordinate values to obtain the left vertical line coordinate set; the horizontal coordinates of the top-right vertices of all the cells are subjected to cluster analysis to obtain the right vertical line coordinates of each right vertical line in the table, and the right vertical line coordinates are sorted in ascending order of coordinate values to obtain the right vertical line coordinate set; the vertical coordinates of the top-left vertices of all the cells are subjected to cluster analysis to obtain the upper horizontal line coordinates of each upper horizontal line in the table, and the upper horizontal line coordinates are sorted in ascending order of coordinate values to obtain the upper horizontal line coordinate set; and the vertical coordinates of the bottom-left vertices of all the cells are subjected to cluster analysis to obtain the lower horizontal line coordinates of each lower horizontal line in the table, and the lower horizontal line coordinates are sorted in ascending order of coordinate values to obtain the lower horizontal line coordinate set.
3. The table image cell row and column information indexing method according to claim 1, characterized in that: the step of determining the column dynamic threshold of each cell according to the length of the upper horizontal line or the lower horizontal line of the cell comprises: if the half length of the upper horizontal line or the lower horizontal line of the cell is within a second preset range, the half length of the upper horizontal line or the lower horizontal line of the cell is taken as the column dynamic threshold; if the half length of the upper horizontal line or the lower horizontal line of the cell is greater than the upper limit value of the second preset range, the upper limit value of the second preset range is taken as the column dynamic threshold; if the half length of the upper horizontal line or the lower horizontal line of the cell is less than the lower limit value of the second preset range, the lower limit value of the second preset range is taken as the column dynamic threshold.
4. The table image cell row and column information indexing method according to any one of claims 1 to 3, characterized in that: the step of identifying all the cells in the table image comprises: identifying all the table lines in the table image; dividing each cell by using an image connected region analysis method.
5. The table image cell row and column information indexing method according to claim 4, characterized in that: after the step of identifying all the table lines in the table image, the method further comprises: performing a deduplication processing on all the table lines.
6. The table image cell row and column information indexing method according to claim 5, characterized in that: the step of performing a deduplication processing on all the table lines comprises: if the distance between any two horizontal lines is less than a preset distance, the two horizontal lines are merged into one horizontal line; if the distance between any two vertical lines is less than a preset distance, the two vertical lines are merged into one vertical line.
7. The table image cell row and column information indexing method according to any one of claims 1 to 3, characterized in that: before the step of identifying all the cells in the table image, the method further comprises: performing an angle identification on the table image, and performing an image angle correction.
8. A computer apparatus comprising a processor and a memory, characterized in that: The memory stores a computer program, and the computer program is executed by the processor to implement the steps of the table image cell row and column information indexing method according to any one of claims 1 to 7.
9. A computer readable storage medium having stored thereon a computer program, characterized in that: The computer program is executed by the controller to implement the steps of the table image cell row and column information indexing method according to any one of claims 1 to 7.
Citation Information
Patent Citations
Table extraction method and table extraction system
CN114663897A
Table structure identification method and device for three-line table and storage medium
CN115439866A