Table identification method and device

By analyzing and rendering the target document, extracting and determining the table fields, the problems of low table recognition efficiency and inability to identify mixed elements tables in the prior art are solved, and tables with mixed elements in the document are quickly recognized.

CN119540978APending Publication Date: 2025-02-28ZHUHAI KINGSOFT OFFICE SOFTWARE +2
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202311095287.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-08-28
Publication Date
2025-02-28

AI Technical Summary

Technical Problem

In the prior art, the table recognition process is inefficient and cannot recognize mixed element tables.

Method used

By analyzing the target document, a candidate table line element set is obtained, rendered to the same canvas, the outer connected domain set is extracted, and the table field is determined based on the set, and the elements corresponding to the table field in the document are finally determined as tables.

Benefits of technology

It realizes the rapid identification of tables of mixed elements in documents, improves the recognition efficiency, and can identify tables composed of mixed elements.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119540978A_ABST
    Figure CN119540978A_ABST
Patent Text Reader

Abstract

The invention relates to a table recognition method and device, and the method comprises the steps: carrying out the analysis of a target document, and obtaining a candidate table line element set in the target document; rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image; extracting an external connected domain set in the candidate table line image; determining a table domain in the candidate table line image according to the external connected domain set; and determining elements in a document region corresponding to the table field in the target document as a table. Therefore, the table of the mixed elements in the document can be quickly identified.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of document processing, and in particular to a table recognition method and device. Background Art

[0002] As a means of organizing data, tables are an important part of documents. How to accurately identify tables and their contents is particularly important for the analysis of layout documents.

[0003] There are some methods for identifying and converting tables in layout documents in the prior art, such as first obtaining all elements in the document, then rendering all elements into images, and then using pattern recognition, deep learning, etc. to detect the corresponding table area, and then recording line segments and their intersections during page rendering to perform table recognition. Such methods have low recognition efficiency because they need to render all elements in the document, and can only recognize tables composed of Path type (vector type) elements. Summary of the invention

[0004] The present application provides a table recognition method and device to solve the technical problem that the table recognition process in the prior art is not only inefficient but also unable to recognize mixed element tables.

[0005] In a first aspect, the present application provides a table recognition method, the method comprising:

[0006] Parsing the target document to obtain a set of candidate table line elements in the target document;

[0007] Rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image;

[0008] Extracting a set of outer connected domains in the candidate table line image;

[0009] Determine a table domain in the candidate table line image according to the set of outer connected domains;

[0010] An element in a document area corresponding to the table field in the target document is determined as a table.

[0011] Optionally, the parsing of the target document to obtain a set of candidate table line elements in the target document includes:

[0012] Parsing the target document to obtain a set of different types of elements in the target document;

[0013] For the sets of elements of different types, different table line determination conditions are respectively used to determine candidate table line elements from the sets of elements of each type, thereby obtaining a set of candidate table line elements.

[0014] Optionally, the set of elements of different types includes a set of text type elements, and the table line determination condition includes a first table line determination condition;

[0015] Determining the candidate table line element from the set of text type elements is achieved by:

[0016] For each element in the set of text type elements, the following processing is performed: splitting the element to obtain multiple element items;

[0017] Determine the bounding rectangle and Unicode of each element;

[0018] When it is determined that each of the element items satisfies the first table line determination condition according to the corresponding circumscribed rectangular frame and the Unicode, the element is determined as a candidate table line element.

[0019] Optionally, the set of elements of different types includes a set of path type elements, and the table line determination condition includes a second table line determination condition;

[0020] Determining the candidate table line element from the set of path type elements is achieved by:

[0021] The following processing is performed for each element in the set of path type elements:

[0022] Parsing the element to obtain a path instruction set in the element;

[0023] In the case where it is determined that the first type of instruction exists in the path instruction set and the second type of instruction does not exist, determining the circumscribed rectangular frame of the element, the path start point and the path end point in the first direction, and the path start point and the path end point in the second direction;

[0024] When it is determined that the element satisfies the second table line determination condition based on the corresponding circumscribed rectangular box, the path start point and path end point in the first direction, and the path start point and path end point in the second direction, the element is determined as a candidate table line element.

[0025] Optionally, rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image includes:

[0026] Creating a canvas according to the size of the visible area in the target document;

[0027] The following processing is performed for each candidate table line element in the candidate table line element set:

[0028] Determine the bounding rectangle of the candidate table line element;

[0029] Determining a corresponding area of ​​the candidate table line element in the canvas according to the circumscribed rectangular frame;

[0030] The corresponding area is rendered using the set color value to obtain a candidate table line image.

[0031] Optionally, extracting a set of outer connected domains in the candidate table line image includes:

[0032] Performing a closing operation on the candidate table line image;

[0033] Extract the set of outer connected domains in the candidate table line image after the closing operation.

[0034] Optionally, performing a closing operation on the candidate table line image includes:

[0035] Determine a bounding rectangle of each candidate table line element in the candidate table line element set, and determine the shortest side of each of the bounding rectangles;

[0036] Determine the average value of the shortest side of each of the circumscribed rectangular frames;

[0037] A closing operation is performed on the candidate table line image using the average value as a kernel size.

[0038] Optionally, determining a table domain in the candidate table line image according to the outer connected domain set includes:

[0039] The following processing is performed for each outer connected domain in the outer connected domain set:

[0040] Determine the circumscribed rectangular frame of the outer connected domain;

[0041] When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set first table frame condition and the outer connected domain is determined to be a closed loop, the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

[0042] Optionally, the method further includes:

[0043] When the circumscribed rectangular frame of the outer connected domain is determined as a table domain, the corresponding table is determined to be a full-border table.

[0044] Optionally, determining a table domain in the candidate table line image according to the outer connected domain set includes:

[0045] The following processing is performed for each outer connected domain in the outer connected domain set:

[0046] Determine the circumscribed rectangular frame of the outer connected domain;

[0047] When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set second table frame condition, the outer connected domain is determined to be a horizontal line connected domain;

[0048] In the case where it is determined that there are multiple horizontal line connected domains, determining at least one target connected domain group from the multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction is greater than or equal to a set threshold;

[0049] An area formed by horizontal line connected areas at both ends in the second direction in the target connected area group is determined as a table area.

[0050] Optionally, the method further includes:

[0051] When the area formed by the horizontal line connected areas at both ends in the first direction in the target connected area group is determined as a table area, the corresponding table is determined to be a half-border table.

[0052] Optionally, determining at least one target connected domain group from the multiple horizontal line connected domains includes:

[0053] Selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as a current horizontal line connected domain;

[0054] For each other horizontal connected domain that is not grouped, perform the following processing:

[0055] Determine the projection overlap between the horizontal line connected domain and the current horizontal line connected domain in the first direction; if it is determined that the projection overlap is greater than or equal to a set threshold, divide the horizontal line connected domain and the current horizontal line connected domain into the same target connected domain group;

[0056] Return to the step of selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as the current horizontal line connected domain and subsequent steps until all horizontal line connected domains are grouped.

[0057] Optionally, determining the degree of overlap between the projections of the horizontal line connected domain and the current horizontal line connected domain in the first direction includes:

[0058] Determine a first left boundary horizontal coordinate value and a first right boundary horizontal coordinate value of a circumscribed rectangular frame of the horizontal line connected region;

[0059] Determine a second left boundary horizontal coordinate value and a second right boundary horizontal coordinate value of a circumscribed rectangular frame of the current horizontal line connected domain;

[0060] Determine the intersection length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first right boundary horizontal coordinate value and the second left boundary horizontal coordinate value, and determine the union length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first left boundary horizontal coordinate value and the second right boundary horizontal coordinate value;

[0061] The intersection length is divided by the union length to obtain a projection overlap degree between the horizontal line connected domain and the current horizontal line connected domain in the first direction.

[0062] In a second aspect, the present application provides a table recognition device, the device comprising:

[0063] An element parsing module, used to parse the target document to obtain a set of candidate table line elements in the target document;

[0064] A rendering module, used for rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image;

[0065] A connected domain extraction module, used to extract a set of outer connected domains in the candidate table line image;

[0066] A table domain determination module, used for determining a table domain in the candidate table line image according to the outer connected domain set;

[0067] The table identification module is used to determine the elements in the document area corresponding to the table field in the target document as a table.

[0068] Optionally, the element parsing module includes:

[0069] A parsing unit, used to parse the target document to obtain a set of different types of elements in the target document;

[0070] The suspected element identification unit is used to determine candidate table line elements from the set of elements of each type by using different table line determination conditions for the sets of elements of different types, so as to obtain a set of candidate table line elements.

[0071] Optionally, the set of elements of different types includes a set of text type elements, and the table line determination condition includes a first table line determination condition;

[0072] The suspected element identification unit is used to determine the candidate table line element from the set of text type elements in the following manner:

[0073] For each element in the set of text type elements, the following processing is performed: splitting the element to obtain multiple element items;

[0074] Determine the bounding rectangle and Unicode of each element;

[0075] When it is determined that each of the element items satisfies the first table line determination condition according to the corresponding circumscribed rectangular frame and the Unicode, the element is determined as a candidate table line element.

[0076] Optionally, the set of elements of different types includes a set of path type elements, and the table line determination condition includes a second table line determination condition;

[0077] The suspected element identification unit is used to determine the candidate table line element from the set of path type elements in the following manner:

[0078] The following processing is performed for each element in the set of path type elements:

[0079] Parsing the element to obtain a path instruction set in the element;

[0080] In the case where it is determined that the first type of instruction exists in the path instruction set and the second type of instruction does not exist, determining the circumscribed rectangular frame of the element, the path start point and the path end point in the first direction, and the path start point and the path end point in the second direction;

[0081] When it is determined that the element satisfies the second table line determination condition based on the corresponding circumscribed rectangular box, the path start point and path end point in the first direction, and the path start point and path end point in the second direction, the element is determined as a candidate table line element.

[0082] Optionally, the rendering module includes:

[0083] A canvas creation unit, used to create a canvas according to the size of the visible area in the target document;

[0084] The circumscribed rectangular frame rendering unit is used to perform the following processing on each candidate table line element in the candidate table line element set:

[0085] Determine the bounding rectangle of the candidate table line element;

[0086] Determining a corresponding area of ​​the candidate table line element in the canvas according to the circumscribed rectangular frame;

[0087] The corresponding area is rendered using the set color value to obtain a candidate table line image.

[0088] Optionally, the connected domain extraction module includes:

[0089] a closing operation unit, used for performing a closing operation on the candidate table line image;

[0090] The extraction unit is used to extract the set of outer connected domains in the candidate table line image after the closing operation.

[0091] Optionally, the closing operation unit is specifically used to:

[0092] Determine a bounding rectangle of each candidate table line element in the candidate table line element set, and determine the shortest side of each of the bounding rectangles;

[0093] Determine the average value of the shortest side of each of the circumscribed rectangular frames;

[0094] A closing operation is performed on the candidate table line image using the average value as a kernel size.

[0095] Optionally, the table domain determination module is specifically used to:

[0096] The following processing is performed for each outer connected domain in the outer connected domain set:

[0097] Determine the circumscribed rectangular frame of the outer connected domain;

[0098] When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set first table frame condition and the outer connected domain is determined to be a closed loop, the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

[0099] Optionally, the device further comprises:

[0100] The table type identification module is used to determine that the corresponding table is a full-border table when the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

[0101] Optionally, the table domain determination module includes:

[0102] An external frame determining unit, used for determining, for each external connected domain in the external connected domain set, an external rectangular frame of the external connected domain;

[0103] a horizontal line connected domain determining unit, configured to determine the outer connected domain as a horizontal line connected domain when it is determined according to the circumscribed rectangular frame that the outer connected domain meets a set second table frame condition;

[0104] a target connected domain group determining unit, configured to determine at least one target connected domain group from the multiple horizontal line connected domains when it is determined that there are multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction is greater than or equal to a set threshold;

[0105] The table domain determining unit is used to determine the area formed by the horizontal line connected domains located at both ends in the second direction in the target connected domain group as a table domain.

[0106] Optionally, the device further comprises:

[0107] The table type identification module is used to determine that the corresponding table is a half-border table when the area formed by the horizontal line connected domains at both ends in the first direction in the target connected domain group is determined as a table area.

[0108] Optionally, the target connected domain group determining unit is specifically configured to:

[0109] Selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as a current horizontal line connected domain;

[0110] For each other horizontal connected domain that is not grouped, perform the following processing:

[0111] Determine the projection overlap between the horizontal line connected domain and the current horizontal line connected domain in the first direction; if it is determined that the projection overlap is greater than or equal to a set threshold, divide the horizontal line connected domain and the current horizontal line connected domain into the same target connected domain group;

[0112] Return to the step of selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as the current horizontal line connected domain and subsequent steps until all horizontal line connected domains are grouped.

[0113] Optionally, the target connected domain group determining unit determines the projection overlap degree of the horizontal line connected domain and the current horizontal line connected domain in the first direction in the following manner:

[0114] Determine a first left boundary horizontal coordinate value and a first right boundary horizontal coordinate value of a circumscribed rectangular frame of the horizontal line connected region;

[0115] Determine a second left boundary horizontal coordinate value and a second right boundary horizontal coordinate value of a circumscribed rectangular frame of the current horizontal line connected domain;

[0116] Determine the intersection length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first right boundary horizontal coordinate value and the second left boundary horizontal coordinate value, and determine the union length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first left boundary horizontal coordinate value and the second right boundary horizontal coordinate value;

[0117] The intersection length is divided by the union length to obtain a projection overlap degree between the horizontal line connected domain and the current horizontal line connected domain in the first direction.

[0118] In a third aspect, the present application provides an electronic device, comprising: a processor and a memory, wherein the processor is used to execute a table recognition program stored in the memory to implement the table recognition method described in any one of the first aspects.

[0119] In a fourth aspect, the present application provides a storage medium storing one or more programs, wherein the one or more programs can be executed by one or more processors to implement the table recognition method described in any one of the first aspects.

[0120] The above-mentioned technical scheme provided by the embodiment of the present application has the following advantages over the prior art: the method provided by the embodiment of the present application, by parsing the target document, obtains a set of candidate table line elements in the target document, renders each candidate table line element in the set of candidate table line elements to the same canvas, obtains a candidate table line image, extracts a set of externally connected domains in the candidate table line image, determines the table domain in the candidate table line image according to the set of externally connected domains, determines the elements in the document area corresponding to the table domain in the target document as a table, thereby realizing the recognition of tables in documents, and can recognize tables of mixed elements, and in the recognition process, only renders the candidate table line elements therein to the canvas, which can reduce the rendering workload compared to the prior art of rendering all elements in the target document to the canvas, thereby improving the efficiency of table recognition. It can be seen that the application of the method provided by the embodiment of the present application can realize the rapid recognition of tables of mixed elements in documents. BRIEF DESCRIPTION OF THE DRAWINGS

[0121] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0122] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0123] One or more embodiments are exemplarily described by pictures in the corresponding drawings, and these exemplified descriptions do not constitute limitations on the embodiments. Elements with the same reference numerals in the drawings represent similar elements, and unless otherwise stated, the figures in the drawings do not constitute proportional limitations.

[0124] Figure 1 A flowchart of an embodiment of a table recognition method provided in an embodiment of the present application;

[0125] Figure 2 A flowchart of an embodiment of determining a candidate table line element from a set of text type elements provided in an embodiment of the present application;

[0126] Figure 3 A flowchart of another embodiment of determining a candidate table line element from a set of text type elements provided in an embodiment of the present application;

[0127] Figure 4 A flowchart of an embodiment of the present application for determining a table domain in a candidate table line image according to an outer connected domain set;

[0128] Figure 5 A flowchart of another embodiment of determining a table domain in a candidate table line image according to an outer connected domain set provided in an embodiment of the present application;

[0129] Figure 6 A schematic diagram of determining the projection overlap between horizontal line connected domains provided in an embodiment of the present application;

[0130] Figure 7 A block diagram of an embodiment of a table recognition device provided in an embodiment of the present application;

[0131] Figure 8 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0132] In order to make the purpose, technical solution and advantages of the embodiments of the present application clearer, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of this application.

[0133] The disclosure below provides many different embodiments or examples to implement different structures of the present invention. In order to simplify the disclosure of the present invention, the parts and settings of specific examples are described below. Of course, they are only examples, and the purpose is not to limit the present invention. In addition, the present invention can repeat reference numbers and / or letters in different examples. This repetition is for the purpose of simplification and clarity, and does not itself indicate the relationship between the various embodiments and / or settings discussed.

[0134] In order to solve the technical problem that the table recognition process in the prior art is not only inefficient but also unable to recognize mixed-element tables, the present application provides a table recognition method that can quickly recognize mixed-element tables in a document.

[0135] Figure 1 The following is a flow chart of an embodiment of a table recognition method provided in an embodiment of the present application. Figure 1 As shown, the following steps are included:

[0136] Step 101: parse the target document to obtain a set of candidate table line elements in the target document.

[0137] The target document is a document whose table is to be recognized, which can be a layout document in a format such as .pdf or .ofd, or a document in a picture format such as .jpg or .jpeg. For a document in a picture format, it can be converted into a layout document through OCR (Optical Character Recognition) technology and scanned document recognition technology.

[0138] Taking the target document in.pdf format as an example, it may include various types of elements such as Text type (text type), Path type (vector type), and Image type (image type). Different types of elements are restricted by their own attributes and have their own drawing methods when drawn as table lines. For example, elements of the Text type have a unified character encoding (Unicode) and a bounding rectangle (BBox), and the bounding rectangle has attributes such as width (BBox.Width) and height (BBox.Height). It can be understood that when drawing the table line of the Text type, Unicode exists in the line segment table set, and this line segment table set includes, for example, Unicode such as "-", "—", "一", "|" that may form the table line. Further, when drawing the horizontal table line of the Text type, the horizontal table line will have an oblong bounding rectangle, which will be reflected in the attributes of the bounding rectangle as a larger width and a smaller height of the bounding rectangle. When drawing the vertical table line of the Text type, the vertical table line will have a slender bounding rectangle, which will be reflected in the attributes of the bounding rectangle as a smaller width and a larger height of the bounding rectangle. Elements of the Path type have attributes such as a bounding rectangle (BBox), path instructions, a path start point (StartPoint), and a path end point (EndPoint). Among them, the path instructions include the LineTo instruction (which means moving and drawing a straight line), the BezierTo instruction (which means moving and drawing a Bezier curve), etc. It can be understood that when drawing the horizontal table line of the Path type, the path instruction of the horizontal table line is the LineTo instruction and cannot be the BezierTo instruction, and the horizontal table line will have an oblong bounding rectangle, which will be reflected in the attributes of the bounding rectangle as a larger width and a smaller height of the bounding rectangle, and the distance between the path start point (StartPoint.y) and the path end point (EndPoint.y) of the horizontal table line in the vertical direction does not exceed the width of its bounding rectangle. When drawing the vertical table line of the Path type, the path instruction of the vertical table line is also the LineTo instruction and cannot be the BezierTo instruction, and the vertical table line will have a slender bounding rectangle, which will be reflected in the attributes of the bounding rectangle as a smaller width and a larger height of the bounding rectangle, and the distance between the path start point (StartPoint.x) and the path end point (EndPoint.x) of the horizontal table line in the horizontal direction does not exceed the width of its bounding rectangle.

[0139] In this regard, in one embodiment, the target document is first parsed to obtain a set of different types of elements in the target document. For the sets of different types of elements, different table line determination conditions are used to determine candidate table line elements from the set of each type of element to obtain a set of candidate table line elements. It can be seen that the technical solution provided in the embodiment of the present application can identify a table composed of mixed elements in the target document.

[0140] Typically, table line elements are of the Text type or the Path type. Therefore, the target document may be parsed first to obtain a set of Text type elements and a set of Path type elements in the target document. The elements in the two sets may then be analyzed one by one. During the analysis, the corresponding table line determination conditions may be used to determine whether the element is a candidate table line element. If the element is determined to be a candidate table line element, the element may be included in the pre-created candidate table line element set.

[0141] It can be seen that by applying the method provided in the embodiment of the present application, not only can a table composed of Path type elements in the target document be identified, but also a table composed of Text type elements, as well as a table composed of Path type and Text type elements can be identified.

[0142] Step 102: Render each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image.

[0143] In an embodiment of the present application, each candidate table line element in the candidate table line element set is mapped to a new canvas for analysis to obtain a table domain, and then the table domain on the canvas is mapped back to the target document to determine the table element in the target document.

[0144] Specifically, in one embodiment, a blank canvas may be created, and each candidate table line element in the candidate table line element set may be rendered onto the canvas. For ease of description, the rendered canvas is referred to as a candidate table line image. The mapping position of the candidate table line element on the canvas is calculated based on the position of the candidate table line element in the target document, the size of the visible area in the target document, and the size of the canvas, and then the candidate table line element is rendered at the mapping position on the canvas. For example, assuming that the position of the candidate table line element in the target document is (x, y), and the size ratio between the visible area in the target document and the canvas is 1:m, then the mapping position of the candidate table line element on the canvas is (mx, my). The above m is a positive number. For example, when m is 1, it means that the size of the visible area in the target document is the same as the size of the canvas. When m is 0.5, it means that the size of the visible area in the target document is twice the size of the canvas, or the canvas size is 1 / 2 of the size of the visible area in the target document. When m is 2, it means that the canvas size is twice the size of the visible area in the target document, or the canvas size is 1 / 2 of the size of the visible area in the target document. And so on. Examples are not given one by one here. Here, since only the candidate table line elements are rendered to the canvas, compared with the prior art of rendering all elements in the target document to the canvas, that is, rendering the entire document page, the rendering workload can be reduced, thereby improving the efficiency of table recognition.

[0145] Among them, when creating the above-mentioned canvas, it can be created according to the size of the visible area in the target document, that is, create a canvas with the same size as the visible area in the target document. It can be seen from the above description that by creating a canvas with the same size as the visible area in the target document, it is possible to achieve mapping between the target document and the canvas without calculating the mapping position, thereby improving the efficiency of mapping. Of course, in actual applications, if the mapping efficiency is not considered, a canvas with a size different from that of the visible area in the target document can also be created, and this application does not make specific limitations on this.

[0146] In addition, in one embodiment, when rendering the candidate table line element to the canvas, only its outline needs to be rendered to the canvas, without considering other information, such as fill and stroke of Path type elements, font of Text type elements, etc. Compared with the prior art of rendering the original elements in the target document, this can greatly improve the rendering speed, thereby improving the efficiency of table recognition.

[0147] Specifically, the specific implementation of rendering each candidate table line element in the candidate table line element set onto the same canvas to obtain the candidate table line image includes: for each candidate table line element in the candidate table line element set, determining the bounding box (BBox) of the candidate table line element, and based on this bounding box, determining the corresponding area of the candidate table line element in the canvas, and using a set color value (such as black) to render the corresponding area in the canvas to obtain the candidate table line image. Thus, for a candidate table line element, a black rectangular area can be rendered in the canvas according to the coordinate information of its bounding box.

[0148] Step 103: Extract the set of outer connected regions in the candidate table line image.

[0149] First, it should be noted that in the table recognition scenario, the outer connected region is the largest connected region formed by the outermost border of the table. For example, for a "field"-shaped table, there are several connected regions, and the outer connected region is the largest connected region formed by the outermost border.

[0150] In one embodiment, the candidate table line image can be first subjected to a closing operation, and then the set of outer connected regions in the candidate table line image after the closing operation is extracted. The closing operation is a morphological operation in image processing, usually used to remove small holes and breaks in a binary image, making the objects in the image more connected and complete. The closing operation first performs a dilation operation and then an erosion operation, which can fill and connect the small holes and small cracks in the original image. The closing operation can be implemented with structuring elements of different sizes and shapes, and can be performed multiple times to better fill the holes and breaks in the image. Thus, by extracting the set of outer connected regions from the candidate table line image after the closing operation, the accuracy of the extracted outer connected regions can be improved.

[0151] Among them, as an optional implementation, when performing the closing operation on the candidate table line image, the bounding box of each candidate table line element in the candidate table line element set can be first determined, and the shortest side of each bounding box can be determined, and then the average value of the shortest sides of each bounding box can be determined, and the candidate table line image is subjected to the closing operation with this average value as the kernel size (denoted as KernelSize). In this way, the accuracy of the finally extracted outer connected regions can be further improved.

[0152] Step 104: Determine the table region in the candidate table line image according to the set of outer connected regions.

[0153] In the embodiment of the present application, the externally connected domains in the externally connected domain set are analyzed one by one to find the externally connected domains that meet the table characteristics, and then the table domain, that is, the area where the table is located, is determined. As for how to determine the table domain in the candidate table line image based on the externally connected domain set, it will be described in detail through specific embodiments below, and will not be described in detail here.

[0154] Step 105: Determine the element in the document area corresponding to the table field in the target document as a table.

[0155] In one embodiment, when the candidate table line image and the visible area in the target document are of the same size, the table field can be directly mapped to the target document according to the coordinates to obtain a document area in the target document corresponding to the table field, and the elements in the document area are determined as a table.

[0156] In another embodiment, when the sizes of the candidate table line image and the visible area in the target document are different, the coordinates of the table field can be transformed according to the sizes of the candidate table line image and the visible area in the target document, and then the table field can be mapped to the target document according to the transformed coordinates to obtain a document area in the target document corresponding to the table field, and the elements in the document area are determined as a table.

[0157] The technical solution provided by the embodiment of the present application, through the method provided by the embodiment of the present application, by parsing the target document, a set of candidate table line elements in the target document is obtained, each candidate table line element in the candidate table line element set is rendered to the same canvas to obtain a candidate table line image, an outer connected domain set in the candidate table line image is extracted, and the table domain is determined in the candidate table line image according to the outer connected domain set, and the elements in the document area corresponding to the table domain in the target document are determined as tables, thereby realizing the recognition of tables in documents, and being able to recognize tables of mixed elements, and in the recognition process, only rendering the candidate table line elements therein to the canvas, which can reduce the rendering workload compared to the prior art of rendering all elements in the target document to the canvas, thereby improving the efficiency of table recognition. It can be seen that the application of the method provided by the embodiment of the present application can realize the rapid recognition of tables of mixed elements in documents.

[0158] As can be seen from the above description, when identifying candidate table line elements from a target document, the target document is first parsed to obtain a set of Text type elements and a set of Path type elements in the target document, and then the elements in these two sets are analyzed one by one to see whether they are candidate table line elements. In this regard, the following describes the determination process of whether a Text type element and a Path type element are candidate table line elements respectively.

[0159] First, for elements of type Text:

[0160] In one embodiment, the target document is parsed to obtain a set of text type (Text type) elements in the target document. Here, the table line determination condition corresponding to the text type element is the first table line determination condition, and the first table line determination condition is as follows:

[0161] Unicode exists in the line segment table set; and,

[0162] BBox.Width > a * BBox.Height and BBox.Height < b (horizontal table line), or BBox.Height > a * BBox.Width and BBox.Width < b (vertical table line).

[0163] The above line segment table set includes Unicodes such as "-", "—", "一", "|", etc. that may form table lines.

[0164] The above BBox.Width refers to the width of the circumscribed rectangle, and BBox.Height refers to the height of the circumscribed rectangle. In practical applications, since for a horizontal line, the width of its circumscribed rectangle is greater than its height, and for a vertical line, the height of its circumscribed rectangle is greater than its width, so the above a is a constant greater than 1, and those skilled in the art can set a to 5 according to the current general settings. The above b is a positive number, and those skilled in the art can set b to 5.25 according to the current general settings. In practical applications, the values of a and b can be adjusted according to the actual situation, and the present application does not make specific limitations on this.

[0165] Specifically, it can be achieved by Figure 2 the shown process to determine candidate table line elements from the set of text type elements.

[0166] As Figure 2 shown, it includes the following steps:

[0167] Step 201: Split the elements of the first type to obtain multiple element items.

[0168] For example, if an element of the Text type includes 5 characters, then splitting this element can obtain 5 element items, and each element item includes one character.

[0169] Step 202: Determine the circumscribed rectangle and unified character encoding of each element item.

[0170] Step 203: When it is determined that each element item satisfies the first table line determination condition according to the corresponding circumscribed rectangle and unified character encoding, the element is determined as a candidate table line element.

[0171] For elements of the Text type, if each element item obtained after splitting satisfies the above first table line determination condition, then the element is determined as a candidate table line element. Among them, when the Unicode of each element item in the Text type element exists in the line segment table set, if the bounding rectangle of each element item satisfies BBox.Width > a * BBox.Height and BBox.Height < b, it means that the element may be a horizontal table line. If the bounding rectangle of each element item satisfies BBox.Height > a *

[0172] BBox.Width and BBox.Width < b, it means that the element may be a vertical table line.

[0173] Figure 2 In the process shown, by splitting the elements of the first type, multiple element items are obtained, the bounding rectangle and unified character encoding of each element item are determined. When it is determined that each element item satisfies the first table line determination condition according to the corresponding bounding rectangle and unified character encoding, the element is determined as a candidate table line element, realizing the recognition of table elements of the Text type in the target document. Moreover, since candidate table lines can be recognized through simple condition determination based on the bounding rectangle and unified character encoding of the Text type element without other complex processes, the recognition of table elements of the Text type in the target document can be achieved simply and efficiently.

[0174] Secondly, for elements of the Path type:

[0175] In an embodiment, the target document is parsed to obtain a set of path type elements in the target document. Here, the table line determination condition corresponding to the path type element is the second table line determination condition, and the second table line determination condition is as follows:

[0176] BBox.Width > a * BBox.Height and BBox.Height < b, and |Path.StartPoint.y - Path.EndPoint.y| < c (horizontal table line); or

[0177] BBox.Height > a * BBox.Width and BBox.Width < b, and |Path.StartPoint.x - Path.EndPoint.x| < c (vertical table line).

[0178] The above Path.StartPoint.x refers to the starting point of the path of the element in the first direction (here the horizontal direction, also called the x-axis direction), Path.EndPoint.x refers to the end point of the path of the element in the first direction, Path.StartPoint.y refers to the starting point of the path of the element in the second direction (here the vertical direction, also called the y-axis direction), and Path.EndPoint.y refers to the end point of the path of the element in the second direction.

[0179] In practical applications, since for a horizontal line, the width of its circumscribed rectangular frame is greater than the height, and for a vertical line, the height of its circumscribed rectangular frame is greater than the width, the above a is a constant greater than 1, and those skilled in the art can set a to 5 according to the current general settings. The above b is a positive number, and those skilled in the art can set b to 5.25 according to the current general settings. In practical applications, the values ​​of a and b can be adjusted according to actual conditions, and this application does not make specific limitations on this.

[0180] The maximum value of c above is the width of the circumscribed rectangular box of the table line. That is to say, for a horizontal table line, |Path.StartPoint.y-Path.EndPoint.y| does not exceed the width of the circumscribed rectangular box of the table line; for a vertical table line, |Path.StartPoint.x-Path.EndPoint.x| does not exceed the width of the circumscribed rectangular box of the table line.

[0181] Specific Figure 3 The process shown implements determining candidate table line elements from a set of path type elements.

[0182] like Figure 3 As shown, the following steps are included:

[0183] Step 301: parse each element in a set of path type elements to obtain a path instruction set in each element.

[0184] Step 302: When it is determined that there are first type instructions but no second type instructions in the path instruction set, determine the bounding rectangle of the element, the path start point and path end point in the first direction, and the path start point and path end point in the second direction.

[0185] The first type of instruction is the LineTo instruction, and the second type of instruction is the BezierTo instruction. The LineTo instruction instructs to move and draw a straight line, and the BezierTo instruction instructs to move and draw a Bezier curve. Then, when the path instruction set of the element is determined to contain the LineTo instruction but not the BezierTo instruction, it can be determined that the element is a straight line, and further it can be determined whether the element is a candidate table line element.

[0186] Step 303: When it is determined that the element meets the second table line determination condition based on the corresponding circumscribed rectangle, the path start point and path end point in the first direction, and the path start point and path end point in the second direction, the element is determined as a candidate table line element.

[0187] Among them, when an element of Path type satisfies BBox.Width > a * BBox.Height and BBox.Height < b, and |Path.StartPoint.y - Path.EndPoint.y| < c, it means that the element may be a horizontal table line; when an element of Path type satisfies BBox.Height > a * BBox.Width and BBox.Width < b, and |Path.StartPoint.x - Path.EndPoint.x| < c, it means that the element may be a vertical table line.

[0188] Figure 3 In the shown process, by parsing each element in the set of elements of Path type, the set of path instructions in each element is obtained. When it is determined that there is a first type of instruction and no second type of instruction in the set of path instructions, the circumscribed rectangle of the element, the path start point and path end point in the first direction, and the path start point and path end point in the second direction are determined. When it is determined that the element meets the second table line determination condition based on the corresponding circumscribed rectangle, the path start point and path end point in the first direction, and the path start point and path end point in the second direction, the element is determined as a candidate table line element, realizing the recognition of table elements of Path type in the target document. Moreover, since the candidate table lines can be recognized by simply making conditional judgments through the circumscribed rectangle of the element of Path type and the path start point and path end point, without other complex processes, it is possible to simply and efficiently recognize table elements of Path type in the target document.

[0189] The tables in the target document can be divided into full-border tables and half-border tables. Among them, full-border tables have lines surrounding the table, including all borders and the dividing lines between cells, such as tables in the shapes of "□", "田", "日", etc. Half-border tables only have some table lines, usually including at least the upper and lower edges of the border, such as double-line tables in the shape of "二", three-line tables in the shape of "三", etc. For this, the process of determining the table area in the candidate table line image based on the set of outer connected regions is described below for full-border tables and half-border tables respectively.

[0190] First, for full-border tables, it can be done through Figure 4The process shown is used to determine the table domain in the candidate table line image according to the set of outer connected domains. Figure 4 As shown, the following steps are included:

[0191] Step 401: Determine the circumscribed rectangular frame of the outer connected domain.

[0192] Step 402: When it is determined that the outer connected domain meets the set first table frame condition according to the outer connected domain circumscribed rectangular frame and the outer connected domain is a closed loop, the outer connected domain circumscribed rectangular frame is determined as a table domain.

[0193] Referring to the definition of the outer connected domain in step 103 above, when the outer connected domain is obviously not in line form and the element corresponding to the outer connected domain is a candidate table line element, the circumscribed rectangular frame of the outer connected domain can be determined as the table domain.

[0194] Specifically, when it is determined that the outer connected domain meets the set first table frame condition according to the circumscribed rectangular frame and the outer connected domain is closed, it is considered that the outer connected domain is obviously not in the form of a line, and the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

[0195] The first table frame condition is that the width and height of the circumscribed rectangular frame of the externally connected domain are both greater than KernelSize. This setting is because in actual applications, if the width and height of the circumscribed rectangular frame are too small, it is likely not a table.

[0196] Furthermore, according to Figure 4 In the case where the illustrated process determines the circumscribed rectangular frame of the outer connected domain as a table domain, it determines that the table identified in the above step 105 is a full-border table.

[0197] Figure 4 The process shown, by determining the circumscribed rectangular frame of the outer connected domain, when it is determined based on the circumscribed rectangular frame that the outer connected domain meets the set first table frame condition, and when it is determined that the outer connected domain is a closed loop, the circumscribed rectangular frame of the outer connected domain is determined as a table domain, so that a table of full-border type can be identified from the target document.

[0198] Secondly, for half-border tables, you can use Figure 5 The process shown is to determine the table domain in the candidate table line image according to the set of outer connected domains. Figure 5 As shown, the following steps are included:

[0199] Step 501: Determine the circumscribed rectangular frame of the outer connected domain.

[0200] Step 502: When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set second table frame condition, the outer connected domain is determined to be a horizontal line connected domain.

[0201] Unlike the closed loop of the external connected domain of a full-border table, the borders on all four sides of a half-border table are missing, so a half-border table corresponds to more than one external connected domain, and because a half-border table usually contains at least the upper and lower edges of the border, such as a double-line table similar to the shape of a "two", a three-line table similar to the shape of a "three", etc., the external connected domain corresponding to the half-border table includes at least two horizontal lines (called horizontal line connected domains). Therefore, when the external connected domain is significantly in the form of lines, that is, when the external connected domain is a horizontal line connected domain, it is considered that the horizontal line external connected domain may be the table line of the half-border table.

[0202] Specifically, when it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set second table frame condition, it is considered that the outer connected domain is obviously in the form of lines, and then the outer connected domain is determined to be a horizontal line connected domain.

[0203] The second table frame condition is: BBox.Width>a*BBox.Height and BBox.Height <b。

[0204] In practical applications, since for a horizontal line, the width of its circumscribed rectangular frame is greater than the height, and for a vertical line, the height of its circumscribed rectangular frame is greater than the width, the above a is a constant greater than 1, and those skilled in the art can set a to 5 according to the current general settings. The above b is a positive number, and those skilled in the art can set b to 5.25 according to the current general settings. In practical applications, the values ​​of a and b can be adjusted according to actual conditions, and this application does not make specific limitations on this.

[0205] Step 503: When it is determined that there are multiple horizontal line connected domains, determine at least one target connected domain group from the multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction is greater than or equal to a set threshold.

[0206] Step 504: Determine the area formed by the horizontal line connected areas at both ends of the target connected area group in the second direction as a table area.

[0207] Referring to the half-border table such as the double-line table in the shape of the character "two" and the three-line table in the shape of the character "three", the half-border table includes at least two horizontal table lines, and the projections of the at least two table lines in the horizontal direction almost overlap. Based on this, in an embodiment of the present application, when multiple horizontal line connected domains are identified, at least one target connected domain group is determined from the multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction (referring to the horizontal direction, also known as the x-axis direction) is greater than or equal to the set threshold. That is to say, the two or more horizontal connected domains in the target connected domain group correspond to more than two horizontal lines in the same half-border table. Further, the area formed by the horizontal line connected domains at both ends in the second direction (here refers to the vertical direction, also known as the y-axis direction) in the target connected domain group (where the horizontal line connected domain at the top corresponds to the upper border of the half-border table, and the horizontal line connected domain at the bottom corresponds to the lower border of the half-border table) can be determined as the table domain.

[0208] In one embodiment, the specific implementation of determining at least one target connected domain group from multiple horizontal line connected domains includes: selecting an ungrouped horizontal line connected domain from multiple horizontal line connected domains as the current horizontal line connected domain, and performing the following processing for each other ungrouped horizontal line connected domain: determining the projection overlap between the horizontal line connected domain and the current horizontal line connected domain in the first direction; if it is determined that the projection overlap is greater than or equal to a set threshold, dividing the horizontal line connected domain and the current horizontal line connected domain into the same target connected domain group; returning to execute the steps of selecting an ungrouped horizontal line connected domain from multiple horizontal line connected domains as the current horizontal line connected domain and the subsequent steps until all horizontal line connected domains are grouped. The above-mentioned set threshold is, for example, 95%. It can be understood that the larger the set threshold, the more accurate the final determination result.

[0209] For example, suppose there are five horizontal connected domains, A, B, C, D, and E. Initially, none of the five horizontal connected domains are grouped, and one of them can be arbitrarily selected as the current horizontal connected domain. Assuming that the horizontal connected domain A is selected as the previous horizontal connected domain, the projection overlap of the horizontal connected domain A and the horizontal connected domain B, the horizontal connected domain A and the horizontal connected domain C, the horizontal connected domain A and the horizontal connected domain D, and the horizontal connected domain A and the horizontal connected domain E in the first direction can be calculated respectively, and the horizontal connected domains whose corresponding projection overlap is greater than or equal to the set threshold are divided into the same target connected domain group as the horizontal connected domain A. Assume that the horizontal connected domain B and the horizontal connected domain A are divided into the same target connected domain group at this time. Then in the next round of grouping, the horizontal connected domain B and the horizontal connected domain A will no longer participate in the grouping, and the above steps will be repeated only for the horizontal connected domains C, D, and E.

[0210] It should be noted here that there is a case where a target connected domain group includes only one horizontal line connected domain. Such a target connected domain group can be directly discarded, that is, excluded from the table.

[0211] It can be seen from the above description that in the embodiment of the present application, when dividing the target connected domain groups, each round of division no longer considers the horizontal line connected domains that have been grouped, so that the calculation time complexity of the embodiment of the present application is O(n). Therefore, even if there are many elements in the target document, the table can be quickly identified.

[0212] In one embodiment, the specific implementation of determining the overlap of the projection of a horizontal line connected domain with the current horizontal line connected domain in the first direction includes: determining the first left boundary horizontal coordinate value and the first right boundary horizontal coordinate value of the circumscribed rectangular box of the horizontal line connected domain, and determining the second left boundary horizontal coordinate value and the second right boundary horizontal coordinate value of the circumscribed rectangular box of the current horizontal line connected domain; determining the intersection length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first right boundary horizontal coordinate value and the second left boundary horizontal coordinate value, and determining the union length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first left boundary horizontal coordinate value and the second right boundary horizontal coordinate value; finally, dividing the intersection length by the union length to obtain the overlap of the projection of the horizontal line connected domain with the current horizontal line connected domain in the first direction.

[0213] The calculation formula for the above specific implementation is as follows:

[0214] Ileft=max(BBox1.left,BBox2.left);

[0215] Iright=min(BBox1.right,BBox2.right);

[0216] Uleft=min(BBox1.left,BBox2.left);

[0217] Uright=max(BBox1.right,BBox2.right);

[0218] Intersect = Iright - Ileft (here, if Intersect < 0, then Intersect = 0);

[0219] Union=Uright-Uleft;

[0220] IoU = Intersect / Union;

[0221] The above BBox1 and BBox2 refer to the external rectangular boxes of two horizontal line connected domains respectively;

[0222] BBox1.left refers to the horizontal coordinate value of the left border of BBox1, and BBox2.left refers to the horizontal coordinate value of the left border of BBox2; BBox1.right refers to the horizontal coordinate value of the right border of BBox1, and BBox2.right refers to the horizontal coordinate value of the left border of BBox2.

[0223] The larger one of the horizontal coordinate values ​​of the left borders of BBox1 and BBox2 is recorded as Ileft, the smaller one of the horizontal coordinate values ​​of the left borders of BBox1 and BBox2 is recorded as Uleft, the smaller one of the horizontal coordinate values ​​of the right borders of BBox1 and BBox2 is recorded as Iright, and the larger one of the horizontal coordinate values ​​of the right borders of BBox1 and BBox2 is recorded as Uright.

[0224] The difference between Iright and Ileft is recorded as Intersect, and if Iright is less than Ileft, that is, the difference between Iright and Ileft is less than 0, then Intersect=0.

[0225] The difference between Uright and Uleft is recorded as Union.

[0226] For ease of understanding, the Figure 6 .like Figure 6 As shown, Union is equivalent to the union of BBox1 and BBox2 in the horizontal direction, Intersect is equivalent to the intersection of BBox1 and BBox2 in the horizontal direction, and the quotient between the two is equivalent to the projection overlap IoU of BBox1 and BBox2 in the horizontal direction.

[0227] Furthermore, according to Figure 5 In the process shown, when the area formed by the horizontal line connected domains at both ends in the second direction in the target connected domain group is determined as a table domain, the table identified in the above step 105 is determined to be a half-border table.

[0228] Figure 5The process shown, by determining the circumscribed rectangular frame of the outer connected domain, when it is determined that the outer connected domain meets the set second table frame condition based on the circumscribed rectangular frame, the outer connected domain is determined as a horizontal line connected domain, when it is determined that there are multiple horizontal line connected domains, at least one target connected domain group is determined from the multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction is greater than or equal to the set threshold, and the area formed by the horizontal line connected domains at both ends in the second direction in the target connected domain group is determined as a table domain, so that a table of half-border type can be recognized from the target document.

[0229] Figure 7 This is a block diagram of an embodiment of a table recognition device provided in an embodiment of the present application. Figure 7 As shown, the device comprises:

[0230] An element parsing module 71 is used to parse the target document to obtain a set of candidate table line elements in the target document;

[0231] A rendering module 72, configured to render each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image;

[0232] A connected domain extraction module 73, used to extract a set of external connected domains in the candidate table line image;

[0233] A table domain determining module 74, configured to determine a table domain in the candidate table line image according to the outer connected domain set;

[0234] The table identification module 75 is used to determine the elements in the document area corresponding to the table field in the target document as a table.

[0235] Optionally, the element parsing module 71 includes:

[0236] A parsing unit, used to parse the target document to obtain a set of different types of elements in the target document;

[0237] The suspected element identification unit is used to determine candidate table line elements from the set of elements of each type by using different table line determination conditions for the sets of elements of different types, so as to obtain a set of candidate table line elements.

[0238] Optionally, the set of elements of different types includes a set of text type elements, and the table line determination condition includes a first table line determination condition;

[0239] The suspected element identification unit is used to determine the candidate table line element from the set of text type elements in the following manner:

[0240] For each element in the set of text type elements, the following processing is performed: splitting the element to obtain multiple element items;

[0241] Determine the bounding rectangle and Unicode of each element;

[0242] When it is determined that each of the element items satisfies the first table line determination condition according to the corresponding circumscribed rectangular frame and the Unicode, the element is determined as a candidate table line element.

[0243] Optionally, the set of elements of different types includes a set of path type elements, and the table line determination condition includes a second table line determination condition;

[0244] The suspected element identification unit is used to determine the candidate table line element from the set of path type elements in the following manner:

[0245] The following processing is performed for each element in the set of path type elements:

[0246] Parsing the element to obtain a path instruction set in the element;

[0247] In the case where it is determined that the first type of instruction exists in the path instruction set and the second type of instruction does not exist, determining the circumscribed rectangular frame of the element, the path start point and the path end point in the first direction, and the path start point and the path end point in the second direction;

[0248] When it is determined that the element satisfies the second table line determination condition based on the corresponding circumscribed rectangular box, the path start point and path end point in the first direction, and the path start point and path end point in the second direction, the element is determined as a candidate table line element.

[0249] Optionally, the rendering module 72 includes:

[0250] A canvas creation unit, used to create a canvas according to the size of the visible area in the target document;

[0251] The circumscribed rectangular frame rendering unit is used to perform the following processing on each candidate table line element in the candidate table line element set:

[0252] Determine the bounding rectangle of the candidate table line element;

[0253] Determining a corresponding area of ​​the candidate table line element in the canvas according to the circumscribed rectangular frame;

[0254] The corresponding area is rendered using the set color value to obtain a candidate table line image.

[0255] Optionally, the connected domain extraction module 73 includes:

[0256] a closing operation unit, used for performing a closing operation on the candidate table line image;

[0257] The extraction unit is used to extract the set of outer connected domains in the candidate table line image after the closing operation.

[0258] Optionally, the closing operation unit is specifically used to:

[0259] Determine a bounding rectangle of each candidate table line element in the candidate table line element set, and determine the shortest side of each of the bounding rectangles;

[0260] Determine the average value of the shortest side of each of the circumscribed rectangular frames;

[0261] A closing operation is performed on the candidate table line image using the average value as a kernel size.

[0262] Optionally, the table domain determination module 74 is specifically used to:

[0263] The following processing is performed for each outer connected domain in the outer connected domain set:

[0264] Determine the circumscribed rectangular frame of the outer connected domain;

[0265] When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set first table frame condition and the outer connected domain is determined to be a closed loop, the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

[0266] Optionally, the device further comprises:

[0267] The table type identification module is used to determine that the corresponding table is a full-border table when the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

[0268] Optionally, the table domain determination module 74 includes:

[0269] An external frame determining unit, used for determining, for each external connected domain in the external connected domain set, an external rectangular frame of the external connected domain;

[0270] a horizontal line connected domain determining unit, configured to determine the outer connected domain as a horizontal line connected domain when it is determined according to the circumscribed rectangular frame that the outer connected domain meets a set second table frame condition;

[0271] a target connected domain group determining unit, configured to determine at least one target connected domain group from the multiple horizontal line connected domains when it is determined that there are multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction is greater than or equal to a set threshold;

[0272] The table domain determining unit is used to determine the area formed by the horizontal line connected domains located at both ends in the first direction in the target connected domain group as a table domain.

[0273] Optionally, the device further comprises:

[0274] The table type identification module is used to determine that the corresponding table is a half-border table when the area formed by the horizontal line connected domains at both ends in the second direction in the target connected domain group is determined as a table area.

[0275] Optionally, the target connected domain group determining unit is specifically configured to:

[0276] Selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as a current horizontal line connected domain;

[0277] For each other horizontal connected domain that is not grouped, perform the following processing:

[0278] Determine the projection overlap between the horizontal line connected domain and the current horizontal line connected domain in the first direction; if it is determined that the projection overlap is greater than or equal to a set threshold, divide the horizontal line connected domain and the current horizontal line connected domain into the same target connected domain group;

[0279] Return to the step of selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as the current horizontal line connected domain and subsequent steps until all horizontal line connected domains are grouped.

[0280] Optionally, the target connected domain group determining unit determines the projection overlap degree of the horizontal line connected domain and the current horizontal line connected domain in the first direction in the following manner:

[0281] Determine a first left boundary horizontal coordinate value and a first right boundary horizontal coordinate value of a circumscribed rectangular frame of the horizontal line connected region;

[0282] Determine a second left boundary horizontal coordinate value and a second right boundary horizontal coordinate value of a circumscribed rectangular frame of the current horizontal line connected domain;

[0283] Determine the intersection length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first right boundary horizontal coordinate value and the second left boundary horizontal coordinate value, and determine the union length of the horizontal line connected domain and the current horizontal line connected domain in the first direction according to the first left boundary horizontal coordinate value and the second right boundary horizontal coordinate value;

[0284] The intersection length is divided by the union length to obtain a projection overlap degree between the horizontal line connected domain and the current horizontal line connected domain in the first direction.

[0285] like Figure 8 As shown, an embodiment of the present application provides an electronic device, including a processor 811, a communication interface 812, a memory 813 and a communication bus 814, wherein the processor 811, the communication interface 812, and the memory 813 communicate with each other through the communication bus 814, and the memory 813 is used to store computer programs;

[0286] In one embodiment of the present application, the processor 811 is used to implement the table recognition method provided by any one of the aforementioned method embodiments when executing the program stored in the memory 813, including:

[0287] Parsing the target document to obtain a set of candidate table line elements in the target document;

[0288] Rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image;

[0289] Extracting a set of outer connected domains in the candidate table line image;

[0290] Determine a table domain in the candidate table line image according to the set of outer connected domains;

[0291] An element in a document area corresponding to the table field in the target document is determined as a table.

[0292] An embodiment of the present application further provides a computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, the steps of the table recognition method provided in any of the aforementioned method embodiments are implemented.

[0293] The device embodiments described above are merely illustrative, wherein the units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0294] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a general hardware platform, and of course, by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the relevant technology can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.

[0295] It should be understood that the terms used herein are only for the purpose of describing specific example embodiments and are not intended to be limiting. Unless the context clearly indicates otherwise, the singular forms "one", "an" and "said" as used herein may also be meant to include plural forms. The terms "include", "comprise", "contain", and "have" are inclusive, and therefore specify the existence of stated features, steps, operations, elements and / or parts, but do not exclude the existence or addition of one or more other features, steps, operations, elements, parts, and / or combinations thereof. The method steps, processes, and operations described herein are not interpreted as necessarily requiring them to be performed in the specific order described or illustrated, unless the execution order is clearly indicated. It should also be understood that additional or alternative steps may be used.

[0296] The foregoing is merely a specific embodiment of the present invention, which enables those skilled in the art to understand or implement the present invention. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present invention. Therefore, the present invention will not be limited to the embodiments shown herein, but rather to the widest scope consistent with the principles and novel features claimed herein.

Claims

1. A table recognition method, characterized in that: The method comprises: Parsing the target document to obtain a set of candidate table line elements in the target document; Rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image; Extracting a set of outer connected domains in the candidate table line image; Determine a table domain in the candidate table line image according to the set of outer connected domains; An element in a document area corresponding to the table field in the target document is determined as a table.

2. The method according to claim 1, characterized in that The step of parsing the target document to obtain a set of candidate table line elements in the target document includes: Parsing the target document to obtain a set of different types of elements in the target document; For the sets of elements of different types, different table line determination conditions are respectively used to determine candidate table line elements from the sets of elements of each type, thereby obtaining a set of candidate table line elements.

3. The method according to claim 2, characterized in that The set of different types of elements includes a set of text type elements, and the table line determination condition includes a first table line determination condition; Determining the candidate table line element from the set of text type elements is achieved by: For each element in the set of text type elements, the following processing is performed: splitting the element to obtain multiple element items; Determine the bounding rectangle and Unicode of each element; When it is determined that each of the element items satisfies the first table line determination condition according to the corresponding circumscribed rectangular frame and the Unicode, the element is determined as a candidate table line element.

4. The method according to claim 2, characterized in that: The set of different types of elements includes a set of path type elements, and the table line determination condition includes a second table line determination condition; Determining a candidate table line element from the set of path type elements is achieved by: The following processing is performed for each element in the set of path type elements: Parsing the element to obtain a path instruction set in the element; In the case where it is determined that the first type of instruction exists in the path instruction set and the second type of instruction does not exist, determining the circumscribed rectangular frame of the element, the path start point and the path end point in the first direction, and the path start point and the path end point in the second direction; When it is determined that the element satisfies the second table line determination condition based on the corresponding circumscribed rectangular box, the path start point and path end point in the first direction, and the path start point and path end point in the second direction, the element is determined as a candidate table line element.

5. The method according to claim 1, characterized in that The step of rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image includes: Creating a canvas according to the size of the visible area in the target document; The following processing is performed for each candidate table line element in the candidate table line element set: Determine the bounding rectangle of the candidate table line element; Determining a corresponding area of ​​the candidate table line element in the canvas according to the circumscribed rectangular frame; The corresponding area is rendered using the set color value to obtain a candidate table line image.

6. The method according to claim 1, characterized in that The step of extracting a set of outer connected domains in the candidate table line image comprises: Performing a closing operation on the candidate table line image; Extract the set of outer connected domains in the candidate table line image after the closing operation.

7. The method according to claim 6, characterized in that The performing a closing operation on the candidate table line image includes: Determine a bounding rectangle of each candidate table line element in the candidate table line element set, and determine the shortest side of each of the bounding rectangles; Determine the average value of the shortest side of each of the circumscribed rectangular frames; A closing operation is performed on the candidate table line image using the average value as a kernel size.

8. The method according to claim 1, characterized in that The step of determining a table domain in the candidate table line image according to the set of outer connected domains includes: The following processing is performed for each outer connected domain in the outer connected domain set: Determine the circumscribed rectangular frame of the outer connected domain; When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set first table frame condition and the outer connected domain is determined to be a closed loop, the circumscribed rectangular frame of the outer connected domain is determined as a table domain.

9. The method according to claim 1, characterized in that: The step of determining a table domain in the candidate table line image according to the set of outer connected domains includes: The following processing is performed for each outer connected domain in the outer connected domain set: Determine the circumscribed rectangular frame of the outer connected domain; When it is determined according to the circumscribed rectangular frame that the outer connected domain meets the set second table frame condition, the outer connected domain is determined to be a horizontal line connected domain; In the case where it is determined that there are multiple horizontal line connected domains, determining at least one target connected domain group from the multiple horizontal line connected domains, wherein the projection overlap of two or more horizontal line connected domains in the target connected domain group in the first direction is greater than or equal to a set threshold; An area formed by horizontal line connected areas at both ends in the second direction in the target connected area group is determined as a table area.

10. The method according to claim 9, characterized in that The step of determining at least one target connected domain group from the plurality of horizontal line connected domains comprises: Selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as a current horizontal line connected domain; For each other horizontal connected domain that is not grouped, perform the following processing: Determine the projection overlap between the horizontal line connected domain and the current horizontal line connected domain in the first direction; if it is determined that the projection overlap is greater than or equal to a set threshold, divide the horizontal line connected domain and the current horizontal line connected domain into the same target connected domain group; Return to the step of selecting an ungrouped horizontal line connected domain from the multiple horizontal line connected domains as the current horizontal line connected domain and subsequent steps until all horizontal line connected domains are grouped.

11. A table recognition device, characterized in that: The device comprises: An element parsing module, used to parse the target document to obtain a set of candidate table line elements in the target document; A rendering module, used for rendering each candidate table line element in the candidate table line element set to the same canvas to obtain a candidate table line image; A connected domain extraction module, used to extract a set of outer connected domains in the candidate table line image; A table domain determination module, used for determining a table domain in the candidate table line image according to the outer connected domain set; The table identification module is used to determine the elements in the document area corresponding to the table field in the target document as a table.