A table image processing method, device, equipment and medium
By identifying and filtering horizontal and vertical lines in table images, and establishing cell mapping relationships, the problem of difficult information extraction caused by merging cells in image tables is solved, and accurate extraction of object information in tables is achieved.
Patent Information
- Application Number
- CN202411099505.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-12
- Publication Date
- 2024-10-15
- Estimated Expiration
- 2044-08-12
AI Technical Summary
In scenarios where the table is in the form of an image, especially when cells are merged in the table, how to accurately extract the complete information of each object from the table in the image form is an urgent problem to be solved.
By identifying the horizontal and vertical lines in the target table image, filter and extend the corresponding lines to determine the initial and target cells, and establish the corresponding mapping relationship, thereby determining the output information corresponding to each row of cells, and solving the problem of merging cells Problem of dividing into multiple target cells.
It is achieved that even when cells are merged, the complete information of the object corresponding to each row of cells can be accurately obtained, which solves the problem of difficulty in extracting information from image tables.
Smart Images

Figure CN118629060B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of graphic data reading technology, and in particular to a table image processing method, device, equipment and medium. Background Art
[0002] Tables are a relatively common way to express information, and tables often include several rows and columns. In common tables, different rows correspond to different objects, and different columns correspond to information of different dimensions of the objects. For example, a table is an equipment list, in which different rows correspond to different equipment, and different columns correspond to information of different dimensions of the equipment. For example, the table includes 4 columns, the first column is the name of the equipment, the second column is the model of the equipment, the third column is the supplier of the equipment, and the fourth column is the quantity of the equipment.
[0003] For scenarios where the table is in image format, especially when cells are merged in the table (for example, devices in multiple adjacent rows in the equipment list correspond to the same supplier, and the cells of the device supplier corresponding to the devices in the multiple adjacent rows are merged into a larger cell), how to accurately extract the complete information of each object from the table in image format is an urgent problem to be solved. Summary of the invention
[0004] The object of the present invention is to provide a method, device, equipment and medium for processing table images, so as to accurately extract complete information of each object from a table in image form.
[0005] According to a first aspect of the present invention, a method for processing a table image is provided, the processing method comprising the following steps:
[0006] Identify all horizontal and vertical lines in the target table image.
[0007] All horizontal lines and all vertical lines in the target table image are screened according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold.
[0008] An initial cell of the target table image is determined according to the filtered horizontal and vertical lines of the target table image, and a first mapping relationship between the initial cell and the text in the target table image is established.
[0009] The target table image is horizontally extended to obtain a target table image after horizontal extension processing; the horizontal extension processing includes: if a filtered horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then the filtered horizontal line is extended to the left boundary line and the right boundary line of the target table image.
[0010] A target cell of the target table image after the horizontal extension process is acquired, and a second mapping relationship between the target cell and the initial cell is established according to the coordinate position relationship between the target cell and the initial cell.
[0011] A third mapping relationship between the target cell and the text in the target table image is determined according to the first mapping relationship and the second mapping relationship.
[0012] The output information corresponding to each row of cells of the target table image after the horizontal extension process is determined according to the third mapping relationship.
[0013] Furthermore, the process of acquiring the target table image includes:
[0014] Get the text box corresponding to the text in the target image.
[0015] The table boundary line of the target image is determined based on the topmost, leftmost, bottommost and rightmost text boxes in the text box.
[0016] The text box corresponding to the text in the target image is divided into several columns of text boxes.
[0017] Get the horizontal dividing line between the upper and lower adjacent text boxes in each column of text boxes; the horizontal dividing line distance is equal to the vertical distance between the two corresponding text boxes, the horizontal dividing line extends to the left to the left boundary line of the table of the target image, and the horizontal dividing line extends to the right to the right boundary line of the table of the target image.
[0018] The horizontal dividing line is deleted; the deletion process includes: if a horizontal dividing line passes through a text box, the part of the horizontal dividing line located in the target column corresponding to the horizontal dividing line is deleted; the target column corresponding to the horizontal dividing line is the column where the text box passed by the horizontal dividing line is located.
[0019] The horizontal dividing lines are merged; the merging process includes: if there is no text box between the two horizontal dividing lines, the two horizontal dividing lines are merged into one horizontal dividing line.
[0020] A table image composed of a table boundary line, a middle vertical line and a horizontal dividing line is determined as a target table image; the middle vertical line is a dividing line between left and right adjacent column text boxes.
[0021] Furthermore, dividing the text box corresponding to the text in the target image into a plurality of columns of text boxes includes:
[0022] Get the horizontal coordinate of the center of each text box.
[0023] The text boxes are clustered according to the horizontal coordinate of the center of each text box.
[0024] The text boxes of the same type obtained through clustering are determined as the text boxes of the same column.
[0025] Furthermore, clustering the text boxes according to the horizontal coordinate of the center of each text box includes:
[0026] Get the number of text boxes to which the even-numbered rows of pixels in the target image belong.
[0027] The maximum value of the number of text boxes to which all even-numbered row pixels of the target image belong is determined as the target number.
[0028] Select the target number of text boxes to be determined as initial clustering text boxes, and the vertical coordinates corresponding to any two initial clustering text boxes do not overlap.
[0029] The distance between the text boxes corresponding to the text in the target image and each initial clustering text box except the initial clustering text box is obtained; the distance between two text boxes is the absolute value of the difference between the horizontal coordinates of the centers of the two text boxes.
[0030] Each text box except the initial clustering text box in the text boxes corresponding to the text in the target image is assigned to the nearest initial clustering text box.
[0031] Update the cluster center until the preset stop updating condition is met.
[0032] Further, the determining of a third mapping relationship between the target cell and the text in the target table image according to the first mapping relationship and the second mapping relationship includes:
[0033] An initial cell having a second mapping relationship with a first target cell is determined as a first initial cell; the first target cell is a target cell of the target table image after being horizontally extended.
[0034] The text of the target table image having a first mapping relationship with the first initial cell is determined as the first text.
[0035] It is determined that a third mapping relationship exists between the first text and the first target cell.
[0036] According to a second aspect of the present invention, there is provided a table image processing device, the processing device comprising:
[0037] The recognition module is used to recognize all horizontal and vertical lines in the target table image.
[0038] A screening module is used to screen all horizontal lines and all vertical lines in a target table image according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold.
[0039] The first mapping relationship establishing module is used to determine the initial cell of the target table image according to the filtered horizontal and vertical lines of the target table image, and establish a first mapping relationship between the initial cell and the text in the target table image.
[0040] The horizontal extension processing module is used to perform horizontal extension processing on the target table image to obtain the target table image after horizontal extension processing; the horizontal extension processing includes: if a filtered horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then the filtered horizontal line is extended to the left boundary line and the right boundary line of the target table image.
[0041] The second mapping relationship establishing module is used to obtain the target cell of the target table image after the horizontal extension processing, and establish a second mapping relationship between the target cell and the initial cell according to the coordinate position relationship between the target cell and the initial cell.
[0042] The third mapping relationship establishing module is used to determine a third mapping relationship between the target cell and the text in the target table image according to the first mapping relationship and the second mapping relationship.
[0043] The information output module is used to determine the output information corresponding to each row of cells of the target table image after the horizontal extension processing according to the third mapping relationship.
[0044] Furthermore, the processing device further includes a module for acquiring a target table image, and the module for acquiring a target table image includes:
[0045] The first acquisition module is used to acquire the text box corresponding to the text in the target image.
[0046] The boundary line determination module is used to determine the table boundary line of the target image according to the topmost, leftmost, bottommost and rightmost text boxes in the text box.
[0047] The column division module is used to divide the text box corresponding to the text in the target image into several columns of text boxes.
[0048] The second acquisition module is used to obtain the horizontal dividing line between the upper and lower adjacent text boxes in each column of text boxes; the horizontal dividing line distance is equal to the vertical distance between the two corresponding text boxes, the horizontal dividing line extends to the left to the left boundary line of the table of the target image, and the horizontal dividing line extends to the right to the right boundary line of the table of the target image.
[0049] The deletion processing module is used to perform deletion processing on the horizontal dividing line; the deletion processing includes: if a horizontal dividing line passes through a text box, the part of the horizontal dividing line located in the target column corresponding to the horizontal dividing line is deleted; the target column corresponding to the horizontal dividing line is the column where the text box passed by the horizontal dividing line is located.
[0050] The merging processing module is used to merge the horizontal dividing lines; the merging processing includes: if there is no text box between the two horizontal dividing lines, then the two horizontal dividing lines are merged into one horizontal dividing line.
[0051] The target table image determination module is used to determine the table image composed of the table boundary line, the middle vertical line and the horizontal dividing line as the target table image; the middle vertical line is the dividing line between the column text boxes adjacent to the left and right.
[0052] Furthermore, the column partitioning module includes:
[0053] The third acquisition module is used to acquire the horizontal coordinate of the center of each text box.
[0054] The clustering module is used to cluster the text boxes according to the horizontal coordinate of the center of each text box.
[0055] The same column text box determination module is used to determine the same type of text boxes obtained by clustering as the same column of text boxes.
[0056] Furthermore, the clustering module includes:
[0057] The fourth acquisition module is used to obtain the number of text boxes to which the even-numbered rows of pixels in the target image belong.
[0058] The target number determination module is used to determine the maximum number of text boxes to which all even-numbered rows of pixel points of the target image belong as the target number.
[0059] The selection module is used to select a target number of text boxes as initial clustering text boxes, and the vertical coordinates corresponding to any two initial clustering text boxes do not overlap.
[0060] The fifth acquisition module is used to obtain the distance between the text boxes corresponding to the text in the target image except the initial clustering text box and each initial clustering text box; the distance between two text boxes is the absolute value of the difference between the horizontal coordinates of the centers of the two text boxes.
[0061] The allocation module is used to allocate each text box except the initial clustering text box in the text boxes corresponding to the text in the target image to the nearest initial clustering text box.
[0062] The updating module is used to update the cluster center until the preset stop updating condition is met.
[0063] Furthermore, the third mapping relationship establishing module includes:
[0064] The first initial cell determination module is used to determine an initial cell having a second mapping relationship with a first target cell as a first initial cell; the first target cell is a target cell of the target table image after horizontal extension processing.
[0065] The first text determination module is used to determine the text of the target table image having a first mapping relationship with the first initial cell as the first text.
[0066] The third mapping relationship determining module is used to determine whether a third mapping relationship exists between the first text and the first target cell.
[0067] According to a third aspect of the present invention, there is provided an electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned method for processing table images when executing the computer program.
[0068] According to a fourth aspect of the present invention, there is provided a computer-readable storage medium storing a computer program, wherein the computer program implements the above-mentioned table image processing method when executed by a processor.
[0069] Compared with the prior art, the present invention has at least the following beneficial effects:
[0070] The present invention first obtains the initial cell in the target table image by identifying the horizontal lines and vertical lines in the target table image, and establishes a first mapping relationship between the initial cell and the text in the target table image; and then obtains the target cell by extending the filtered horizontal lines in the target table image; if an initial cell is not a merged cell type, then the initial cell corresponds to 1 target cell; if an initial cell is a merged cell type, then the initial cell corresponds to at least 2 target cells; the present invention determines the second mapping relationship between the target cell and the initial cell based on the coordinate position relationship between the target cell and the initial cell, and establishes a third mapping relationship between the target cell and the text in the target table image in combination with the first mapping relationship, thereby, even if the initial cell of the merged cell type in the target table image is divided into multiple target cells by horizontally extended horizontal lines, and some of the multiple target cells are empty cells or cells with incomplete text, the complete text information corresponding to the above-mentioned empty cells or cells with incomplete text can be determined according to the established third mapping relationship between the target cell and the text of the target table image, and then the complete information of the object corresponding to each row of cells can be obtained. The present invention can solve the problem of difficulty in extracting information when a table is in image form and cells are merged in the table, and can accurately extract complete information of each object from the table in image form. BRIEF DESCRIPTION OF THE DRAWINGS
[0071] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0072] Figure 1 A flowchart of a method for processing a table image provided in Embodiment 1 of the present invention;
[0073] Figure 2 A flowchart of a process for acquiring a target table image provided in the first embodiment of the present invention;
[0074] Figure 3 A flowchart of the steps of dividing a text box corresponding to text in a target image into a plurality of columns of text boxes provided in the first embodiment of the present invention;
[0075] Figure 4 A first flow chart of the step of clustering text boxes according to the horizontal coordinate of the center of each text box provided in the first embodiment of the present invention;
[0076] Figure 5A second flow chart of the step of clustering text boxes according to the horizontal coordinate of the center of each text box provided in the first embodiment of the present invention;
[0077] Figure 6 A flowchart of the steps of determining a third mapping relationship between a target cell and text in a target table image according to the first mapping relationship and the second mapping relationship provided in the first embodiment of the present invention;
[0078] Figure 7 A schematic diagram of a table image processing device provided in Embodiment 2 of the present invention;
[0079] Figure 8 A schematic diagram of a module for acquiring a target table image provided in Embodiment 2 of the present invention;
[0080] Fig. 9 A schematic diagram of a column division module provided in Embodiment 2 of the present invention;
[0081] Fig.10 This is a first schematic diagram of a clustering module provided in Embodiment 2 of the present invention;
[0082] Fig.11 A second schematic diagram of a clustering module provided in the second embodiment of the present invention;
[0083] Fig.12 This is a schematic diagram of a third mapping relationship establishing module provided in Embodiment 2 of the present invention. DETAILED DESCRIPTION
[0084] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only 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 those skilled in the art without creative work are within the scope of protection of the present invention.
[0085] Embodiment 1:
[0086] According to this embodiment, Figure 1 As shown, a method for processing a table image is provided, the method comprising the following steps:
[0087] S100, identifying all horizontal and vertical lines in the target table image.
[0088] In this embodiment, the target table image is an image of a table. The target table image includes only one table. The table includes several rows and several columns. Different rows correspond to different objects. Different columns correspond to information of different dimensions of the object. The text in the cell of the table is located in a relatively centered position in the cell. The table in the target table image may have merged cells.
[0089] Those skilled in the art know that any method of obtaining horizontal and vertical lines in an image in the prior art falls within the protection scope of the present invention. Optionally, the Hough detection method is used to identify straight lines in the image, and the straight lines parallel to the horizontal axis of the image are determined as horizontal lines, and the straight lines parallel to the vertical axis of the image are determined as vertical lines.
[0090] As an optional specific implementation, the target table image is directly acquired.
[0091] As an optional specific implementation, the target table image is obtained based on the text in the target image. The target image does not display a table, but the text in the target image is laid out in the form of a table, which still conforms to the feature that different rows represent different objects and different columns represent different dimensional information of the object. As a preferred specific implementation, Figure 2 As shown, the process of acquiring the target table image includes:
[0092] S010, obtaining a text box corresponding to the text in the target image.
[0093] Those skilled in the art know that any method of obtaining a text box corresponding to a text in an image in the prior art falls within the protection scope of the present invention. Optionally, a trained neural network model is used to recognize text in an image and annotate a text box corresponding to the text.
[0094] S020, determining the table boundary line of the target image according to the topmost, leftmost, bottommost and rightmost text boxes in the text boxes.
[0095] In this embodiment, the upper boundary line of the table of the target image is determined according to the topmost text box in the text box, the left boundary line of the table of the target image is determined according to the leftmost text box in the text box, the lower boundary line of the table of the target image is determined according to the bottommost text box in the text box, and the right boundary line of the table of the target image is determined according to the rightmost text box in the text box.
[0096] As an optional specific implementation, the upper border line of the topmost text box in the text box is translated upward by a preset distance to mark the position where the upper border line of the table passes; the left border line of the leftmost text box in the text box is translated to the left by a preset distance to mark the position where the left border line of the table passes; the lower border line of the bottommost text box in the text box is translated downward by a preset distance to mark the position where the lower border line of the table passes; the right border line of the rightmost text box in the text box is translated to the right by a preset distance to mark the position where the right border line of the table passes.
[0097] S030, dividing the text box corresponding to the text in the target image into a plurality of columns of text boxes.
[0098] In this embodiment, the difference in the horizontal coordinates of the text boxes in the same column of the table is small, and the difference in the horizontal coordinates of the text boxes in different columns of the table is large; as a preferred specific implementation, Figure 3 As shown, S030 includes:
[0099] S031, obtaining the horizontal coordinate of the center of each text box.
[0100] In this embodiment, the average value of the horizontal coordinates of the pixels included in each text box is determined as the horizontal coordinate of the center of the corresponding text box.
[0101] S032: Cluster the text boxes according to the horizontal coordinate of the center of each text box.
[0102] In this embodiment, the text boxes with smaller differences in the horizontal coordinates of the corresponding centers are determined as one category, and the text boxes with larger differences in the horizontal coordinates of the corresponding centers are determined as different categories; as a preferred specific implementation, Figure 4 As shown, S032 includes:
[0103] S0321, obtaining the number of text boxes to which the even-numbered rows of pixels in the target image belong.
[0104] In this embodiment, the number of text boxes to which each even-numbered row of pixels in the target image belongs is obtained. For example, if the pixels of an even-numbered row of the target image are pixels in three text boxes respectively, then the number of text boxes to which the even-numbered row belongs is three. For another example, if the pixels of an even-numbered row of the target image are pixels in four text boxes respectively, then the number of text boxes to which the even-numbered row belongs is four.
[0105] S0322, determining the maximum value of the number of text boxes to which all even-numbered rows of pixels of the target image belong as the target number.
[0106] In the present embodiment, the maximum value of the number of text boxes to which all even-numbered row pixels of the target image belong is determined as the target number. Compared with obtaining the number of text boxes to which all row pixels of the target image belong and determining the maximum value of the number of text boxes to which all row pixels of the target image belong as the target number, the process of only obtaining the number of text boxes to which even-numbered row pixels belong in the present embodiment has less workload and can ultimately obtain the same target number, thereby improving the accuracy of the preliminary estimation of the number of table columns.
[0107] S0323, selecting a target number of text boxes to be determined as initial clustering text boxes, and the vertical coordinates corresponding to any two initial clustering text boxes do not overlap.
[0108] In this embodiment, the k-means clustering method is used to cluster the text boxes, the value of k is determined as the target number, and when the initial clustering text boxes are selected, it is necessary to ensure that the vertical coordinates corresponding to any two initial clustering text boxes do not overlap. Compared with arbitrarily selecting a target number of text boxes as the initial clustering text boxes, the initial clustering text boxes selected in this embodiment are likely to belong to different columns, which is conducive to reducing the number of subsequent update iterations, speeding up the clustering process, and obtaining more accurate clustering results.
[0109] S0324, obtaining the distance between each initial clustering text box and the text boxes corresponding to the text in the target image except the initial clustering text box; the distance between two text boxes is the absolute value of the difference between the horizontal coordinates of the centers of the two text boxes.
[0110] S0325, assigning each text box except the initial clustering text box in the text boxes corresponding to the text in the target image to the nearest initial clustering text box.
[0111] S0326, updating the cluster center until a preset stop updating condition is met.
[0112] In this embodiment, the center of each type of text box is the mean value of the horizontal coordinates of the centers of the text boxes of that type.
[0113] Optionally, the preset stop updating condition is that the number of updates reaches a preset number or the cluster center no longer changes.
[0114] As an optional specific implementation, the clustering result of S0326 is used as a basis for dividing the text box into columns, and the number of columns is equal to the target number.
[0115] As a preferred specific implementation, after S0326, S032 further includes the following steps: Figure 5 As shown:
[0116] S0327, obtaining the variance of the horizontal coordinate of the center of each type of text box.
[0117] In this embodiment, the variance of the horizontal coordinate of the center of a certain type of text box is the variance of the horizontal coordinate of the center of each text box in the type of text box. The process of obtaining the variance is a prior art and will not be repeated here.
[0118] S0328: If the variance of the horizontal coordinates of the centers of any type of text boxes is less than or equal to a preset variance threshold, the clustering result when the number of clusters is the target number is determined as the final clustering result.
[0119] In this embodiment, the preset variance threshold is an empirical value. If the variance of the horizontal coordinate of the center of any type of text box is less than or equal to the preset variance threshold, it is determined that each type of text box does not contain text boxes in other columns. In this case, the clustering result when the number of clusters is the target number is determined as the final clustering result.
[0120] In this embodiment, if the variance of the horizontal coordinates of the centers of a certain type of text boxes in the clustering results is greater than a preset variance threshold, it is determined that the text boxes in this type contain text boxes of other columns; in this embodiment, the target number is less than or equal to the actual number of columns in the table, if the variance of the horizontal coordinates of the centers of a certain type of text boxes is greater than the preset variance threshold, the clustering result when the number of clusters is the target number plus 1 is obtained; if the variance of the horizontal coordinates of the centers of any type of text boxes in the clustering results when the number of clusters is the target number plus 1 is less than or equal to the preset variance threshold, the clustering result when the number of clusters is the target number plus 1 is determined as the final clustering result; otherwise, the clustering result when the number of clusters is the target number plus 2 is obtained; and so on, until the variance of the horizontal coordinates of the centers of any type of text boxes in the newly obtained clustering results is less than or equal to the preset variance threshold, and the clustering result corresponding to the new number of clusters is determined as the final clustering result.
[0121] Based on the above preferred specific implementation manner, the exact number of columns can be determined and the text boxes can be accurately classified.
[0122] S033, determining the text boxes of the same type obtained by clustering as text boxes of the same column.
[0123] In this embodiment, each category of text boxes is sorted according to the size of the mean horizontal coordinate of the center of the text boxes corresponding to each category, wherein the text boxes included in the category with the smallest mean horizontal coordinate are the text boxes in the first column, the text boxes included in the category with the second smallest mean horizontal coordinate are the text boxes in the second column, and so on.
[0124] S040, obtaining the horizontal dividing line between the upper and lower adjacent text boxes in each column of text boxes; the horizontal dividing line distance is equal to the vertical distance between the two corresponding text boxes, the horizontal dividing line extends to the left to the left boundary line of the table of the target image, and the horizontal dividing line extends to the right to the right boundary line of the table of the target image.
[0125] In this embodiment, for any column of text boxes, a horizontal dividing line between upper and lower adjacent text boxes in the column of text boxes is obtained; there is a probability that the horizontal dividing line passes through text boxes in other columns.
[0126] S050, deleting the horizontal dividing line; the deleting process includes: if a horizontal dividing line passes through a text box, deleting the part of the horizontal dividing line located in the target column corresponding to the horizontal dividing line; the target column corresponding to the horizontal dividing line is the column where the text box passed by the horizontal dividing line is located.
[0127] In this embodiment, a certain horizontal dividing line may not pass through any text box, may only pass through one text box, or may pass through more than two text boxes; if a certain horizontal dividing line passes through a text box, the portion of the horizontal dividing line located in the column where the text box passed by the horizontal dividing line is located is deleted. Thus, after the deletion process, the horizontal dividing line no longer passes through any text box.
[0128] S060, merging the horizontal dividing lines; the merging process includes: if there is no text box between the two horizontal dividing lines, merging the two horizontal dividing lines into one horizontal dividing line.
[0129] As an optional specific implementation, if the lengths of the two horizontal dividing lines that need to be merged are equal, the equidistant horizontal dividing lines of the two horizontal dividing lines that need to be merged will be used as the corresponding horizontal dividing lines after the merger, and the length of the merged horizontal dividing line is equal to the length of the two horizontal dividing lines that need to be merged. The equidistant dividing lines of the two horizontal dividing lines refer to the horizontal dividing lines that are at the same distance from the two horizontal dividing lines; if the lengths of the two horizontal dividing lines that need to be merged are not equal, the horizontal dividing line with the longer length will be determined as the horizontal dividing line after the merger.
[0130] S070, determining a table image composed of a table boundary line, a middle vertical line and a horizontal dividing line as a target table image; the middle vertical line is a dividing line between left and right adjacent column text boxes.
[0131] In this embodiment, the dividing line between the left and right adjacent column text boxes does not pass through any text box in the left and right adjacent column text boxes.
[0132] Based on S010-S070, this embodiment implements the process of marking a table on the target image according to the position of the text in the target image, obtains an image with a table, and improves the readability of the target image.
[0133] S200, all horizontal lines and all vertical lines in the target table image are filtered according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain filtered horizontal lines and vertical lines of the target table image; the length of each of the filtered horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the filtered vertical lines is greater than or equal to the preset vertical line length threshold.
[0134] As an optional specific implementation, the preset horizontal line length threshold and the preset vertical line length threshold are both empirical values, and the horizontal lines and vertical lines filtered by the preset horizontal line length threshold and the preset vertical line length threshold are both part of the table.
[0135] S300, determining an initial cell of the target table image according to the filtered horizontal and vertical lines of the target table image, and establishing a first mapping relationship between the initial cell and the text in the target table image.
[0136] In this embodiment, if a certain text in the target image is located in a certain initial cell, it is determined that a first mapping relationship exists between the text and the initial cell.
[0137] In this embodiment, if there is no text in an initial cell, it is determined that the text having the first mapping relationship with the initial cell is empty text.
[0138] S400, performing horizontal extension processing on the target table image to obtain a target table image after horizontal extension processing; the horizontal extension processing includes: if a filtered horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then extending the filtered horizontal line to the left boundary line and the right boundary line of the target table image.
[0139] S500, acquiring a target cell of the target table image after the horizontal extension process, and establishing a second mapping relationship between the target cell and the initial cell according to the coordinate position relationship between the target cell and the initial cell.
[0140] In this embodiment, the cell in the target table image after the horizontal extension processing, that is, the target cell, is determined based on the horizontal lines and vertical lines in the target table image after the horizontal extension processing; if the coordinate position of a target cell is the same as that of an initial cell, or the target cell is only a part of the area corresponding to the initial cell, it is determined that there is a second mapping relationship between the target cell and the initial cell.
[0141] S600: Determine a third mapping relationship between a target cell and text in a target table image according to the first mapping relationship and the second mapping relationship.
[0142] As a specific implementation, Figure 6 As shown, S600 includes:
[0143] S610: Determine an initial cell having a second mapping relationship with a first target cell as a first initial cell; the first target cell is a target cell of the target table image after horizontal extension processing.
[0144] S620: Determine the text of the target table image having a first mapping relationship with the first initial cell as the first text.
[0145] S630: Determine whether a third mapping relationship exists between the first text and the first target cell.
[0146] Based on S610 - S630 , text having a third mapping relationship with each target unit may be acquired.
[0147] S700: Determine output information corresponding to each row of cells of the target table image after the horizontal extension process according to the third mapping relationship.
[0148] In this embodiment, for a row of cells in the target table image after horizontal extension processing, the corresponding output information includes text having a third mapping relationship with the target cells in each column included in the row of cells. Therefore, based on the output information corresponding to each row of cells in the target table image after horizontal extension processing, the information of each dimension of each object corresponding to each row of cells can be obtained.
[0149] This embodiment first obtains the initial cell in the target table image by identifying the horizontal and vertical lines in the target table image, and establishes a first mapping relationship between the initial cell and the text in the target table image; and then obtains the target cell by extending the filtered horizontal lines in the target table image; if an initial cell is not a merged cell type, then the initial cell corresponds to 1 target cell; if an initial cell is a merged cell type, then the initial cell corresponds to at least 2 target cells; this embodiment determines the second mapping relationship between the target cell and the initial cell based on the coordinate position relationship between the target cell and the initial cell, and establishes a third mapping relationship between the target cell and the text in the target table image in combination with the first mapping relationship, thereby, even if the initial cell of the merged cell type in the target table image is divided into multiple target cells by horizontal lines extending horizontally, and some of the multiple target cells are empty cells or cells with incomplete text, the complete text information corresponding to the above-mentioned empty cells or cells with incomplete text can be determined according to the established third mapping relationship between the target cell and the text of the target table image, and then the complete information of the object corresponding to each row of cells can be obtained. This embodiment can solve the problem of difficulty in extracting information when the table is in image form and cells are merged in the table, and can accurately extract complete information of each object from the table in image form.
[0150] Embodiment 2:
[0151] According to this embodiment, Figure 7 As shown, a table image processing device is provided, the processing device comprising:
[0152] The recognition module 100 is used to recognize all horizontal lines and vertical lines in the target table image.
[0153] In this embodiment, the target table image is an image of a table. The target table image includes only one table. The table includes several rows and several columns. Different rows correspond to different objects. Different columns correspond to information of different dimensions of the object. The text in the cell of the table is located in a relatively centered position in the cell. The table in the target table image may have merged cells.
[0154] Those skilled in the art know that any method of obtaining horizontal and vertical lines in an image in the prior art falls within the protection scope of the present invention. Optionally, the Hough detection method is used to identify straight lines in the image, and the straight lines parallel to the horizontal axis of the image are determined as horizontal lines, and the straight lines parallel to the vertical axis of the image are determined as vertical lines.
[0155] As an optional specific implementation, the target table image is directly acquired.
[0156] As an optional specific implementation, the target table image is obtained based on the text in the target image. The target image does not display a table, but the text in the target image is laid out in the form of a table, which still conforms to the feature that different rows represent different objects and different columns represent different dimensional information of the object. As a preferred specific implementation, the processing device further includes a module for acquiring the target table image, such as Figure 8 As shown, the target table image acquisition module includes:
[0157] The first acquisition module 010 is used to acquire a text box corresponding to the text in the target image.
[0158] Those skilled in the art know that any method of obtaining a text box corresponding to a text in an image in the prior art falls within the protection scope of the present invention. Optionally, a trained neural network model is used to recognize text in an image and annotate a text box corresponding to the text.
[0159] The boundary line determination module 020 is used to determine the table boundary line of the target image according to the topmost, leftmost, bottommost and rightmost text boxes in the text boxes.
[0160] In this embodiment, the upper boundary line of the table of the target image is determined according to the topmost text box in the text box, the left boundary line of the table of the target image is determined according to the leftmost text box in the text box, the lower boundary line of the table of the target image is determined according to the bottommost text box in the text box, and the right boundary line of the table of the target image is determined according to the rightmost text box in the text box.
[0161] As an optional specific implementation, the upper border line of the topmost text box in the text box is translated upward by a preset distance to mark the position where the upper border line of the table passes; the left border line of the leftmost text box in the text box is translated to the left by a preset distance to mark the position where the left border line of the table passes; the lower border line of the bottommost text box in the text box is translated downward by a preset distance to mark the position where the lower border line of the table passes; the right border line of the rightmost text box in the text box is translated to the right by a preset distance to mark the position where the right border line of the table passes.
[0162] The column division module 030 is used to divide the text box corresponding to the text in the target image into a plurality of columns of text boxes.
[0163] In this embodiment, the difference in the horizontal coordinates of the text boxes in the same column of the table is small, and the difference in the horizontal coordinates of the text boxes in different columns of the table is large; as a preferred specific implementation, Fig. 9 As shown, the column division module 030 includes:
[0164] The third acquisition module 031 is used to acquire the horizontal coordinate of the center of each text box.
[0165] In this embodiment, the average horizontal coordinate of the pixels included in each text box is determined as the horizontal coordinate of the center of the corresponding text box.
[0166] The clustering module 032 is used to cluster the text boxes according to the horizontal coordinate of the center of each text box.
[0167] In this embodiment, the text boxes with smaller differences in the horizontal coordinates of the corresponding centers are determined as one category, and the text boxes with larger differences in the horizontal coordinates of the corresponding centers are determined as different categories; as a preferred specific implementation, Fig.10 As shown, the clustering module 032 includes:
[0168] The fourth acquisition module 0321 is used to acquire the number of text boxes to which the even-numbered rows of pixels in the target image belong.
[0169] In this embodiment, the number of text boxes to which each even-numbered row of pixels in the target image belongs is obtained. For example, if the pixels of an even-numbered row of the target image are pixels in three text boxes respectively, then the number of text boxes to which the even-numbered row belongs is three. For another example, if the pixels of an even-numbered row of the target image are pixels in four text boxes respectively, then the number of text boxes to which the even-numbered row belongs is four.
[0170] The target number determination module 0322 is used to determine the maximum number of text boxes to which all even-numbered rows of pixels of the target image belong as the target number.
[0171] In the present embodiment, the maximum value of the number of text boxes to which all even-numbered row pixels of the target image belong is determined as the target number. Compared with obtaining the number of text boxes to which all row pixels of the target image belong and determining the maximum value of the number of text boxes to which all row pixels of the target image belong as the target number, the process of only obtaining the number of text boxes to which even-numbered row pixels belong in the present embodiment has less workload and can ultimately obtain the same target number, thereby improving the accuracy of the preliminary estimation of the number of table columns.
[0172] The selection module 0323 is used to select a target number of text boxes as initial clustering text boxes, and the vertical coordinates corresponding to any two initial clustering text boxes do not overlap.
[0173] In this embodiment, the k-means clustering method is used to cluster the text boxes, the value of k is determined as the target number, and when the initial clustering text boxes are selected, it is necessary to ensure that the vertical coordinates corresponding to any two initial clustering text boxes do not overlap. Compared with arbitrarily selecting a target number of text boxes as the initial clustering text boxes, the initial clustering text boxes selected in this embodiment are likely to belong to different columns, which is conducive to reducing the number of subsequent update iterations, speeding up the clustering process, and obtaining more accurate clustering results.
[0174] The fifth acquisition module 0324 is used to obtain the distance between the text boxes corresponding to the text in the target image except the initial clustering text box and each initial clustering text box; the distance between two text boxes is the absolute value of the difference between the horizontal coordinates of the centers of the two text boxes.
[0175] The allocation module 0325 is used to allocate each text box except the initial cluster text box in the text boxes corresponding to the text in the target image to the nearest initial cluster text box.
[0176] The updating module 0326 is used to update the cluster center until a preset stop updating condition is met.
[0177] In this embodiment, the center of each type of text box is the mean value of the horizontal coordinates of the centers of the text boxes of that type.
[0178] Optionally, the preset stop updating condition is that the number of updates reaches a preset number or the cluster center no longer changes.
[0179] As an optional specific implementation, the clustering result of the update module 0326 is used as the basis for dividing the text box into columns, and the number of columns is equal to the target number.
[0180] As a preferred specific embodiment, Fig.11 As shown, the clustering module 032 also includes:
[0181] The variance acquisition module 0327 is used to acquire the variance of the horizontal coordinate of the center of each type of text box.
[0182] In this embodiment, the variance of the horizontal coordinate of the center of a certain type of text box is the variance of the horizontal coordinate of the center of each text box in the type of text box. The process of obtaining the variance is a prior art and will not be repeated here.
[0183] The judgment module 0328 is used to determine the clustering result when the number of clusters is the target number as the final clustering result if the variance of the horizontal coordinates of the center of any type of text box is less than or equal to a preset variance threshold.
[0184] In this embodiment, the preset variance threshold is an empirical value. If the variance of the horizontal coordinate of the center of any type of text box is less than or equal to the preset variance threshold, it is determined that each type of text box does not contain text boxes in other columns. In this case, the clustering result when the number of clusters is the target number is determined as the final clustering result.
[0185] In this embodiment, the judgment module 0328 is also used to determine whether the text box of a certain type contains text boxes of other columns if the variance of the horizontal coordinates of the centers of a certain type of text boxes in the clustering results is greater than a preset variance threshold; in this embodiment, the target number is less than or equal to the number of actual columns of the table, and the judgment module 0328 is also used to obtain the clustering result when the number of clusters is the target number plus 1 if the variance of the horizontal coordinates of the centers of a certain type of text boxes is greater than the preset variance threshold; if the variance of the horizontal coordinates of the centers of any type of text boxes in the clustering results when the number of clusters is the target number plus 1 is less than or equal to the preset variance threshold, the clustering result when the number of clusters is the target number plus 1 is determined as the final clustering result; otherwise, the clustering result when the number of clusters is the target number plus 2 is obtained; and so on, until the variance of the horizontal coordinates of the centers of any type of text boxes in the newly obtained clustering results is less than or equal to the preset variance threshold, and the clustering result corresponding to the new number of clusters is determined as the final clustering result.
[0186] Based on the above preferred specific implementation manner, the exact number of columns can be determined and the text boxes can be accurately classified.
[0187] The same column text box determination module 033 is used to determine the same type of text boxes obtained through clustering as the same column of text boxes.
[0188] In this embodiment, each category of text boxes is sorted according to the size of the mean horizontal coordinate of the center of the text boxes corresponding to each category, wherein the text boxes included in the category with the smallest mean horizontal coordinate are the text boxes in the first column, the text boxes included in the category with the second smallest mean horizontal coordinate are the text boxes in the second column, and so on.
[0189] The second acquisition module 040 is used to obtain the horizontal dividing line between the upper and lower adjacent text boxes in each column of text boxes; the horizontal dividing line distance is equal to the vertical distance between the two corresponding text boxes, the horizontal dividing line extends to the left to the left boundary line of the table of the target image, and the horizontal dividing line extends to the right to the right boundary line of the table of the target image.
[0190] In this embodiment, for any column of text boxes, a horizontal dividing line between upper and lower adjacent text boxes in the column of text boxes is obtained; there is a probability that the horizontal dividing line passes through text boxes in other columns.
[0191] The deletion processing module 050 is used to perform deletion processing on the horizontal dividing line; the deletion processing includes: if a horizontal dividing line passes through a text box, the part of the horizontal dividing line located in the target column corresponding to the horizontal dividing line is deleted; the target column corresponding to the horizontal dividing line is the column where the text box passed by the horizontal dividing line is located.
[0192] In this embodiment, a certain horizontal dividing line may not pass through any text box, may only pass through one text box, or may pass through more than two text boxes; if a certain horizontal dividing line passes through a text box, the portion of the horizontal dividing line located in the column where the text box passed by the horizontal dividing line is located is deleted. Thus, after the deletion process, the horizontal dividing line no longer passes through any text box.
[0193] The merging processing module 060 is used to merge the horizontal dividing lines. The merging processing includes: if there is no text box between the two horizontal dividing lines, merging the two horizontal dividing lines into one horizontal dividing line.
[0194] As an optional specific implementation, if the lengths of the two horizontal dividing lines that need to be merged are equal, the equidistant horizontal dividing lines of the two horizontal dividing lines that need to be merged will be used as the corresponding horizontal dividing lines after the merger, and the length of the merged horizontal dividing line is equal to the length of the two horizontal dividing lines that need to be merged. The equidistant dividing lines of the two horizontal dividing lines refer to the horizontal dividing lines that are at the same distance from the two horizontal dividing lines; if the lengths of the two horizontal dividing lines that need to be merged are not equal, the horizontal dividing line with the longer length will be determined as the horizontal dividing line after the merger.
[0195] The target table image determination module 070 is used to determine the table image composed of the table boundary line, the middle vertical line and the horizontal dividing line as the target table image; the middle vertical line is the dividing line between the column text boxes adjacent to the left and right.
[0196] In this embodiment, the dividing line between the left and right adjacent column text boxes does not pass through any text box in the left and right adjacent column text boxes.
[0197] Based on all the modules included in the target table image acquisition module, this embodiment implements the process of marking the table on the target image according to the position of the text in the target image, obtains the image with the table, and improves the readability of the target image.
[0198] The screening module 200 is used to screen all horizontal lines and all vertical lines in the target table image according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain the screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold.
[0199] As an optional specific implementation, the preset horizontal line length threshold and the preset vertical line length threshold are both empirical values, and the horizontal lines and vertical lines filtered by the preset horizontal line length threshold and the preset vertical line length threshold are both part of the table.
[0200] The first mapping relationship establishing module 300 is used to determine the initial cell of the target table image according to the filtered horizontal and vertical lines of the target table image, and establish a first mapping relationship between the initial cell and the text in the target table image.
[0201] In this embodiment, if a certain text in the target image is located in a certain initial cell, it is determined that a first mapping relationship exists between the text and the initial cell.
[0202] In this embodiment, if there is no text in an initial cell, it is determined that the text having the first mapping relationship with the initial cell is empty text.
[0203] The horizontal extension processing module 400 is used to perform horizontal extension processing on the target table image to obtain the target table image after horizontal extension processing; the horizontal extension processing includes: if a filtered horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then the filtered horizontal line is extended to the left boundary line and the right boundary line of the target table image.
[0204] The second mapping relationship establishing module 500 is used to obtain the target cell of the target table image after the horizontal extension process, and establish a second mapping relationship between the target cell and the initial cell according to the coordinate position relationship between the target cell and the initial cell.
[0205] In this embodiment, if the coordinate position of a target cell is the same as that of an initial cell, or the target cell is only a part of the area corresponding to the initial cell, it is determined that there is a second mapping relationship between the target cell and the initial cell.
[0206] The third mapping relationship establishing module 600 is used to determine a third mapping relationship between the target cell and the text in the target table image according to the first mapping relationship and the second mapping relationship.
[0207] As a specific implementation, Fig.12 As shown, the third mapping relationship establishing module 600 includes:
[0208] The first initial cell determination module 610 is used to determine an initial cell having a second mapping relationship with a first target cell as a first initial cell; the first target cell is a target cell of the target table image after the horizontal extension process.
[0209] The first text determination module 620 is used to determine the text of the target table image having a first mapping relationship with the first initial cell as the first text.
[0210] The third mapping relationship determining module 630 is used to determine whether a third mapping relationship exists between the first text and the first target cell.
[0211] Based on all modules included in the third mapping relationship establishing module 600, text having a third mapping relationship with each target unit can be obtained.
[0212] The information output module 700 is used to determine the output information corresponding to each row of cells of the target table image after the horizontal extension processing according to the third mapping relationship.
[0213] In this embodiment, for a row of cells in the target table image after horizontal extension processing, the corresponding output information includes text having a third mapping relationship with the target cells in each column included in the row of cells. Therefore, based on the output information corresponding to each row of cells in the target table image after horizontal extension processing, the information of each dimension of each object corresponding to each row of cells can be obtained.
[0214] This embodiment first obtains the initial cell in the target table image by identifying the horizontal and vertical lines in the target table image, and establishes a first mapping relationship between the initial cell and the text in the target table image; and then obtains the target cell by extending the filtered horizontal lines in the target table image; if an initial cell is not a merged cell type, then the initial cell corresponds to 1 target cell; if an initial cell is a merged cell type, then the initial cell corresponds to at least 2 target cells; this embodiment determines the second mapping relationship between the target cell and the initial cell based on the coordinate position relationship between the target cell and the initial cell, and establishes a third mapping relationship between the target cell and the text in the target table image in combination with the first mapping relationship, thereby, even if the initial cell of the merged cell type in the target table image is divided into multiple target cells by horizontal lines extending horizontally, and some of the multiple target cells are empty cells or cells with incomplete text, the complete text information corresponding to the above-mentioned empty cells or cells with incomplete text can be determined according to the established third mapping relationship between the target cell and the text of the target table image, and then the complete information of the object corresponding to each row of cells can be obtained. This embodiment can solve the problem of difficulty in extracting information when the table is in image form and cells are merged in the table, and can accurately extract complete information of each object from the table in image form.
[0215] Embodiment three:
[0216] This embodiment provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, the following steps are implemented:
[0217] Identify all horizontal and vertical lines in the target table image.
[0218] All horizontal lines and all vertical lines in the target table image are screened according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold.
[0219] An initial cell of the target table image is determined according to the filtered horizontal and vertical lines of the target table image, and a first mapping relationship between the initial cell and the text in the target table image is established.
[0220] The target table image is horizontally extended to obtain a target table image after horizontal extension processing; the horizontal extension processing includes: if a filtered horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then the filtered horizontal line is extended to the left boundary line and the right boundary line of the target table image.
[0221] A target cell of the target table image after the horizontal extension process is acquired, and a second mapping relationship between the target cell and the initial cell is established according to the coordinate position relationship between the target cell and the initial cell.
[0222] A third mapping relationship between the target cell and the text in the target table image is determined according to the first mapping relationship and the second mapping relationship.
[0223] The output information corresponding to each row of cells of the target table image after the horizontal extension process is determined according to the third mapping relationship.
[0224] Embodiment 4:
[0225] This embodiment provides a computer-readable storage medium, on which a computer program is stored. When the computer program is executed by a processor, the following steps are implemented:
[0226] Identify all horizontal and vertical lines in the target table image.
[0227] All horizontal lines and all vertical lines in the target table image are screened according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold.
[0228] An initial cell of the target table image is determined according to the filtered horizontal and vertical lines of the target table image, and a first mapping relationship between the initial cell and the text in the target table image is established.
[0229] The target table image is horizontally extended to obtain a target table image after horizontal extension processing; the horizontal extension processing includes: if a filtered horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then the filtered horizontal line is extended to the left boundary line and the right boundary line of the target table image.
[0230] A target cell of the target table image after the horizontal extension process is acquired, and a second mapping relationship between the target cell and the initial cell is established according to the coordinate position relationship between the target cell and the initial cell.
[0231] A third mapping relationship between the target cell and the text in the target table image is determined according to the first mapping relationship and the second mapping relationship.
[0232] The output information corresponding to each row of cells of the target table image after the horizontal extension process is determined according to the third mapping relationship.
[0233] Those of ordinary skill in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be implemented by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in this application may include non-volatile and / or volatile memory. Non-volatile memory may include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory may include random access memory (RAM) or external cache memory. By way of illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM), etc.
[0234] Although some specific embodiments of the present invention have been described in detail by way of example, it will be appreciated by those skilled in the art that the above examples are for illustration only and are not intended to limit the scope of the present invention. It will also be appreciated by those skilled in the art that various modifications may be made to the embodiments without departing from the scope and spirit of the present invention. The scope of the present invention is defined by the appended claims.
Claims
1. A method for processing a table image, characterized in that: The processing method comprises the following steps: Identify all horizontal and vertical lines in the target table image; All horizontal lines and all vertical lines in the target table image are screened according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold; Determine an initial cell of the target table image according to the filtered horizontal and vertical lines of the target table image, and establish a first mapping relationship between the initial cell and the text in the target table image; Performing a horizontal extension process on the target table image to obtain a target table image after the horizontal extension process; the horizontal extension process includes: if a selected horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, extending the selected horizontal line to the left boundary line and the right boundary line of the target table image; Acquire a target cell of the target table image after the horizontal extension process, and establish a second mapping relationship between the target cell and the initial cell according to the coordinate position relationship between the target cell and the initial cell; Determine a third mapping relationship between the target cell and the text in the target table image according to the first mapping relationship and the second mapping relationship; The output information corresponding to each row of cells of the target table image after the horizontal extension process is determined according to the third mapping relationship.
2. The method for processing a table image according to claim 1, characterized in that: The process of acquiring the target table image includes: Get the text box corresponding to the text in the target image; Determine the table boundary line of the target image according to the topmost, leftmost, bottommost and rightmost text boxes in the text box; Divide the text box corresponding to the text in the target image into several columns of text boxes; Get the horizontal dividing line between the upper and lower adjacent text boxes in each column of text boxes; the horizontal dividing line is equal to the vertical distance between the two corresponding text boxes, the horizontal dividing line extends to the left to the left boundary line of the table of the target image, and the horizontal dividing line extends to the right to the right boundary line of the table of the target image; Deleting the horizontal dividing line; the deletion process includes: if a horizontal dividing line passes through a text box, deleting the part of the horizontal dividing line located in the target column corresponding to the horizontal dividing line; the target column corresponding to the horizontal dividing line is the column where the text box passed by the horizontal dividing line is located; Merging the horizontal dividing lines; the merging process includes: if there is no text box between the two horizontal dividing lines, merging the two horizontal dividing lines into one horizontal dividing line; A table image composed of a table boundary line, a middle vertical line and a horizontal dividing line is determined as a target table image; the middle vertical line is a dividing line between left and right adjacent column text boxes.
3. The method for processing a table image according to claim 2, characterized in that: The step of dividing the text box corresponding to the text in the target image into a plurality of columns of text boxes comprises: Get the horizontal coordinate of the center of each text box; Cluster the text boxes according to the horizontal coordinate of the center of each text box; The text boxes of the same type obtained through clustering are determined as the text boxes of the same column.
4. The method for processing a table image according to claim 3, characterized in that: The clustering of the text boxes according to the horizontal coordinate of the center of each text box comprises: Get the number of text boxes to which the even-numbered rows of pixels in the target image belong; The maximum value of the number of text boxes to which all even-numbered row pixels of the target image belong is determined as the target number; Select the target number of text boxes to be determined as the initial clustering text boxes, and the vertical coordinates corresponding to any two initial clustering text boxes do not overlap; Obtain the distance between the text boxes corresponding to the text in the target image and each initial clustering text box except the initial clustering text box; the distance between the two text boxes is the absolute value of the difference between the horizontal coordinates of the centers of the two text boxes; Assign each text box except the initial clustering text box among the text boxes corresponding to the text in the target image to the nearest initial clustering text box; Update the cluster center until the preset stop updating condition is met.
5. The method for processing a table image according to claim 1, characterized in that: Determining a third mapping relationship between the target cell and the text in the target table image according to the first mapping relationship and the second mapping relationship includes: An initial cell having a second mapping relationship with the first target cell is determined as a first initial cell; the first target cell is a target cell of the target table image after the horizontal extension process; Determine the text of the target table image having a first mapping relationship with the first initial cell as the first text; It is determined that a third mapping relationship exists between the first text and the first target cell.
6. A table image processing device, characterized in that: The processing device comprises: A recognition module, used for recognizing all horizontal and vertical lines in a target table image; A screening module, used for screening all horizontal lines and all vertical lines in the target table image according to a preset horizontal line length threshold and a preset vertical line length threshold, respectively, to obtain screened horizontal lines and vertical lines of the target table image; the length of each of the screened horizontal lines is greater than or equal to the preset horizontal line length threshold, and the length of each of the screened vertical lines is greater than or equal to the preset vertical line length threshold; A first mapping relationship establishing module, used to determine an initial cell of the target table image according to the filtered horizontal and vertical lines of the target table image, and establish a first mapping relationship between the initial cell and the text in the target table image; A horizontal extension processing module is used to perform horizontal extension processing on the target table image to obtain a target table image after horizontal extension processing; the horizontal extension processing includes: if a selected horizontal line of the target table image does not extend to the left boundary line or the right boundary line of the target table image, then the selected horizontal line is extended to the left boundary line and the right boundary line of the target table image; A second mapping relationship establishing module, used for acquiring a target cell of the target table image after the horizontal extension processing, and establishing a second mapping relationship between the target cell and the initial cell according to the coordinate position relationship between the target cell and the initial cell; A third mapping relationship establishing module, used to determine a third mapping relationship between the target cell and the text in the target table image according to the first mapping relationship and the second mapping relationship; The information output module is used to determine the output information corresponding to each row of cells of the target table image after the horizontal extension processing according to the third mapping relationship.
7. The table image processing device according to claim 6, characterized in that: The processing device further includes a target table image acquisition module, and the target table image acquisition module includes: A first acquisition module is used to acquire a text box corresponding to the text in the target image; A boundary line determination module is used to determine the table boundary line of the target image according to the topmost, leftmost, bottommost and rightmost text boxes in the text box; A column division module is used to divide the text box corresponding to the text in the target image into a plurality of columns of text boxes; The second acquisition module is used to acquire a horizontal dividing line between the upper and lower adjacent text boxes in each column of text boxes; the horizontal dividing line is equal to the vertical distance between the two corresponding text boxes, the horizontal dividing line extends to the left to the left boundary line of the table of the target image, and the horizontal dividing line extends to the right to the right boundary line of the table of the target image; The deletion processing module is used to perform deletion processing on the horizontal dividing line; the deletion processing includes: if a horizontal dividing line passes through a text box, then the part of the horizontal dividing line located in the target column corresponding to the horizontal dividing line is deleted; the target column corresponding to the horizontal dividing line is the column where the text box passed by the horizontal dividing line is located; A merging processing module is used to merge the horizontal dividing lines; the merging processing includes: if there is no text box between the two horizontal dividing lines, merging the two horizontal dividing lines into one horizontal dividing line; The target table image determination module is used to determine the table image composed of the table boundary line, the middle vertical line and the horizontal dividing line as the target table image; the middle vertical line is the dividing line between the column text boxes adjacent to the left and right.
8. The table image processing device according to claim 7, characterized in that: The column partitioning module includes: The third acquisition module is used to obtain the horizontal coordinate of the center of each text box; A clustering module, used for clustering text boxes according to the horizontal coordinate of the center of each text box; The same column text box determination module is used to determine the same type of text boxes obtained by clustering as the same column of text boxes.
9. The table image processing device according to claim 8, characterized in that: The clustering module includes: A fourth acquisition module is used to acquire the number of text boxes to which the even-numbered rows of pixels in the target image belong; A target number determination module, used to determine the maximum number of text boxes to which all even-numbered rows of pixel points of the target image belong as the target number; A selection module, used for selecting a target number of text boxes to be determined as initial clustering text boxes, and the vertical coordinates corresponding to any two initial clustering text boxes do not overlap; A fifth acquisition module is used to acquire the distance between the text boxes corresponding to the text in the target image and each initial clustering text box except the initial clustering text box; the distance between two text boxes is the absolute value of the difference between the horizontal coordinates of the centers of the two text boxes; An assignment module, used for assigning each text box except the initial clustering text box among the text boxes corresponding to the text in the target image to the nearest initial clustering text box; The updating module is used to update the cluster center until the preset stop updating condition is met.
10. The table image processing device according to claim 6, characterized in that: The third mapping relationship establishment module includes: A first initial cell determination module is used to determine an initial cell having a second mapping relationship with a first target cell as a first initial cell; the first target cell is a target cell of the target table image after the horizontal extension process; A first text determination module, used for determining the text of the target table image having a first mapping relationship with the first initial cell as the first text; The third mapping relationship determining module is used to determine whether a third mapping relationship exists between the first text and the first target cell.
11. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein: When the processor executes the computer program, the method for processing a table image according to any one of claims 1 to 5 is implemented.
12. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method for processing a table image according to any one of claims 1 to 5 is implemented.
