Table recognition method, system, electronic device and storage medium

By filtering and merging horizontal and vertical lines in drawings to construct tables, and using OCR technology to recognize text, the inefficiency of manually inputting table content in existing technologies is solved, achieving automated table content recognition and improving efficiency.

CN117133002BActive Publication Date: 2026-03-17GLODON CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-09-05
Publication Date
2026-03-17

AI Technical Summary

Technical Problem

Existing technology cannot automatically recognize the table content in drawings, forcing technicians to manually input it, which is inefficient.

Method used

An initial table is constructed by filtering horizontal and vertical lines in the drawing area, and cells are merged based on the common edge position of adjacent cells. The cell content is then identified and output, and OCR technology is used to recognize the text content.

Benefits of technology

It enables automatic recognition of drawing and table content, eliminating the need for manual input and improving the work efficiency of technical personnel.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117133002B_ABST
    Figure CN117133002B_ABST
Patent Text Reader

Abstract

This invention relates to the field of computer-aided design technology, and discloses a table recognition method, system, electronic device, and storage medium. The table recognition method includes filtering table lines for constructing tables from lines in a specified drawing area. These table lines include horizontal and vertical lines, each with an x-coordinate and a y-coordinate. An initial table is constructed based on the y-coordinate of the horizontal lines and the x-coordinate of the vertical lines. In the initial table, if the common boundary line between adjacent cells is not located on either the horizontal or vertical line, the adjacent cells are merged to obtain the drawing table. In the drawing table, the content of each cell is identified and output, cell by cell. This method can automatically recognize tables in drawings, improving the work efficiency of technicians.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer-aided design technology, specifically to a table recognition method, system, electronic device, and storage medium. Background Technology

[0002] In the infrastructure sector, blueprint recognition is fundamental for quantity surveying and pricing in construction projects. Among the various needs for blueprint recognition, the recognition of tables within blueprints is one of the most critical.

[0003] Currently, for some drawings (such as PDF vector drawings), when technicians use these drawings to perform quantity calculations or pricing for construction projects, the software cannot automatically recognize the tables in these drawings. They can only manually input the contents of the tables into the quantity calculation software, which is inefficient.

[0004] Therefore, there is an urgent need for a table recognition method that can automatically identify table content. Summary of the Invention

[0005] In view of this, embodiments of the present invention provide a table recognition method, a table recognition system, an electronic device, and a computer-readable storage medium, which can automatically recognize tables in drawings and improve the work efficiency of technicians.

[0006] This invention provides a table recognition method, the method comprising:

[0007] In the lines of the specified drawing area, filter the table lines used to construct the table. The table lines include horizontal lines and vertical lines, and each line has a horizontal coordinate and a vertical coordinate.

[0008] An initial table is constructed based on the ordinate of the horizontal lines and the abscissa of the vertical lines;

[0009] In the initial table, if the common edge between adjacent cells is not located on the horizontal or vertical line, the adjacent cells are merged to obtain the drawing table;

[0010] In the drawing table, the contents of each cell are identified and output, on a cell-by-cell basis.

[0011] In some embodiments of this application, horizontal and vertical lines are selected from the lines in a specified drawing area. An initial table is constructed based on the ordinate of the horizontal lines and the abscissa of the vertical lines. In the initial table, cells are merged based on whether the common edge between adjacent cells lies on a horizontal or vertical line, resulting in a drawing table. The content of each cell in the drawing table is identified and output. This allows for automatic identification of tables and their contents in the drawing, eliminating the need for manual input by technicians and improving their work efficiency.

[0012] In some embodiments, it is determined whether the common border between adjacent cells is not located on the horizontal line or the vertical line based on the following method:

[0013] If one or more target points on the common edge are not located on the horizontal line or the vertical line, it is determined that the common edge is not located on the horizontal line or the vertical line.

[0014] Determining whether a common boundary line lies on a horizontal or vertical line by identifying the location of one or more target points on that boundary line simplifies the judgment process.

[0015] In some embodiments, the x-coordinate of each line is represented by the x-coordinates of its two endpoints, and the y-coordinate of each line is represented by the y-coordinates of its two endpoints.

[0016] The filtering used to construct the table lines includes:

[0017] In the designated drawing area, if the vertical coordinates of the two endpoints of a line are the same, the corresponding line is determined as a candidate horizontal line; and if the horizontal coordinates of the two endpoints of a line are the same, the corresponding line is determined as a candidate vertical line.

[0018] After removing lines that do not meet the preset conditions from the candidate horizontal lines and candidate vertical lines, the horizontal lines and vertical lines are obtained.

[0019] Lines are filtered based on whether their x-coordinates and y-coordinates are the same. This filtering method aligns with the way line coordinates are stored in computer memory, allowing for the direct selection of candidate horizontal and vertical lines based on the data stored in the computer. The filtering logic is relatively simple.

[0020] In some embodiments, the step of removing lines that do not meet the preset conditions from the candidate horizontal lines and the candidate vertical lines includes:

[0021] Among the candidate horizontal lines and the candidate vertical lines, lines with a length less than a length threshold are removed.

[0022] Removing lines shorter than a certain length threshold can reduce interference from these lines in subsequent table recognition, and also reduce the amount of line data, thereby reducing the amount of data processing.

[0023] In some embodiments, the step of removing lines that do not meet the preset conditions from the candidate horizontal lines and the candidate vertical lines includes:

[0024] Among the candidate horizontal lines and the candidate vertical lines, lines that do not form a loop with other lines are eliminated.

[0025] Removing lines that do not form loops with other lines eliminates lines that are definitely not table lines, thus reducing interference from these lines in subsequent table recognition and improving accuracy. It also reduces the amount of data processing required.

[0026] In some embodiments, the removal of lines that do not form a loop with other lines includes:

[0027] For any one of the candidate horizontal lines and the candidate vertical lines, if the line intersects with other lines at a non-endpoint position, the line is broken at the intersection point.

[0028] After the interruption operation is completed, count the number of lines associated with each line endpoint;

[0029] For any line endpoint, if the number of lines associated with that line endpoint is 1, then the lines associated with that line endpoint are considered lines that do not form a loop with other lines, and the corresponding lines are removed.

[0030] After the interruption operation is performed, the number of lines associated with each line endpoint is counted to filter and remove lines that do not form a loop with other lines. This filtering method is more accurate and can prevent omissions.

[0031] In some embodiments, the content of each cell in the drawing table includes text content, which is composed of lines;

[0032] Identify the content in each cell, including:

[0033] The lines in the cells are printed onto an image, and the image is then recognized to obtain the text content of each cell.

[0034] Printing the content of cells onto an image and then using image recognition technology to extract the text content from the cells reduces the reliance on text elements and broadens the applicability of the solution.

[0035] In some embodiments, the x-coordinate and y-coordinate of each line are determined based on a first coordinate system;

[0036] The step of printing the lines in the cell onto the image includes:

[0037] Construct a first bounding box for the cell and obtain the lines located within the first bounding box;

[0038] Construct a second bounding box for the set of lines within the cell bounding box, and construct a second coordinate system based on the second bounding box;

[0039] Transform the coordinates of each line in the cell from the first coordinate system to the second coordinate system, and print the lines in the cell onto the image based on the coordinates of each line in the second coordinate system.

[0040] Transforming the line coordinates from the first coordinate system to the second coordinate system facilitates the implementation of the solution. Constructing the second coordinate system based on bounding boxes simplifies the shape and structure of cells or line sets, reducing computational complexity.

[0041] In another aspect, the present invention provides a table recognition system, the system comprising:

[0042] The filtering module is used to filter table lines for constructing tables from lines in a specified drawing area. The table lines include horizontal lines and vertical lines, and each line has a horizontal coordinate and a vertical coordinate.

[0043] An initial construction module is used to construct an initial table based on the ordinate of the horizontal lines and the abscissa of the vertical lines;

[0044] The merging module is used to merge adjacent cells in the initial table if the common edge between adjacent cells is not located on the horizontal line or the vertical line, to obtain the drawing table.

[0045] The content recognition module is used to identify and output the text content in each cell of the drawing table, on a cell-by-cell basis.

[0046] In another aspect, the present invention provides an electronic device comprising a processor and a memory, the memory being used to store a computer program which, when executed by the processor, implements the method described above.

[0047] In another aspect, the present invention provides a computer-readable storage medium for storing a computer program that, when executed by a processor, implements the method described above. Attached Figure Description

[0048] The features and advantages of the invention will be more clearly understood by referring to the accompanying drawings, which are schematic and should not be construed as limiting the invention in any way. In the drawings:

[0049] Figure 1 A flowchart illustrating a table recognition method provided in one embodiment of this application is shown;

[0050] Figure 2 A schematic diagram of line coordinates provided in one embodiment of this application is shown;

[0051] Figure 3 A schematic diagram of horizontal and vertical lines provided in one embodiment of this application is shown;

[0052] Figure 4 A schematic diagram of an initial table constructed based on horizontal and vertical coordinates according to an embodiment of this application is shown;

[0053] Figure 5 A schematic diagram of a real table in a drawing provided in one embodiment of this application is shown;

[0054] Figure 6 This illustration shows a schematic diagram of the position of a line in a first coordinate system according to an embodiment of this application;

[0055] Figure 7 A schematic diagram of alternative horizontal lines and alternative vertical lines provided in one embodiment of this application is shown;

[0056] Figure 8 A schematic diagram of the modules of a form recognition system provided in one embodiment of this application is shown;

[0057] Figure 9 A schematic diagram of an electronic device provided in one embodiment of this application is shown. Detailed Implementation

[0058] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of the present invention, and not all of them. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0059] Before describing the solution in this application, the relevant concepts involved in this application will be explained.

[0060] 1) Vector graphics

[0061] Vector graphics are graphics described using mathematical formulas. Unlike bitmap graphics, vector graphics are not composed of pixels, but rather of basic geometric elements such as lines, curves, shapes, and colors. Furthermore, each element in a vector graphic has corresponding coordinate information.

[0062] Vector graphics can be created using professional software such as Adobe Illustrator and CorelDRAW. These programs also support exporting vector graphics to DWG and PDF formats. The difference between DWG and PDF vector graphics is that DWG includes layers and text information (i.e., text primitives), while PDF does not. In PDF drawings, text information is represented by vector lines.

[0063] 2) World Coordinate System

[0064] The world coordinate system refers to a spatial coordinate system used in 3D computer graphics. It can also be called the global coordinate system, inertial coordinate system, or absolute coordinate system. The world coordinate system is a fundamental mathematical model used to describe the position and orientation of 3D objects in space; it has fixed coordinate axes and an origin.

[0065] 3) Local coordinate system

[0066] A local coordinate system is a coordinate system established based on a selected object. Typically, the origin of the local coordinate system can be the geometric center of the selected object or another specific location, and the orientation of the coordinate axes can be determined based on the orientation and shape of the selected object. Each selected object can have its own local coordinate system. The relative positional relationship between the local coordinate system and the selected object remains constant. That is, as the position of the selected object changes, the orientation of the coordinate axes, the origin, etc., of the local coordinate system also change.

[0067] 4) Coordinate system transformation

[0068] This refers to the process of transforming the coordinates of a selected object in one coordinate system to another.

[0069] This concludes the explanation of the relevant concepts.

[0070] The table recognition method of this application can be applied to drafting software or to electronic devices running such software. Electronic devices include, but are not limited to, tablet computers, laptops, servers, etc. Please refer to... Figure 1 This is a flowchart illustrating a table recognition method provided in one embodiment of this application. Figure 1In this context, the table recognition method includes the following steps:

[0071] Step S11: In the lines of the specified drawing area, filter the table lines used to construct the table. The table lines include horizontal lines and vertical lines, and each line has a horizontal coordinate and a vertical coordinate.

[0072] The designated drawing area can be a region manually selected by technicians on the drawing based on the actual situation. For example, if technicians need to perform measurements based on tabular data in area A of the drawing, they can manually select area A as the designated drawing area.

[0073] Table lines refer to the lines used to divide cells within a table. When filtering table lines within a specified drawing area, filtering can be based on the x-coordinate and y-coordinate of each line. Specifically, the x-coordinate and y-coordinate of each line can be determined based on a first coordinate system. This first coordinate system can be the world coordinate system. The first coordinate system can include an X-axis and a Y-axis. The x-coordinate of a line can be its X-axis coordinate, and the y-coordinate can be its Y-axis coordinate. (See also...) Figure 2 This is a schematic diagram of line coordinates provided in one embodiment of this application. Figure 2 As can be seen, the horizontal coordinate of the line is between 3 and 7, and the vertical coordinate is between 4 and 5.

[0074] Horizontal lines can refer to lines whose vertical coordinate is a fixed value, that is, lines parallel to the X-axis of the first coordinate system. Vertical lines can refer to lines whose horizontal coordinate is a fixed value, that is, lines parallel to the Y-axis of the first coordinate system. (See also...) Figure 3 This is a schematic diagram of horizontal and vertical lines provided in one embodiment of this application. Figure 3 In the table, for line AB, its x-coordinate is between 3 and 7, and its y-coordinate is between 4 and 5. Neither the x-coordinate nor the y-coordinate is a fixed value, so line AB is not a table line. For line DE, its x-coordinate is between 5 and 9, and its y-coordinate is 5. The y-coordinate is a fixed value (parallel to the x-axis), so line DE can be used as a horizontal line. For line CD, its x-coordinate is 5, and its y-coordinate is between 3 and 5. The x-coordinate is a fixed value (parallel to the y-axis), so line CD can be used as a vertical line.

[0075] The horizontal lines selected from the specified drawing area can be used as the first set of lines, and the vertical lines selected from the specified drawing area can be used as the second set of lines.

[0076] Step S12: Construct an initial table based on the ordinate of the horizontal lines and the abscissa of the vertical lines.

[0077] As described in step S11, the ordinates of the horizontal lines and the abscissas of the vertical lines are both fixed values. From the first set of lines, the ordinates of each horizontal line can be extracted, and from the second set of lines, the abscissas of each vertical line can be extracted. Based on the extracted ordinates and abscissas, the ordinates can be sorted in descending order along the Y-axis of the first coordinate system, and the abscissas can be sorted in descending order along the X-axis of the first coordinate system. Based on the sorted ordinates and abscissas, the first position corresponding to the minimum ordinate and minimum abscissa, the second position corresponding to the minimum ordinate and maximum abscissa, the third position corresponding to the maximum ordinate and minimum abscissa, and the fourth position corresponding to the maximum ordinate and maximum abscissa can be used as the four corner points of the initial table. The intervals between adjacent ordinates and adjacent abscissas can be used as the side lengths of individual cells in the initial table, thus constructing the initial table.

[0078] To facilitate understanding, the following example illustrates this. Assume the extracted horizontal lines have ordinates of 3, 4, 5, and 6, and the vertical lines have x-coordinates of 3, 5, 7, 9, and 11. (Refer to the relevant documentation.) Figure 4 This is a schematic diagram of an initial table constructed based on horizontal and vertical coordinates according to an embodiment of this application. Figure 4 In the table, after sorting 3, 4, 5, 6 along the Y-axis and 3, 5, 7, 9, 11 along the X-axis, the first position corresponding to the minimum ordinate and minimum abscissa is position A; the second position corresponding to the minimum ordinate and maximum abscissa is position B; the third position corresponding to the maximum ordinate and minimum abscissa is position C; and the fourth position corresponding to the maximum ordinate and maximum abscissa is position D. Using positions A, B, C, and D as the four corner points of the initial table, and taking the intervals between adjacent ordinates and adjacent abscissas as the side lengths of individual cells in the initial table, we can construct... Figure 4 The initial table shown.

[0079] Step S13: In the initial table, if the common border between adjacent cells is not located on a horizontal or vertical line, merge the adjacent cells to obtain the drawing table.

[0080] See also Figure 4 When constructing the initial table, only the ordinates of the horizontal lines and the abscissas of the vertical lines were considered, without taking into account the range of the abscissas of the horizontal lines and the range of the ordinates of the vertical lines. Therefore, the constructed initial table may differ from the actual table in the drawing. For example, please refer to... Figure 5 This is a schematic diagram of a real table in a drawing provided in one embodiment of this application. Based on Figure 5The actual table shown can be used to extract horizontal lines gj, fk, cd, en, and vertical lines ge, ab, hl, im, jn in step S11. The horizontal line cd has a different x-coordinate range than the other horizontal lines, and the vertical line ab has a different y-coordinate range than the other vertical lines. However, based on the y-coordinates of the horizontal lines and the x-coordinates of the vertical lines, a table can still be constructed in step S12. Figure 4 The initial table shown. It is obvious that... Figure 4 The initial table and Figure 5 The actual table in the original table differs from the actual table. Therefore, it is necessary to further merge the cells in the initial table.

[0081] In this embodiment, whether adjacent cells should be merged can be determined based on whether the common border between them lies on a horizontal or vertical line. For example, referring to... Figure 4 and Figure 5 ,exist Figure 4 In the middle, the common border op of cells 41 and 42 is not located from... Figure 5 To extract any horizontal or vertical line, cells 41 and 42 need to be merged to obtain the desired result. Figure 5 The merged cells shown in the top left corner. Then... Figure 4 Taking cells 41 and 43 as an example, the common border qp of cells 41 and 43 is located from... Figure 5 The extracted horizontal line fk means that cells 41 and 43 do not need to be merged.

[0082] By iterating through adjacent cells in the initial table, we can obtain a drawing table that matches the actual table in the drawing.

[0083] In drawing tables, a cell obtained by merging multiple adjacent cells from the initial table can be considered as a single cell. For example... Figure 4 Cells 41 and 42 in the text can be merged into Figure 5 A cell in the top left corner.

[0084] Step S14: In the drawing table, identify and output the contents of each cell, cell by cell.

[0085] Specifically, the content within a cell can include, but is not limited to, the text content and fill color of the cell. When the drawing is a DWG vector graphic, since DWG vector graphics include text elements and color information, the text element information and color information within each cell can be directly extracted. When the drawing is a PDF vector graphic, since the text content in PDF vector graphics is composed of lines and does not have color information, the text content in each cell can be directly identified based on the line combination relationships.

[0086] After identifying the content of each cell in the drawing table, this content can be output to a designated form. The designated form can be the location where the content from the drawing table will be output, such as the form in quantity calculation software. This achieves automatic recognition of table content, eliminating the need for technicians to manually input the content from the drawing table into the designated form.

[0087] In summary, in some embodiments of this application, horizontal and vertical lines are selected from the lines in a specified drawing area. An initial table is constructed based on the ordinate of the horizontal lines and the abscissa of the vertical lines. In the initial table, cells are merged based on whether the common edge between adjacent cells lies on a horizontal or vertical line, resulting in a drawing table. The content of each cell in the drawing table is identified and output. This allows for automatic identification of tables and their contents in the drawing, eliminating the need for technicians to manually input table content and improving their work efficiency.

[0088] The following provides further details about this application.

[0089] In some embodiments, when storing the x-coordinates and y-coordinates of a line in computer storage, the x-coordinate of the line can be represented by the x-coordinates of its two endpoints, and the y-coordinate of each line can be represented by the y-coordinates of its two endpoints; that is, only the x-coordinates and y-coordinates of the two endpoints of the line can be stored. Based on the x-coordinates and y-coordinates of the two endpoints of a line, the x-coordinates and y-coordinates of the line in a first coordinate system can be determined. (See also...) Figure 6 This is a schematic diagram showing the position of a line in a first coordinate system according to an embodiment of this application. Based on Figure 6 The lines shown can be stored in computer memory as coordinates (3, 5) and (7, 4). Here, (3, 5) represents the x-coordinate and y-coordinate of one endpoint of the line, and (7, 4) represents the x-coordinate and y-coordinate of the other endpoint. Based on these two endpoint coordinates, it can be determined that the x-coordinate of the line is between 3 and 7, and the y-coordinate is between 4 and 5.

[0090] Based on the storage format of line coordinates, the filtering of table lines used to construct the table in step S11 may include:

[0091] In a specified drawing area, if the vertical coordinates of the two endpoints of a line are the same, the corresponding line will be designated as a candidate horizontal line; and if the horizontal coordinates of the two endpoints of a line are the same, the corresponding line will be designated as a candidate vertical line.

[0092] After removing lines that do not meet the preset conditions from the candidate horizontal and vertical lines, the horizontal and vertical lines are obtained.

[0093] For example, the coordinates of the two endpoints of line A are (3,1) and (5,7), the coordinates of the two endpoints of line B are (2,4) and (2,8), and the coordinates of the two endpoints of line C are (3,5) and (4,5). Among lines A, B, and C, line A has different x and y coordinates at its two endpoints, so it doesn't need to be considered as a candidate horizontal or vertical line. Line B has the same x coordinate at its two endpoints, so it can be considered as a candidate vertical line. Line C has the same y coordinate at its two endpoints, so it can be considered as a candidate horizontal line. It can be understood that if the y coordinates of the two endpoints of a line are the same, the line is parallel to the X-axis of the world coordinate system, therefore, the line can be considered as a candidate horizontal line; if the y coordinates of the two endpoints of a line are the same, the line is parallel to the Y-axis of the world coordinate system, therefore, the line can be considered as a candidate vertical line. Further filtering of the candidate horizontal and vertical lines according to preset conditions will yield the final horizontal and vertical lines. For details on the preset conditions, please refer to the subsequent descriptions; they will not be repeated here. Lines are filtered based on whether their x-coordinates and y-coordinates are the same. This filtering method aligns with the way line coordinates are stored in computer memory, allowing for the direct selection of candidate horizontal and vertical lines based on the data stored in the computer. The filtering logic is relatively simple.

[0094] In some embodiments, the above-mentioned process of eliminating lines that do not meet the preset conditions from the candidate horizontal lines and candidate vertical lines includes:

[0095] Among the candidate horizontal and vertical lines, lines with a length less than the length threshold are removed.

[0096] The length threshold can be determined based on the actual situation. Lines shorter than the length threshold can be defined as non-table lines. In this embodiment, the length threshold is one-tenth of the text height in the drawing.

[0097] Removing lines shorter than a certain length threshold can reduce interference from these lines in subsequent table recognition, and also reduce the amount of line data, thereby reducing the amount of data processing.

[0098] In some embodiments, removing lines that do not meet preset conditions from the candidate horizontal lines and candidate vertical lines includes:

[0099] Among the candidate horizontal and vertical lines, lines that do not form a loop with other lines are eliminated.

[0100] In this context, a loop can refer to a closed area formed by multiple lines. If a line forms a closed area with other lines, it can be considered to have formed a loop. It's understandable that if a line is a table line, it must form a loop with other lines to create a table. If a line does not form a loop with other lines, such as an isolated line in a drawing that is not connected to any other lines, it is definitely not a table line. Therefore, eliminating lines that do not form loops with other lines can exclude lines that are definitely not table lines, thus reducing interference from these lines in subsequent table recognition and improving the accuracy of table recognition. It also reduces the amount of data processing required.

[0101] In some embodiments, removing lines that do not form a loop with other lines includes:

[0102] For any line among the candidate horizontal and candidate vertical lines, if the line intersects with other lines at a non-endpoint position, the line is broken at the intersection point.

[0103] After the interruption operation is completed, count the number of lines associated with each line endpoint;

[0104] For any line endpoint, if the number of lines associated with that line endpoint is 1, then the lines associated with that line endpoint are considered lines that do not form a loop with other lines, and the corresponding lines are removed.

[0105] For ease of understanding, please refer to [link / reference]. Figure 7 This is a schematic diagram of alternative horizontal lines and alternative vertical lines provided for one embodiment of this application. Figure 7 In the given scenario, if the candidate horizontal line ab intersects with the candidate vertical line ce at a non-endpoint position c, then the candidate horizontal line ab is broken at the non-endpoint position c, resulting in lines ac and CB. Similarly, if the candidate horizontal line df intersects with the candidate vertical line ce at a non-endpoint position e, then the candidate horizontal line df is broken at the non-endpoint position e, resulting in lines de and ef.

[0106] The lines associated with a line endpoint refer to lines whose start or end point is a line endpoint. When counting the number of lines associated with each line endpoint after a break operation, a mapping table between line endpoints and their associated lines can be created. Based on this mapping table, the number of lines associated with each line endpoint can be obtained. For example... Figure 7In the code, after the interruption operation is completed, the lines can include lines ad, ac, cb, de, ef, bf, gh, and ce. Taking line endpoints a, c, and g as examples, the mapping table of line endpoints and the lines associated with them can be shown in Table 1.

[0107] Table 1 Mapping Table

[0108] Line endpoints Connecting lines a Lines AC, Lines AD c Lines ac, line ce, line cb g lines gh

[0109] Based on this mapping table, it can be determined that the number of lines associated with line endpoint a is 2, the number of lines associated with line endpoint c is 3, and the number of lines associated with line endpoint g is 1.

[0110] It's understandable that if a line needs to form a loop with other lines, then the minimum number of lines connected to each endpoint of that line should be 2. Based on this, if an endpoint of a line is connected to only 1 line, it can be determined that the lines connected to that endpoint do not form a loop with other lines. For example... Figure 7 In the example, the endpoint g of line is only associated with line gh, which is an isolated line and needs to be removed.

[0111] In the above embodiments, after the interruption operation is performed, the number of lines associated with each line endpoint is counted to filter and remove lines that do not form a loop with other lines. This filtering method is more accurate and can prevent omissions.

[0112] It should be noted that after filtering lines based on the break operation, collinear lines need to be merged into a single line. This process re-merges the previously broken lines into complete lines, resulting in horizontal and vertical lines. Specifically, if different lines share the same direction (i.e., both are horizontal or vertical) and partially overlap, they can be considered collinear. For example, if line A has coordinates (4,5) and (4,8), and line B has coordinates (4,7) and (4,10), and both lines A and B are vertical lines with partial overlap, then lines A and B are collinear.

[0113] This explains how to eliminate lines that do not meet the preset conditions from the candidate horizontal and vertical lines to obtain the horizontal and vertical lines.

[0114] In some embodiments, when merging cells in step S13, it can be determined whether the common border between adjacent cells is not located on a horizontal or vertical line based on the following method:

[0115] If one or more target points on the common edge are not located on the horizontal or vertical lines, it is determined that the common edge is not located on the horizontal or vertical lines.

[0116] The target point can be any point on the common boundary line except for the endpoints. For example, the midpoint of the common boundary line, or the point that divides the common boundary line in a 4:3 ratio.

[0117] In this embodiment, the target point is the midpoint of the common edge line. That is, if the midpoint of the common edge line is not located on a horizontal or vertical line, it is determined that the common edge line is not located on a horizontal or vertical line. Determining whether the common edge line is located on a horizontal or vertical line by using the position of one or more target points on the common edge line simplifies the judgment logic.

[0118] In some embodiments, when the drawing is a PDF vector drawing, the step S14 of identifying the content in each cell includes:

[0119] Print the lines in the cells onto an image, and then use image recognition to obtain the text content of each cell.

[0120] Specifically, functions such as `ellipse`, `line`, and `fillPoly` from the OpenCV library can be used. Each cell's lines are printed as an image, and then OCR (Optical Character Recognition) technology is used to recognize each image to obtain the text content of each cell. OCR technology is a conventional technique known to those skilled in the art, and will not be elaborated upon here. Printing the cell content as an image and then using image recognition technology to obtain the text content reduces the reliance on text primitives, thus broadening the applicability of the solution.

[0121] In some embodiments, considering that the coordinates of the lines in a cell need to be transformed to a local coordinate system before printing, the above-described method of printing the lines in a cell into an image includes:

[0122] Build a first bounding box for the cell and get the lines inside the first bounding box;

[0123] Construct a second bounding box for the set of lines within the cell bounding box, and construct a second coordinate system based on the second bounding box;

[0124] Transform the coordinates of each line in the cell from the first coordinate system to the second coordinate system, and print the lines in the cell onto the image based on the coordinates of each line in the second coordinate system.

[0125] Here, the second coordinate system is the local coordinate system. The origin of the second coordinate system can be the top-left vertex of the second bounding box, the X-axis can have the same direction as the X-axis of the first coordinate system, and the Y-axis can point in the opposite direction to the Y-axis of the first coordinate system.

[0126] Specifically, when constructing a second bounding box for the set of lines within the cell bounding box, you can construct a line bounding box for each line within the cell bounding box, and then merge the line bounding boxes to obtain the second bounding box.

[0127] Transforming the line coordinates from the first coordinate system to the second coordinate system facilitates the implementation of the solution. Constructing the second coordinate system based on bounding boxes simplifies the shape and structure of cells or line sets, reducing computational complexity.

[0128] Please see Figure 8 This is a schematic diagram of a table recognition system provided in one embodiment of this application. Figure 8 In China, the table recognition system includes:

[0129] The filtering module is used to filter table lines for constructing tables from lines in a specified drawing area. The table lines include horizontal lines and vertical lines, and each line has a horizontal coordinate and a vertical coordinate.

[0130] The initial construction module is used to construct an initial table based on the ordinate of the horizontal lines and the abscissa of the vertical lines;

[0131] The merge module is used to merge adjacent cells in the initial table if the common border between them is not located on a horizontal or vertical line, thus obtaining the drawing table.

[0132] The content recognition module is used to identify and output the text content in each cell of a drawing table, on a cell-by-cell basis.

[0133] In some embodiments, the merging module is specifically used for:

[0134] If one or more target points on the common edge are not located on the horizontal line or the vertical line, it is determined that the common edge is not located on the horizontal line or the vertical line.

[0135] In some embodiments, the x-coordinate of each line is represented by the x-coordinates of its two endpoints, and the y-coordinate of each line is represented by the y-coordinates of its two endpoints. The filtering module is specifically used for:

[0136] In the designated drawing area, if the vertical coordinates of the two endpoints of a line are the same, the corresponding line is determined as a candidate horizontal line; and if the horizontal coordinates of the two endpoints of a line are the same, the corresponding line is determined as a candidate vertical line.

[0137] After removing lines that do not meet the preset conditions from the candidate horizontal lines and candidate vertical lines, the horizontal lines and vertical lines are obtained.

[0138] In some embodiments, the filtering module is specifically used for:

[0139] Among the candidate horizontal lines and the candidate vertical lines, lines with a length less than a length threshold are removed.

[0140] In some embodiments, the filtering module is specifically used for:

[0141] Among the candidate horizontal lines and the candidate vertical lines, lines that do not form a loop with other lines are eliminated.

[0142] In some embodiments, the filtering module is specifically used for:

[0143] For any one of the candidate horizontal lines and the candidate vertical lines, if the line intersects with other lines at a non-endpoint position, the line is broken at the intersection point.

[0144] After the interruption operation is completed, count the number of lines associated with each line endpoint;

[0145] For any line endpoint, if the number of lines associated with that line endpoint is 1, then the lines associated with that line endpoint are considered lines that do not form a loop with other lines, and the corresponding lines are removed.

[0146] In some embodiments, the content of each cell in the drawing table includes text content, which is composed of lines; the content recognition module is specifically used for:

[0147] The lines in the cells are printed onto an image, and the image is then recognized to obtain the text content of each cell.

[0148] In some embodiments, the x-coordinate and y-coordinate of each line are determined based on a first coordinate system; the content recognition module is specifically used for:

[0149] Construct a first bounding box for the cell and obtain the lines located within the first bounding box;

[0150] Construct a second bounding box for the set of lines within the cell bounding box, and construct a second coordinate system based on the second bounding box;

[0151] Transform the coordinates of each line in the cell from the first coordinate system to the second coordinate system, and print the lines in the cell onto the image based on the coordinates of each line in the second coordinate system.

[0152] Please see Figure 9The diagram below illustrates an electronic device according to an embodiment of this application. The electronic device includes a processor and a memory, the memory storing a computer program that, when executed by the processor, implements the method described above.

[0153] The processor can be a central processing unit (CPU). It can also be other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, or combinations thereof.

[0154] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs, non-transitory computer-executable programs, and modules, such as the program instructions / modules corresponding to the methods in the embodiments of this invention. The processor executes various functional applications and data processing by running the non-transitory software programs, instructions, and modules stored in the memory, thereby implementing the methods described in the above embodiments.

[0155] The memory may include a program storage area and a data storage area. The program storage area may store the operating system and applications required for at least one function; the data storage area may store data created by the processor, etc. Furthermore, the memory may include high-speed random access memory and non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, the memory may optionally include memory remotely located relative to the processor, which can be connected to the processor via a network. Examples of such networks include, but are not limited to, the Internet, corporate intranets, local area networks, mobile communication networks, and combinations thereof.

[0156] One embodiment of this application also provides a computer-readable storage medium for storing a computer program that, when executed by a processor, implements the above-described method.

[0157] Although embodiments of the invention have been described in conjunction with the accompanying drawings, those skilled in the art can make various modifications and variations without departing from the spirit and scope of the invention, and such modifications and variations all fall within the scope defined by the appended claims.

Claims

1. A form recognition method characterized by, The method comprises: In the line of the specified drawing area, screen the table line for constructing the table, the table line comprises horizontal line and vertical line, each line has horizontal coordinate and vertical coordinate; Based on the vertical coordinate of the horizontal line and the horizontal coordinate of the vertical line, construct the initial table; In the initial table, if the common edge between adjacent cells is not located in the horizontal line or the vertical line, merge the adjacent cells to obtain the drawing table, wherein whether the common edge between adjacent cells is not located in the horizontal line or the vertical line is determined based on the following method: if one or more target points on the common edge is not located in the horizontal line or the vertical line, it is determined that the common edge is not located in the horizontal line or the vertical line; In the drawing table, identify and output the content in each cell in unit of cell; Wherein, the horizontal coordinate of each line is represented by the horizontal coordinate of two end points of the line, and the vertical coordinate of each line is represented by the vertical coordinate of two end points of the line: The screening of the table line for constructing the table comprises: In the specified drawing area, if the vertical coordinates of two end points of a line are the same, the corresponding line is determined as a candidate horizontal line, and if the horizontal coordinates of two end points of a line are the same, the corresponding line is determined as a candidate vertical line; After eliminating the lines in the candidate horizontal line and the candidate vertical line that do not meet the preset condition, the horizontal line and the vertical line are obtained; The eliminating of the lines in the candidate horizontal line and the candidate vertical line that do not meet the preset condition comprises: In the candidate horizontal line and the candidate vertical line, eliminate the lines that do not form a ring with other lines.

2. The method of claim 1, wherein, The eliminating of the lines in the candidate horizontal line and the candidate vertical line that do not meet the preset condition comprises: In the candidate horizontal line and the candidate vertical line, eliminate the lines with length less than a length threshold.

3. The method of claim 1, wherein, The eliminating of the lines that do not form a ring with other lines comprises: For any line in the candidate horizontal line and the candidate vertical line, if the line has intersection points with other lines at non-end point positions, the line is broken at the intersection points; After the breaking operation is completed, count the number of lines associated with each line end point in the lines; For any line end point, if the number of lines associated with the line end point is 1, the line associated with the line end point is taken as a line that does not form a ring with other lines, and the corresponding line is eliminated.

4. The method of claim 1, wherein, The content in each cell of the drawing table comprises text content, and the text content is composed of lines; Identifying the content in each cell comprises: Printing the lines in the cell to a picture, and identifying the picture to obtain the text content in each cell.

5. The method of claim 4, wherein, The horizontal coordinate and the vertical coordinate of each line are determined based on a first coordinate system; The printing of the lines in the cell to a picture comprises: Constructing a first bounding box for the cell, and obtaining the lines located in the first bounding box; Constructing a second bounding box for the line set in the bounding box of the cell, and constructing a second coordinate system based on the second bounding box; The coordinates of each line in the cell in the first coordinate system are converted to the second coordinate system, and the lines in the cell are printed into a picture based on the coordinates of each line in the second coordinate system.

6. A form recognition system characterized by, The system comprises: The screening module is configured to screen table lines for constructing a table from lines in a specified drawing area, the table lines comprising horizontal lines and vertical lines, each line having an abscissa and an ordinate, specifically, the abscissa of each line being represented by the abscissas of two end points of the line, and the ordinate of each line being represented by the ordinates of two end points of the line, in the specified drawing area, if the ordinates of two end points of a line are the same, the corresponding line is determined as a candidate horizontal line, and if the abscissas of two end points of a line are the same, the corresponding line is determined as a candidate vertical line; after eliminating lines that do not meet a preset condition from the candidate horizontal lines and the candidate vertical lines, the horizontal lines and the vertical lines are obtained, specifically, in the candidate horizontal lines and the candidate vertical lines, lines that do not form a loop with other lines are eliminated; The initial construction module is configured to construct an initial table based on the ordinates of the horizontal lines and the abscissas of the vertical lines. The merging module is configured to merge adjacent cells in the initial table if a common edge line between the adjacent cells is not located on the horizontal lines or the vertical lines, to obtain a drawing table, wherein whether the common edge line between the adjacent cells is located on the horizontal lines or the vertical lines is determined based on the following method: if one or more target points on the common edge line are not located on the horizontal lines or the vertical lines, it is determined that the common edge line is not located on the horizontal lines or the vertical lines. The content recognition module is configured to recognize and output text content in each cell in the drawing table in units of cells.

7. A computer-readable storage medium, characterized in that, The computer readable storage medium is configured to store a computer program, which, when executed by a processor, implements the method of any one of claims 1 to 5.

8. An electronic device, comprising: The electronic device comprises a processor and a memory, the memory being configured to store a computer program, which, when executed by the processor, implements the method of any one of claims 1 to 5.

Citation Information

Patent Citations

  • Table layout analysis method, system and device based on minimum cell clustering

    CN111611883A

  • Table processing method, apparatus and device, and computer readable storage medium

    CN113158987A