Method, device, equipment and storage medium for extracting incomplete framed forms
Through rasterization and hitting test combined with text box alignment, the problem of low accuracy of non-complete box line table recognition in PDF files is solved, and efficient extraction of non-complete box line tables is achieved.
Patent Information
- Application Number
- CN202310612931.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-05-26
- Publication Date
- 2025-08-19
- Estimated Expiration
- 2043-05-26
AI Technical Summary
In the prior art, the recognition accuracy of non-complete frame line tables in PDF files is low, and the machine automatically recognizes rows and lines that are difficult to accurately extract incomplete frame line tables.
By determining the table type based on the number of visible rows and column lines in the table area in the PDF file, the non-complete box line table is rastered into a grid cell, and a hit test is performed. Invisible rows and column lines are determined based on the alignment of the text box, and the non-complete box line table is extracted.
The recognition accuracy of incomplete framed tables is improved, and the efficiency and accuracy of the machine's automatic extraction of incomplete framed tables is achieved.
Smart Images

Figure CN116740742B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of document recognition, and in particular to a method, device, equipment and storage medium for extracting an incomplete framed table. Background Art
[0002] PDF (Portable Document Format) is one of the most widely used document formats. Its core advantage lies in its cross-platform nature and its ability to preserve the original formatting of files. With the advancement of document recognition technology, it is now possible to extract nearly all information, including text, images, formulas, and tables, from PDF files.
[0003] Tables in current PDFs typically combine lines with text and numbers, resulting in a more complex structure. Tables contained in PDF documents can generally be divided into two categories: complete outline tables and incomplete outline tables. Complete outline tables are simpler to recognize and can achieve higher accuracy. Incomplete outline tables, while rows and columns are visible to the naked eye due to the lack of outline constraints, automatic machine recognition still suffers from low accuracy. Summary of the Invention
[0004] The present invention provides a method, device, equipment and storage medium for extracting an incomplete frame line table, aiming to solve the problem of low accuracy in extracting an incomplete frame line table in a PDF file.
[0005] To achieve the above-mentioned object, the present invention provides a method for extracting an incomplete frame line table, the method being applied to an extraction device for an incomplete frame line table, the method comprising:
[0006] Determining the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete frame line table and an incomplete frame line table;
[0007] gridding the incomplete frame line table to obtain grid cells, performing a hit test on the grid cells, and determining candidate row and column lines of the grid cells based on the hit test results;
[0008] Based on the alignment of the text box in the grid cell, the invisible row and column lines of the grid cell are determined from the candidate row and column lines, so as to extract the incomplete frame line table according to the invisible row and column lines.
[0009] Optionally, performing a hit test on the grid unit and determining candidate row and column lines of the grid unit based on a hit test result includes:
[0010] Identifying a text box in the grid cell, determining rows and columns to be extracted based on the text box, and determining initial row and column lines;
[0011] Performing a hit test on the initial row and column lines to obtain qualified row and column lines that pass the test;
[0012] The qualified row and column lines between the current row and column basic position and the previous row and column basic position are determined as candidate row and column lines.
[0013] Optionally, performing a hit test on the initial row and column lines to obtain qualified row and column lines that pass the test includes:
[0014] Projecting toward the text boxes along the direction of the initial row and column lines, and recording the number of text boxes hit;
[0015] The initial row and column lines whose number of hit text boxes is less than a threshold are determined as qualified row and column lines that pass the test.
[0016] Optionally, the invisible row and column lines include invisible column lines, and determining the invisible row and column lines of the grid unit from the candidate row and column lines based on the alignment of the text box in the grid unit includes:
[0017] Determine the column alignment of the text box, where the alignment includes left alignment, center alignment, and right alignment;
[0018] Determine a first distance between each candidate column line and the first left boundary of the text box, and determine a second distance between each candidate column line and the first right boundary of the text box;
[0019] An invisible column line of the grid cell is determined from the candidate column lines based on the column alignment, the first distance, and the second distance.
[0020] Optionally, the invisible row and column lines include an invisible upper row line and an invisible lower row line, and determining the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell includes:
[0021] Determine the line alignment of the text box, where the alignment includes top alignment and center alignment;
[0022] For top alignment, determine the interval between each candidate line and the previous candidate line, sort the intervals in a forward order, and determine the candidate line corresponding to the interval that ranks first as the upper line of the current line;
[0023] For center alignment, the first candidate line below the lower boundary of the previous line is determined as the upper line of the current line;
[0024] The candidate line corresponding to the lower boundary of the current line text box is determined as the descending line.
[0025] Optionally, determining the table type of the table based on the number of visible row and column lines of the table in the PDF file includes:
[0026] Determine the visible row and column lines of the table in the PDF file;
[0027] Comparing the number of visible row and column lines with a number threshold;
[0028] If the number of visible row and column lines is less than a number threshold, it is determined that the table type is an incomplete framed table.
[0029] Optionally, the visible row lines and visible column lines are included, and detecting the visible row and column lines of the table in the PDF file includes:
[0030] Convert the PDF file into an image, determine the header position of the table, and determine the region of interest based on the header position;
[0031] Performing binarization processing on the region of interest to obtain a binarized image;
[0032] Performing x-axis mapping on the binary image to obtain a first connected domain, and obtaining a text box at a basic position of each row and a visible row line based on the first connected domain; and
[0033] Sum the pixels of the binary image along the y-axis to obtain the pixel sum of each column line along the y-axis, and determine the line whose pixel sum is consistent with the pixel value of the region of interest as a visible column line
[0034] The embodiment of the present invention further provides a device for extracting an incomplete frame line table, comprising:
[0035] A table type determination module is used to determine the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete frame line table and an incomplete frame line table;
[0036] a gridding module, configured to grid the incomplete frame line table to obtain grid cells, perform a hit test on the grid cells, and determine candidate row and column lines of the grid cells based on the hit test results;
[0037] The invisible row and column line determination module is used to determine the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell, so as to extract the incomplete frame line table according to the invisible row and column lines.
[0038] An embodiment of the present invention further provides a device for extracting an incomplete frame line table, comprising a memory, a processor, and an incomplete frame line table extraction program stored in the memory. When the incomplete frame line table extraction program is executed by the processor, the steps of any of the above methods are implemented:
[0039] An embodiment of the present invention further provides a computer-readable storage medium storing an incomplete frame line table extraction program. When the incomplete frame line table extraction program is executed by a processor, the steps of any of the above methods are implemented.
[0040] Compared to the existing technology, the present invention proposes a method, device, equipment, and storage medium for extracting an incomplete framed table. The method determines the table type of each table based on the number of visible row and column lines in the table area of a PDF file, wherein the table types include complete framed tables and incomplete framed tables. The incomplete framed table is gridded to obtain grid cells, and a hit test is performed on the grid cells. Based on the hit test results, candidate row and column lines of the grid cells are determined. Based on the alignment of the text boxes in the grid cells, the invisible row and column lines of the grid cells are determined from the candidate row and column lines, so as to extract the incomplete framed table based on the invisible row and column lines. The incomplete framed table is gridded, and a hit test is performed on the gridded grid cells to determine the candidate row and column lines. The invisible row and column lines of the incomplete framed table are determined in combination with the alignment. In this way, the incomplete framed table can be extracted, solving the current problem of low accuracy in extracting incomplete framed tables. BRIEF DESCRIPTION OF THE DRAWINGS
[0041] Figure 1 Schematic diagram of the hardware structure of the device for extracting an incomplete frame line table according to various embodiments of the present invention;
[0042] Figure 2 1 is a flow chart of a first embodiment of a method for extracting an incomplete frame line table according to the present invention;
[0043] Figure 3 This is a rasterization diagram related to an embodiment of a method for extracting an incomplete frame line table of the present invention;
[0044] Figure 4 1 is a flow chart of a second embodiment of a method for extracting an incomplete frame line table according to the present invention;
[0045] Figure 5 This is a schematic diagram of a hit test according to an embodiment of a method for extracting an incomplete frame line table of the present invention;
[0046] Figure 6 1 is a flow chart of a third embodiment of a method for extracting an incomplete frame line table according to the present invention;
[0047] Figure 7 1 is a schematic diagram of a column alignment method according to an embodiment of a method for extracting an incomplete framed table of the present invention;
[0048] Figure 8 This is a first schematic diagram of a row alignment method according to an embodiment of a method for extracting an incomplete frame table of the present invention;
[0049] Figure 9 This is a second schematic diagram of a row alignment method according to an embodiment of a method for extracting an incomplete frame table of the present invention;
[0050] Figure 10 1 is a flow chart of a fourth embodiment of a method for extracting an incomplete frame line table according to the present invention;
[0051] Figure 11 2 is a schematic diagram of pixel value summation involved in an embodiment of a method for extracting an incomplete frame line table of the present invention;
[0052] Figure 12 1 is a functional module diagram of a first embodiment of an apparatus for extracting an incomplete frame line table according to the present invention.
[0053] The purpose, features and advantages of the present invention will be further described with reference to the accompanying drawings and in conjunction with the embodiments. DETAILED DESCRIPTION
[0054] It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention.
[0055] The incomplete frame line table extraction device mainly involved in the embodiments of the present invention refers to a network connection device capable of achieving network connection. The incomplete frame line table extraction device may be a server, a cloud platform, etc.
[0056] Reference Figure 1 , Figure 1 Schematic diagram of the hardware structure of the extraction device of the incomplete framed form involved in each embodiment of the present invention. In the embodiment of the present invention, the extraction device of the incomplete framed form may include a processor 1001 (such as a central processing unit, CPU), a communication bus 1002, an input port 1003, an output port 1004, and a memory 1005. Among them, the communication bus 1002 is used to realize the connection and communication between these components; the input port 1003 is used for data input; the output port 1004 is used for data output, and the memory 1005 can be a high-speed RAM memory or a stable memory (non-volatile memory), such as a disk memory. The memory 1005 can optionally be a storage device independent of the aforementioned processor 1001. It can be understood by those skilled in the art that Figure 1 The hardware structure shown in the figure does not constitute a limitation of the present invention, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0057] Continue to refer to Figure 1 , Figure 1 The memory 1005 as a readable storage medium may include an operating system, a network communication module, an application module, and an extraction program for an incomplete frame line table. Figure 1 In the example, the network communication module is mainly used to connect to the server and perform data communication with the server; and the processor 1001 is used to call the extraction program of the incomplete frame line table stored in the memory 1005 and perform the following operations:
[0058] Determining the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete frame line table and an incomplete frame line table;
[0059] gridding the incomplete frame line table to obtain grid cells, performing a hit test on the grid cells, and determining candidate row and column lines of the grid cells based on the hit test results;
[0060] Based on the alignment of the text box in the grid cell, the invisible row and column lines of the grid cell are determined from the candidate row and column lines, so as to extract the incomplete frame line table according to the invisible row and column lines.
[0061] Based on the above-mentioned incomplete frame line table extraction device, the first embodiment of the incomplete frame line table extraction method of the present invention is proposed. Figure 2 , Figure 2 4 is a flow chart of a first embodiment of a method for extracting an incomplete frame line table according to the present invention.
[0062] like Figure 1 As shown, the first embodiment of the present invention provides a method for extracting an incomplete frame line table, which is applied to an extraction device for an incomplete frame line table. The method includes:
[0063] Step S101, determining the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete frame table and an incomplete frame table;
[0064] This embodiment searches for and determines the visible row and column lines in the table by image processing. The PDF page may contain short lines, broken lines, dotted lines, etc. that may interfere with the recognition of row and column lines. In order to eliminate the interference with the recognition of row and column lines to the greatest extent, this embodiment only focuses on the region of interest. After selecting the region of interest, the visible row and column lines are detected. It can be understood that for a table unit, if the row and column lines on all sides are visible, it is a complete framed table; if the row and column lines on all sides are invisible, it is a frameless table; if the row and column lines on all sides include visible row and column lines and invisible row and column lines, it is an incomplete framed table. This embodiment determines the frameless table and the incomplete framed table as an incomplete framed table.
[0065] It is worth noting that the extraction method of the incomplete frame line table proposed in this embodiment adopts a coarse to fine extraction strategy, which mainly includes two stages: the first stage (Coarse Stage), after selecting the area of interest, the visible row and column lines are determined through image processing; the second stage is (Fine Stage), which extracts the invisible row and column lines based on the rasterization of the table.
[0066] In the Fine Stage, row and column lines are determined based on the basic row positions (row kernel) and column positions (column kernel). Therefore, in the Coarse Stage, the row and column kernels must also be detected. The row and column kernels consist of both row and column kernels. A row kernel is the basic position that represents each row, and row lines must be located near it and not overlap with it. A column kernel is the basic position that represents each column, and column lines must be located near it and not overlap with it.
[0067] Specifically, after converting the PDF to an image, the table header position is determined. Based on the header position, the region of interest (ROI) is determined. This ROI is then binarized and mapped along the x-axis to obtain a connected domain. Row kernels are extracted from this connected domain. To extract the row kernel, a closing operation is performed on the binarized ROI: image lines are dilated and then eroded to close the subtly connected blocks. A connected domain is then mapped along the y-axis to extract the column kernel. The row and column kernels are saved for later use.
[0068] Step S102, gridding the incomplete frame line table to obtain grid cells, performing a hit test on the grid cells, and determining candidate row and column lines of the grid cells based on the hit test results;
[0069] For tables with incomplete borders, since there are no frame constraints and no fixed structural constraints, although the rows and columns of the table are visible to the naked eye, the accuracy of machine recognition is often limited. This embodiment uses text boxes and text box alignment to identify incomplete borders. The main idea is to use the position information and alignment of the text to rasterize the table.
[0070] The concept of rasterization first appeared in image processing. Later, with the continuous development of image technology, the concept of rasterization was extended to the description and representation of spatial fields. Figure 3 , Figure 3 This is a rasterization diagram related to an embodiment of a method for extracting an incomplete frame line table of the present invention, such as Figure 3 As shown, a is the text in the table, and grid cells such as A1, A2, A3, and A4 need to be found to separate the text. The restoration of the incomplete border table will be converted into the determination of the row and column lines of the grid cells, that is, the determination of the A frame line.
[0071] This embodiment determines the row and column lines of the grid cells through a hit test. Specifically, a point on the x-axis or y-axis is projected perpendicularly to all text boxes, and the number of text boxes hit is recorded. If the number of text boxes hit is less than a threshold, the row and column line is determined to be a candidate row and column line for the grid line.
[0072] Step S103 : determining invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell, so as to extract the incomplete frame line table according to the invisible row and column lines.
[0073] The column alignment of text boxes in a table includes left alignment, center alignment, and right alignment. Drawing on people's left-to-right reading habits, this embodiment prioritizes detecting the left boundary of the grid cell, that is, the invisible left column line, when detecting invisible row and column lines. After determining the left row and column line, the right boundary of the rightmost text is used as the end position of the grid cell, that is, the invisible right column line of the grid cell. This embodiment can determine the invisible left column line from the column line candidates based on the column alignment of the text box in the grid cell.
[0074] The row alignment options for text boxes in tables include top, center, and bottom. In real-world scenarios, top and center alignment are the primary considerations. When detecting invisible line lines, the top edge of the grid cell (the invisible ascender) is first detected. The bottom edge of the bottommost text is then used as the grid end position (the invisible descender).
[0075] In this way, a complete frame line table is extracted based on the visible row and column lines, and an incomplete frame line table can be extracted based on the obtained invisible column lines and invisible row lines.
[0076] This embodiment uses the above scheme to determine the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table types include complete frame line tables and incomplete frame line tables; the incomplete frame line table is gridded to obtain grid cells, and a hit test is performed on the grid cells, and candidate row and column lines of the grid cells are determined based on the hit test results; based on the alignment of the text box in the grid cell, the invisible row and column lines of the grid cell are determined from the candidate row and column lines, so as to extract the incomplete frame line table based on the invisible row and column lines. The incomplete frame line table is gridded, and a hit test is performed on the gridded grid cells to determine the candidate row and column lines, and the invisible row and column lines of the incomplete frame line table are determined in combination with the alignment method. In this way, the incomplete frame line table can be extracted, solving the current problem of low accuracy in extracting incomplete frame line tables.
[0077] like Figure 4 As shown, the second embodiment of the present invention proposes a method for extracting an incomplete frame line table, step S102: performing a hit test on the grid cell, and determining candidate row and column lines of the grid cell based on the hit test result, including:
[0078] Step S1021: identifying a text box in the grid cell, determining rows and columns to be extracted based on the text box, and determining initial row and column lines;
[0079] Generally, optical character recognition (OCR) can be used to identify all text boxes in the grid cell. Determine all possible rows and columns based on the location of the text box, and determine the frame lines of the text box based on the determined rows and columns. In an actual table, due to the different number of characters in the same row or column, or the difference in character size, the row and column lines of the text boxes in the same row and column will be slightly different. Therefore, after determining all possible rows, the overlapping or almost overlapping text box row lines are merged. After determining all possible columns, the overlapping or almost overlapping text box column lines are merged. Then the text box row lines remaining after the merger are determined as the initial row lines, and the text box column lines remaining after the merger are determined as the initial column lines, so that the initial row and column lines are obtained.
[0080] Step S1022: performing a hit test on the initial row and column lines to obtain qualified row and column lines that pass the test;
[0081] Specifically, the initial row and column lines are projected toward the text boxes along the direction of the initial row and column lines, and the number of the hit text boxes is recorded; the initial row and column lines whose number of hit text boxes is less than a threshold are determined as qualified row and column lines that have passed the test.
[0082] refer to Figure 5 , Figure 5 1 is a schematic diagram of a hit test according to an embodiment of the method for extracting an incomplete frame line table of the present invention. Figure 5 As shown, the thick lines of varying lengths above the x-axis represent text boxes, and the dotted arrows x0 and x1 represent projections toward the text boxes perpendicular to the x-axis. It can be seen from the figure that there are 5 text boxes hit by projection x0, and the number of text boxes hit by projection x1 is also 5.
[0083] It is understandable that the fewer the number of text boxes hit, the greater the probability that the corresponding projection line is a row or column line. Therefore, the number of text boxes hit is compared with a threshold, and the initial row or column line with a number of text boxes hit less than the threshold is determined to be a qualified row or column line that has passed the test. The threshold can be set as needed, for example, to 5, 4, 3, etc.
[0084] Step S1023: determining the qualified row and column lines between the current row and column basic position and the previous row and column basic position as candidate row and column lines.
[0085] It is understandable that, based on the hit test results, there may be more than one row line or column line between rows or between columns. Therefore, this embodiment determines the row lines and column lines between rows or between columns as candidate row and column lines for the corresponding rows or columns. Specifically, the qualified column line between the current column basic position and the previous column basic position is determined as a candidate column line, and the qualified row line between the current row basic position and the previous row basic position is determined as a candidate row line.
[0086] Through the above scheme, this embodiment performs a hit test on the text box based on the grid unit, and determines the candidate row and column lines according to the hit results. In this way, the row and column lines of the incomplete border table are converted into the row and column lines of the grid unit through the idea of rasterization, thereby determining the detection objects of the row and column lines, which helps to improve the pertinence and accuracy of the extraction of the incomplete border table.
[0087] like Figure 6 As shown, the third embodiment of the present invention provides a method for extracting an incomplete frame line table, wherein the invisible row and column lines include invisible column lines, and determining the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell includes:
[0088] Step S10311: Determine the column alignment of the text box, where the alignment includes left alignment, center alignment, and right alignment;
[0089] Specific column alignment reference Figure 7 , Figure 7 : is a schematic diagram of the column alignment method involved in an embodiment of the method for extracting an incomplete frame table of the present invention, Figure 7 (a) means left alignment, Figure 7 (b) indicates center alignment, Figure 7 (c) indicates right alignment.
[0090] Specifically, find and determine the text box corresponding to the target column. If the left borders of the text boxes in this column are equal, the alignment is left-aligned; if the right borders of the text boxes in this column are equal, the alignment is right-aligned; if the central axes of the text boxes in this column are equal, the alignment is center-aligned.
[0091] Step S10312: determining a first distance between each candidate column line and the left border of the text box, and determining a second distance between each candidate column line and the right border of the text box;
[0092] For the target column, there is only one left border of the text box, but multiple candidate column lines can be obtained after the hit test. For left alignment, the left border of the target column text box is consistent, so the candidate column line closest to the left border of the text box is determined as the invisible left column line of the corresponding grid cell; for right alignment, the right border of the target column text box is consistent, but the left border is inconsistent, so the candidate column line closest to the leftmost text box border is determined as the invisible left column line of the corresponding grid cell; for center alignment, the left and right borders of the target column text box are inconsistent, so the candidate column line closest to the leftmost text box border is determined as the invisible left column line of the corresponding grid cell.
[0093] In order to determine the invisible column lines, the first distance between each candidate column line and the first left boundary of the text box is calculated, and the second distance between each candidate column line and the first right boundary of the text box is determined. The first left boundary in this embodiment refers to the leftmost boundary of the target column. For example, for left alignment, there is generally only one left boundary, which is the first left boundary. For center alignment and right alignment, the left boundaries of different rows are generally inconsistent. Therefore, after obtaining the left boundary of each row, the leftmost boundary is determined as the first left boundary, that is, the left boundary farthest from the central axis is the first left boundary. The first right boundary refers to the rightmost boundary of the target column. For example, for right alignment, there is generally only one right boundary, which is the first right boundary. For center alignment and right alignment, the right boundaries of different rows are generally inconsistent. Therefore, after obtaining the right boundary of each row, the rightmost boundary is determined as the first right boundary, that is, the right boundary farthest from the central axis is the first right boundary.
[0094] Step S10313 : determining an invisible column line of the grid unit from the candidate column lines based on the column alignment, the first distance, and the second distance.
[0095] After determining the first distance and the second distance, sort the multiple first distances of the target column, sort the multiple second distances of the target column, and determine the minimum first distance from the first distances and the minimum second distance from the second distances.
[0096] For left alignment, the candidate column line corresponding to the minimum first distance is determined as the invisible left column line of the grid cell; the candidate column line corresponding to the minimum second distance is determined as the invisible right column line of the grid cell. In other words, the candidate column line that coincides with or almost coincides with the left edge of the text box is determined as the invisible left column line, and the candidate column line that coincides with or almost coincides with the right edge of the rightmost side of the text box is determined as the invisible right column line.
[0097] For center alignment, the candidate column line corresponding to the minimum first distance is determined as the invisible left column line of the grid cell, and the candidate column line corresponding to the minimum second distance is determined as the invisible right column line of the grid cell. The candidate column line that coincides with or almost coincides with the left edge of the leftmost side of the target column text box is determined as the invisible left column line; the candidate column line that coincides with or almost coincides with the right edge of the rightmost side of the target column text box is determined as the invisible right column line.
[0098] For right alignment, the candidate column line corresponding to the minimum first distance is determined as the invisible left column line of the grid cell; the candidate column line corresponding to the minimum second distance is determined as the invisible right column line of the grid cell, that is, the candidate column line that coincides with or almost coincides with the right border is determined as the invisible left column line. In other words, the candidate column line that coincides with or almost coincides with the left border of the leftmost side of the text box is determined as the invisible left column line.
[0099] In this embodiment, the invisible row and column lines include an invisible upper row line and an invisible lower row line. Determining the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell includes:
[0100] Step S10321: Determine the line alignment of the text box, where the alignment includes top alignment and center alignment;
[0101] Obtain qualified row lines from the qualified row and column lines that pass the hit test, perform a secondary hit test on the top edges of the row kernels of all rows, and determine the row alignment of the row kernel corresponding to the top edges that pass the secondary hit test as center alignment; those that fail the secondary hit test can be considered to be top aligned.
[0102] Step S10322: For top alignment, determine the intervals between each candidate line and the previous candidate line, sort the intervals in a forward order, and determine the candidate line corresponding to the interval that ranks first as the upper line of the current line;
[0103] refer to Figure 8 , Figure 8 This is a first schematic diagram of a row alignment method according to an embodiment of a method for extracting an incomplete frame table of the present invention. Figure 8For the third row (the last row) as shown, the possible upper lines include Line1 and Line2. Obviously, Line1 is the true upper boundary of this row. Specifically, the distance between the middle row and the upper row is less than the distance x2 between x1 and the row below the middle row, that is, x1 < x2; assuming the text characters are of the same size and the character height is h, then x1 + h < x2 + h, that is, h1 < h2, where h2 is the interval between the candidate row line line2 and the previous candidate row line line2, and h2 is the interval between the candidate row line line1 and the previous candidate row line line2. Thus, after sorting the intervals in ascending order, the candidate row line corresponding to the interval ranked first is the upper line of the current row line, that is, the line with a larger interval between candidate row lines is the upper line.
[0104] Step S10323: For center alignment, determine the first candidate row line below the lower boundary of the previous row as the upper line of the current row; the upper line refers to the upper boundary of the current row text box.
[0105] Reference Figure 9 , Figure 9 FIG. is the second schematic diagram of the row alignment method involved in an embodiment of the method for extracting a non-complete frame line table of the present invention. Based on the row kernel, candidate row lines are determined. As Figure 9 For the last row as shown, the possible upper lines include Line1 and Line2. Obviously, Line1 is the true upper line. The reason for determining Line1 as the row line is that Line1 is below Line4, and Line4 is the lower boundary obtained by taking the row kernel of the previous row above Line3 as the axis of symmetry. That is, for the current row, the upper line is the first line of the lower boundary of the previous row.
[0106] Step S10324: Determine the candidate row line corresponding to the lower boundary of the current row text box as the lower line. That is, the lower boundary of the text box is the lower line of the grid cell.
[0107] Through the above solution in this embodiment, the row and column lines of the grid cell are determined from the candidate row and column lines according to the alignment method, making it possible to extract the non-complete frame line table.
[0108] As Figure 10 shown, the fourth embodiment of the present invention proposes a method for extracting a non-complete frame line table.
[0109] Step S101, determining the table type of the table based on the number of visible row and column lines in the PDF file, includes:
[0110] Step S1011, determining the visible row and column lines in the PDF file.
[0111] Convert the PDF file into an image, determine the header position of the table, and determine the region of interest based on the header position;
[0112] The region of interest is binarized to obtain a binarized image. In this embodiment, binarization is to set the grayscale value of the pixel points on the image to 0 or 255, and the binarized image is a black and white image.
[0113] The binary image is mapped along the x-axis to obtain a first connected domain. Based on the first connected domain, a text box at a base position in each row and visible lines are obtained. The text box at a base position in each row refers to the text box in the first column of each row. Visible lines are obtained using image recognition. Generally, lines with a length in the x-axis greater than a preset length are identified as visible lines.
[0114] The pixels of the binary image are summed along the y-axis direction to obtain the pixel sum of each line along the y-axis direction, and the line whose pixel sum is consistent with the pixel value of the region of interest is determined as a visible column line.
[0115] Considering the different horizontal and vertical representations of text, phrases are mapped horizontally without gaps, but vertically, due to spaces between characters, gaps exist. Using the same method for checking visible row lines would result in many redundant column kernels. To prevent this, a closing operation is performed on the region of interest when detecting column kernels. However, this approach creates a problem: while column kernels can be obtained, if visible column lines are close to text, the closing operation will connect the text to the column line, causing column line detection to fail.
[0116] To this end, this embodiment determines the visible column lines based on pixel values. Figure 11 , Figure 11 This is a schematic diagram of the pixel value summation involved in an embodiment of the method for extracting an incomplete frame line table of the present invention. In the y-axis direction, the visible column lines will run through the entire region of interest in the longitudinal direction; and due to the presence of text in the text box, the column lines passing through the text will have gaps at the top, bottom, or in the middle; based on this, the column lines are summed along the y-axis direction. If the sum of the binarized pixels is equal to the height of the region of interest, the corresponding line is a visible column line.
[0117] In this embodiment, the total number of pixels along the y-axis is represented as H.
[0118]
[0119] Where pix represents a pixel, and x and y represent coordinate positions. The obtained H is compared with the pixel values in the region of interest to determine the visible column lines.
[0120] Step S1012, comparing the number of visible row and column lines with a number threshold;
[0121] The sum of the number of visible row lines and the number of visible column lines is determined as the number of visible row and column lines. In this embodiment, the number threshold may be 4, which is generally 2 row lines and 2 column lines.
[0122] Step S1013 : If the number of visible row and column lines is less than a number threshold, it is determined that the table type is an incomplete framed table.
[0123] If the number of visible row and column lines is less than the threshold, it means that the table lacks one or more row and column lines and is therefore an incomplete border table. If the number of visible row and column lines is equal to the threshold, it means that the table has complete visible row and column lines.
[0124] This embodiment determines the type of the table through the above solution, so that the complete frame table can be directly extracted later, and the focus is placed on the incomplete frame table, so that the incomplete frame table can be extracted efficiently and specifically.
[0125] Furthermore, in order to achieve the above-mentioned purpose, the present invention also provides a device for extracting an incomplete frame line table. Specifically, see 12, Figure 12 1 is a functional module diagram of a first embodiment of an apparatus for extracting an incomplete frame line table according to the present invention, the apparatus comprising:
[0126] A table type determination module 10 is configured to determine the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete framed table and an incomplete framed table;
[0127] a gridding module 20 for gridding the incomplete frame line table to obtain grid cells, performing a hit test on the grid cells, and determining candidate row and column lines of the grid cells based on the hit test results;
[0128] The invisible row and column line determination module 30 is configured to determine the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell, so as to extract the incomplete frame line table according to the invisible row and column lines.
[0129] Furthermore, the rasterization module 20 includes:
[0130] an identification unit, configured to identify a text box in the grid cell, determine rows and columns to be extracted based on the text box, and determine initial row and column lines;
[0131] A hit test unit, used for performing a hit test on the initial row and column lines to obtain qualified row and column lines that pass the test;
[0132] The row and column line determination unit is used to determine the qualified row and column lines between the current row and column basic position and the previous row and column basic position as candidate row and column lines.
[0133] Furthermore, the hit test unit includes:
[0134] a recording subunit, configured to project onto the text boxes along the direction of the initial row and column lines, and record the number of text boxes hit;
[0135] The qualified row and column line determination subunit is used to determine the initial row and column line whose number of hit text boxes is less than a threshold as a qualified row and column line that has passed the test.
[0136] Furthermore, the invisible row and column line determination module 30 includes:
[0137] A column alignment determination unit, configured to determine a column alignment of the text box, wherein the alignment includes left alignment, center alignment, and right alignment;
[0138] a distance determining unit, configured to determine a first distance between each candidate column line and the first left boundary of the text box, and determine a second distance between each candidate column line and the first right boundary of the text box;
[0139] The invisible column line determining unit is configured to determine the invisible column line of the grid unit from the candidate column lines based on the column alignment, the first distance, and the second distance.
[0140] Furthermore, the invisible row and column line determination module 30 includes:
[0141] A row alignment determination unit, configured to determine a row alignment of the text box, wherein the alignment includes top alignment and center alignment;
[0142] a first ascending line determining unit, configured to determine the intervals between each candidate line and the previous candidate line for top alignment, sort the intervals in a forward order, and determine the candidate line corresponding to the interval that ranks first as the ascending line of the current line;
[0143] a second ascending line determining unit, configured to determine, for center alignment, the first candidate line below the lower boundary of the previous line as the ascending line of the current line;
[0144] The descending line determining unit is configured to determine the candidate line corresponding to the lower boundary of the current line text box as the descending line.
[0145] Furthermore, the table type determination module includes:
[0146] A visible row and column line determination unit is used to determine the visible row and column lines of a table in a PDF file;
[0147] a comparing unit, configured to compare the number of the visible row and column lines with a number threshold;
[0148] The incomplete frame table determining unit is configured to determine that the table type is an incomplete frame table if the number of the visible row and column lines is less than a number threshold.
[0149] Furthermore, the visible row and column line determination unit includes
[0150] a conversion subunit, configured to convert the PDF file into an image, determine a table header position, and determine a region of interest based on the table header position;
[0151] A binarization subunit, configured to perform binarization processing on the region of interest to obtain a binarized image;
[0152] a visible row line determination subunit, configured to perform x-axis mapping on the binary image to obtain a first connected domain, and obtain a text box at a basic position of each row and visible row lines based on the first connected domain; and
[0153] The visible column line determination subunit is used to sum the pixels of the binary image along the y-axis direction to obtain the pixel sum of each column line along the y-axis direction, and determine the line whose pixel sum is consistent with the pixel value of the region of interest as a visible column line.
[0154] In addition, the present invention also proposes a computer-readable storage medium, on which is stored a program for extracting an incomplete frame line table. When the program for extracting an incomplete frame line table is executed by a processor, the steps of the method for extracting an incomplete frame line table as described above are implemented, which will not be repeated here.
[0155] Compared to the existing technology, the present invention determines the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table types include complete framed table and incomplete framed table; the incomplete framed table is gridded to obtain grid cells, and a hit test is performed on the grid cells, and candidate row and column lines of the grid cells are determined based on the hit test results; based on the alignment of the text box in the grid cell, the invisible row and column lines of the grid cell are determined from the candidate row and column lines, so as to extract the incomplete framed table based on the invisible row and column lines. The incomplete framed table is gridded, and a hit test is performed on the gridded grid cells to determine the candidate row and column lines, and the invisible row and column lines of the incomplete framed table are determined in combination with the alignment method. In this way, the incomplete framed table can be extracted, solving the current problem of low accuracy in extracting incomplete framed tables.
[0156] The above description is only a preferred embodiment of the present invention and does not limit the patent scope of the present invention. Any equivalent structure or process transformation made by using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A method for extracting an incomplete frame line table, characterized in that: The method comprises: Determining the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete frame line table and an incomplete frame line table; Gridding the incomplete frame line table to obtain grid cells, identifying text boxes in the grid cells, determining rows and columns to be extracted based on the text boxes, and determining initial row and column lines; Performing a hit test on the initial row and column lines to obtain qualified row and column lines that have passed the test; wherein performing a hit test on the initial row and column lines to obtain qualified row and column lines that have passed the test comprises: projecting toward the text boxes along the direction of the initial row and column lines, recording the number of text boxes hit; determining the initial row and column lines for which the number of text boxes hit is less than a threshold as qualified row and column lines that have passed the test; Determine the qualified row and column line between the current row and column basic position and the previous row and column basic position as a candidate row and column line; Based on the alignment of the text box in the grid cell, the invisible row and column lines of the grid cell are determined from the candidate row and column lines, so as to extract the incomplete frame line table according to the invisible row and column lines.
2. The method according to claim 1, characterized in that The invisible row and column lines include invisible column lines, and determining the invisible row and column lines of the grid unit from the candidate row and column lines based on the alignment of the text box in the grid unit includes: Determine the column alignment of the text box, where the alignment includes left alignment, center alignment, and right alignment; Determine a first distance between each candidate column line and the first left boundary of the text box, and determine a second distance between each candidate column line and the first right boundary of the text box; An invisible column line of the grid cell is determined from the candidate column lines based on the column alignment, the first distance, and the second distance.
3. The method according to claim 1, characterized in that The invisible row and column lines include an invisible upper row line and an invisible lower row line. The determining of the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell includes: Determine the line alignment of the text box, where the alignment includes top alignment and center alignment; For top alignment, determine the interval between each candidate line and the previous candidate line, sort the intervals in a forward order, and determine the candidate line corresponding to the interval that ranks first as the upper line of the current line; For center alignment, the first candidate line below the lower boundary of the previous line is determined as the upper line of the current line; The candidate line corresponding to the lower boundary of the current line text box is determined as the descending line.
4. The method according to claim 1, wherein Determining the table type based on the number of visible row and column lines of the table in the PDF file includes: Determine the visible row and column lines of the table in the PDF file; Comparing the number of visible row and column lines with a number threshold; If the number of visible row and column lines is less than a number threshold, it is determined that the table type is an incomplete framed table.
5. The method according to claim 4, characterized in that The visible row and column lines include visible row lines and visible column lines, and determining the visible row and column lines of the table in the PDF file includes: Convert the PDF file into an image, determine the table header position, and determine the region of interest based on the table header position; Performing binarization processing on the region of interest to obtain a binarized image; Performing x-axis mapping on the binary image to obtain a first connected domain, and obtaining a text box at a basic position of each row and a visible row line based on the first connected domain; and The pixels of the binary image are summed along the y-axis direction to obtain the pixel sum of each column line along the y-axis direction, and the line whose pixel sum is consistent with the pixel value of the region of interest is determined as a visible column line.
6. A device for extracting an incomplete frame line table, characterized in that: include: A table type determination module is used to determine the table type of each table based on the number of visible row and column lines in the table area of the PDF file, wherein the table type includes a complete frame line table and an incomplete frame line table; A rasterization module is used to rasterize the incomplete frame line table to obtain raster units, identify text boxes in the raster units, determine rows and columns to be extracted based on the text boxes, and determine initial row and column lines; perform a hit test on the initial row and column lines to obtain qualified row and column lines that pass the test; and determine qualified row and column lines between the current row and column basic position and the previous row and column basic position as candidate row and column lines. The hit test is performed on the initial row and column lines to obtain qualified row and column lines that pass the test. The rasterization module is specifically used to: project toward the text boxes along the direction of the initial row and column lines and record the number of text boxes hit; and determine the initial row and column lines whose number of text boxes hit is less than a threshold as qualified row and column lines that pass the test; The invisible row and column line determination module is used to determine the invisible row and column lines of the grid cell from the candidate row and column lines based on the alignment of the text box in the grid cell, so as to extract the incomplete frame line table according to the invisible row and column lines.
7. A device for extracting an incomplete frame line table, characterized in that: The system comprises a memory, a processor and an extraction program for an incomplete frame line table stored in the memory, wherein the extraction program for an incomplete frame line table is executed by the processor to implement the steps of the method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that The computer-readable storage medium stores an extraction program for an incomplete frame line table. When the extraction program for the incomplete frame line table is executed by a processor, the steps of the method according to any one of claims 1 to 5 are implemented.
Citation Information
Patent Citations
Method and system for identifying incomplete frame line table for analytic PDF (Portable Document Format)
CN118351557A