Table reconstruction method and device, storage medium and electronic device
By detecting table area boundaries and lines in the table reconstruction method, and searching for cell position information along the target direction, the problems of high complexity and low efficiency in table reconstruction in the existing technology are solved, and more efficient table reconstruction is achieved. .
Patent Information
- Application Number
- CN202110867193.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-29
- Publication Date
- 2024-09-24
- Estimated Expiration
- 2041-07-29
AI Technical Summary
Table reconstruction methods in the prior art have high computational complexity and low efficiency, especially when processing tables with complex merged cell styles.
By performing table detection on the document to be reconstructed, the area boundaries and table lines of the table area are obtained, and cell searches are performed along the target direction in the table area to obtain the position information of the cells, and then the table is reconstructed, reducing the intersection point. Dependence on contour detection and coordinate sorting.
It effectively reduces the computational complexity of table reconstruction and improves the efficiency of table reconstruction, especially when processing complex tables.
Smart Images

Figure CN113486638B
Abstract
Description
Technical Field
[0001] The present application relates to the field of communications, and in particular, to a table reconstruction method and device, a storage medium, and an electronic device. Background Art
[0002] Currently, many companies are migrating to smart offices, and many paper document data need to be digitized. Forms are an important part of documents, and form digitization is closely related to form reconstruction.
[0003] The table reconstruction method provided in the related art is: obtain the table image to be reconstructed; segment the table image to be reconstructed to obtain the first table line and the second table line; obtain the intersection points of the first table line and the second table line; obtain the intersection point coordinates corresponding to each intersection point; and connect the corresponding intersection points according to the intersection point coordinates to reconstruct the table.
[0004] For the above table reconstruction method, after obtaining the horizontal and vertical lines of the table, the intersection outline is detected, and after the intersection is determined, it is sorted according to the intersection coordinates, which has high computational complexity. At the same time, the reconstruction logic for tables with complex merged cell styles will be more complicated.
[0005] It can be seen that the method of reconstructing a table based on table lines in the related art has the problems of high computational complexity and low table reconstruction efficiency. Summary of the invention
[0006] Embodiments of the present application provide a table reconstruction method and device, a storage medium, and an electronic device to at least reduce the computational complexity of table reconstruction based on table lines and improve table reconstruction efficiency.
[0007] According to one aspect of an embodiment of the present application, a method for reconstructing a table is provided, comprising: performing table detection on a document to be reconstructed to obtain area boundaries of a table area in the document to be reconstructed, and table lines within the table area; based on the area boundaries and the table lines, performing a cell search along a target direction within the table area to obtain position information of each cell within the table area, wherein the target direction includes a first direction parallel to a target area boundary of the table area, and a second direction perpendicular to the target area boundary; performing table reconstructing according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0008] In an exemplary embodiment, based on the area boundary and the table line, a cell search is performed within the table area along the target direction to obtain the position information of each cell within the table area, including: based on the area boundary and the table line, a cell search is performed within the table area along the target direction to obtain the target vertices of each cell, wherein the relative positions of the target vertices of each cell in each cell are the same; based on the area boundary and the table line, a cell boundary search is performed within the table area along the target direction with the target vertices of each cell as the starting point to obtain the position information of each cell.
[0009] In an exemplary embodiment, based on the area boundary and the table line, performing a cell search along the target direction within the table area to obtain the target vertices of each cell includes: based on the area boundary and the table line, searching for target vertices of adjacent cells along the target direction within the table area to obtain the target vertices of each cell.
[0010] In an exemplary embodiment, based on the area boundary and the table line, searching for target vertices of adjacent cells along the target direction within the table area to obtain the target vertices of each cell includes: based on the area boundary and the table line, starting from the target vertex of the first cell, searching for target vertices of adjacent cells along the target direction to obtain the target vertex of the second cell, wherein the first cell is the first cell searched and the second cell is an adjacent cell of the first cell; adding the target vertex of the second cell to a search queue; extracting the target vertices of cells from the search queue in sequence as the target vertex of the current cell to perform the following steps until the search queue is empty: based on the area boundary and the table line, starting from the target vertex of the current cell, searching for target vertices of adjacent cells along the target direction to obtain target vertices of adjacent cells of the current cell; if the adjacent cells of the current cell have not been searched for the target vertices of adjacent cells, adding the target vertices of the adjacent cells of the current cell to the search queue.
[0011] In an exemplary embodiment, based on the area boundary and the table line, the target vertex of the adjacent cell is searched along the target direction with the target vertex of the current cell as the starting point, and the target vertex of the adjacent cell of the current cell is obtained, including: searching the area boundary and the table line along the target direction with the target vertex of the current cell as the starting point, and searching for a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction; when the target boundary is not the area boundary, determining a candidate vertex in a third cell adjacent to the current cell in the target direction, wherein the candidate vertex is a point obtained by offsetting the reference point by a target distance along the target direction; when the distance between the candidate vertex and the cell boundary of the third cell is less than or equal to a target distance threshold, determining the candidate vertex as the target vertex of the third cell.
[0012] In an exemplary embodiment, reconstructing a table according to the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed includes: determining the cell size of each cell and the minimum cell size among the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the size of the smallest cell in the table area; determining the reconstructed size of each cell according to the cell size of each cell and the minimum cell size, wherein the reconstructed size of each cell is used to indicate the number of the minimum cells occupied by each cell in the reconstructed table; reconstructing the table according to the position information of each cell and the reconstructed size of each cell to obtain the reconstructed table corresponding to the document to be reconstructed.
[0013] In an exemplary embodiment, reconstructing a table according to the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed includes: reconstructing a table according to the search order of each cell and the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed.
[0014] According to another aspect of an embodiment of the present application, a table reconstruction device is also provided, including: a detection unit, used to perform table detection on a document to be reconstructed, and obtain the area boundary of a table area in the document to be reconstructed, and the table lines within the table area; a search unit, used to perform a cell search along a target direction within the table area based on the area boundary and the table lines, and obtain position information of each cell within the table area, wherein the target direction includes a first direction parallel to the target area boundary of the table area, and a second direction perpendicular to the target area boundary; a reconstruction unit, used to reconstruct the table according to the position information of each cell, and obtain a reconstructed table corresponding to the document to be reconstructed.
[0015] In an exemplary embodiment, the search unit includes: a first search module, used to perform a cell search within the table area along the target direction based on the area boundary and the table line to obtain the target vertices of each cell, wherein the relative positions of the target vertices of each cell in each cell are the same; and a second search module, used to perform a cell boundary search within the table area along the target direction based on the area boundary and the table line with the target vertices of each cell as the starting point to obtain the position information of each cell.
[0016] In an exemplary embodiment, the first search module includes: a search submodule for searching for target vertices of adjacent cells along the target direction within the table area based on the area boundary and the table line to obtain the target vertices of each cell.
[0017] In an exemplary embodiment, the search submodule includes: a search subunit, which is used to search for target vertices of adjacent cells along the target direction based on the area boundary and the table line, starting from the target vertex of the first cell, to obtain the target vertex of the second cell, wherein the first cell is the first cell to be searched and the second cell is the adjacent cell of the first cell; an adding subunit, which is used to add the target vertex of the second cell to a search queue; an executing subunit, which is used to extract the target vertices of cells from the search queue in sequence as the target vertex of the current cell and perform the following steps until the search queue is empty: based on the area boundary and the table line, searching for target vertices of adjacent cells along the target direction starting from the target vertex of the current cell, to obtain the target vertices of adjacent cells of the current cell; if the adjacent cells of the current cell have not been searched for the target vertices of the adjacent cells, the target vertices of the adjacent cells of the current cell are added to the search queue.
[0018] In an exemplary embodiment, the execution subunit includes: a search subunit, which is used to search the area boundary and the table line along the target direction with the target vertex of the current cell as the starting point, and search for a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction; a first determination subunit, which is used to determine, when the target boundary is not the area boundary, a candidate vertex in a third cell adjacent to the current cell in the target direction, wherein the candidate vertex is a point obtained by offsetting the reference point by a target distance along the target direction; and a second determination subunit, which is used to determine the candidate vertex as the target vertex of the third cell when the distance between the candidate vertex and the cell boundary of the third cell is less than or equal to a target distance threshold.
[0019] In an exemplary embodiment, the reconstruction unit includes: a first determination module, used to determine the cell size of each cell and the minimum cell size of the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the size of the minimum cell in the table area; a second determination module, used to determine the reconstructed size of each cell according to the cell size of each cell and the minimum cell size, wherein the reconstructed size of each cell is used to indicate the number of the minimum cells occupied by each cell in the reconstructed table; a first reconstruction module, used to reconstruct the table according to the position information of each cell and the reconstructed size of each cell, to obtain the reconstructed table corresponding to the document to be reconstructed.
[0020] In an exemplary embodiment, the reconstruction unit includes: a second reconstruction module, configured to reconstruct a table according to the search order of each cell and the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed.
[0021] According to another aspect of the embodiments of the present application, a computer-readable storage medium is provided, in which a computer program is stored, wherein the computer program is configured to execute the above table reconstruction method when running.
[0022] According to another aspect of an embodiment of the present application, there is also provided an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the table reconstruction method through the computer program.
[0023] In an embodiment of the present application, a method of converting a table structure into a cell traversal and parsing along a specific direction is adopted. By performing table detection on the document to be reconstructed, the area boundary of the table area in the document to be reconstructed and the table lines in the table area are obtained; based on the area boundary and the table line, a cell search is performed in the table area along a target direction to obtain the position information of each cell in the table area, wherein the target direction includes a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary; the table is reconstructed according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed. Since the cell traversal and parsing are performed along a specific direction in the detected table area, the position information of each cell can be determined based on the area boundary and the table line, and there is no need to perform operations such as detecting the intersection contour and sorting according to the intersection coordinates. The technical effect of reducing the computational complexity of the algorithm and improving the efficiency of table reconstruction can be achieved, thereby solving the problems of high computational complexity and low table reconstruction efficiency in the method of performing table reconstruction based on table lines in the related art. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.
[0025] In order to more clearly illustrate the embodiments of the present application 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.
[0026] Figure 1 is a schematic diagram of a hardware environment of an optional table reconstruction method according to an embodiment of the present application;
[0027] Figure 2 is a flowchart of an optional table reconstruction method according to an embodiment of the present application;
[0028] Figure 3 is a schematic diagram of an optional table reconstruction method according to an embodiment of the present application;
[0029] Figure 4 is a schematic diagram of another optional table reconstruction method according to an embodiment of the present application;
[0030] Figure 5 is a schematic diagram of an optional search binary tree according to an embodiment of the present application;
[0031] Figure 6is a flowchart of another optional table reconstruction method according to an embodiment of the present application;
[0032] Figure 7 is a structural block diagram of an optional table reconstruction device according to an embodiment of the present application;
[0033] Figure 8 It is a structural block diagram of an optional electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0034] In order to enable those skilled in the art to better understand the solution of the present application, 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 only 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 creative work should fall within the scope of protection of the present application.
[0035] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments of the present application described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0036] According to one aspect of an embodiment of the present application, a table reconstruction method is provided. Optionally, in this embodiment, the table reconstruction method can be applied to Figure 1 In the hardware environment composed of the terminal 102 and the server 104 shown in FIG. Figure 1 As shown, the server 104 is connected to the terminal 102 via a network, and can be used to provide services (such as application services, etc.) for the terminal or a client installed on the terminal. A database can be set on the server or independently of the server to provide data storage services for the server 104.
[0037] The above network may include but is not limited to at least one of the following: wired network, wireless network. The above wired network may include but is not limited to at least one of the following: wide area network, metropolitan area network, local area network, and the above wireless network may include but is not limited to at least one of the following: WIFI (Wireless Fidelity), Bluetooth. The terminal 102 may not be limited to a PC (Personal Computer), a mobile phone, a tablet computer, etc.
[0038] The table reconstruction method of the embodiment of the present application can be executed by the server 104, or by the terminal 102, or by both the server 104 and the terminal 102. The terminal 102 can also execute the table reconstruction method of the embodiment of the present application by a client installed thereon.
[0039] Taking the table reconstruction method in this embodiment executed by the server 104 as an example, Figure 2 is a flow chart of an optional table reconstruction method according to an embodiment of the present application, such as Figure 2 As shown, the process of the method may include the following steps:
[0040] Step S202 , performing table detection on the document to be reconstructed to obtain the region boundary of the table region in the document to be reconstructed and the table lines in the table region.
[0041] The table reconstruction method in this embodiment can be applied to the scenario of reconstructing a corresponding table for a table area in a document. The document that needs to reconstruct the corresponding table area is the document to be reconstructed, that is, the document to be reconstructed with the corresponding table. The above-mentioned document to be reconstructed can be in a variety of formats, such as PDF (Portable Document Format), image, or other document formats that can contain a table area. In this embodiment, the document format of the document to be reconstructed is not limited.
[0042] A target client with a table reconstruction function may be run on the target terminal, and a document to be reconstructed, i.e., a document to be reconstructed, may be selected through the target client. The target client may directly perform a table reconstruction operation on the document to be reconstructed, or may send the document to be reconstructed to the backend server through a communication connection with the backend server, and the backend server may perform the table reconstruction operation. In this embodiment, the table reconstruction operation performed by the backend server is taken as an example for description.
[0043] The server (i.e., the backend server) may obtain the document to be reconstructed, perform table detection on the document to be reconstructed, and obtain the region boundary of the table region in the document to be reconstructed, and the table lines in the table region. For example, the backend server may process the document to be reconstructed based on deep learning technology or morphology to obtain the table region and table lines of the document to be reconstructed.
[0044] Optionally, after detecting the table area and table lines of the document to be reconstructed, the area boundaries and table lines of the table area in the document to be reconstructed can be set to a first color (for example, white), and other positions in the document to be reconstructed except the area boundaries and table lines of the table area can be set to a second color (for example, black), so that it can be determined whether the area boundaries or table lines are searched based on the searched color.
[0045] For example, the document to be reconstructed is an image to be reconstructed. After the table is detected in the image to be reconstructed, the detected table area and table lines can be set to white, and other positions can be set to black, so as to obtain the following: Figure 3 The image area shown.
[0046] Step S204, based on the area boundary and the table line, perform a cell search along the target direction in the table area to obtain the position information of each cell in the table area, wherein the target direction includes a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary.
[0047] Based on the region boundary and the table line, the server can search for cells along a target direction in the table region. The target direction can include a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary, that is, the second direction perpendicular to the first direction.
[0048] For example, the target area boundary may be the upper boundary (or lower boundary) of the table area, the first direction is the horizontal left direction (or the horizontal right direction), and the second direction is the vertical upward direction (or the vertical downward direction). For another example, the target area boundary may be the left boundary (or the right boundary) of the table area, the first direction is the vertical upward direction (or the vertical downward direction), and the second direction is the horizontal left direction (or the horizontal right direction).
[0049] When searching for a cell, you can start the search from a position point (search starting point) in the table area. The search starting point can be a table vertex in the table area. For example, the upper left corner of the table area can be used as the search cell vertex. In order to avoid the influence of line width, the table vertex may not be a strict table vertex (that is, not the intersection of the area boundary), but a point located in the table area and at a target distance from the target vertex of the table area. For example, Figure 3 As shown, the starting point of the search cell can be a point that is moved a short distance to the lower right from the vertex of the upper left corner of the table area and has no white pixel values around it.
[0050] Starting from the search starting point, the server can search for cells along the first direction. If a region boundary or table line is found, it can be determined that the boundary of the current cell has been found. The server can also search for cells along the second direction. If a region boundary or table line is found, it can be determined that the boundary of the current cell has been found. Based on the searched cell boundary, the location information of the current cell can be determined.
[0051] In addition to searching cells starting from table vertices, you can also search cells starting from any point in the table area in four directions (the first direction includes two opposite directions, and the second direction also includes two opposite directions), thereby determining the four boundaries of the current cell.
[0052] After searching the location area of the current cell, the boundary of the adjacent cell of the current cell can be searched along the target direction based on the area boundary and the table line. The search starting point is updated to a point in the adjacent cell. The search starting point of the adjacent cell can be determined based on the search starting point of the current cell. For example, if the adjacent cell is adjacent to the current cell in the first direction, the search starting point of the adjacent cell is the point obtained after searching the table line along the first direction from the search starting point of the current cell and then offsetting a short distance along the first direction.
[0053] It should be noted that, in order to avoid searching cells that have been searched, it is possible to determine whether the cell to be searched has been searched based on the position information of the searched cells, thereby improving the efficiency of cell search.
[0054] Optionally, the cell search may be performed in a progressive manner, for example, searching the adjacent cells of the cell along the target direction, and then searching the adjacent cells of the adjacent cells along the target direction until all cells have been searched. The cell search may be performed in a random manner, for example, randomly selecting a position point in an unsearched table area, searching the boundary of the cell where the position point is located along the target direction, determining the position area of the cell, updating the unsearched table area, and reselecting a position point for search until the unsearched table area is empty.
[0055] It should be noted that the cell search along the target direction in the table area may be the search for the cell boundary along the target direction. When searching for cells, the cell boundary may be searched along the first direction and the second direction respectively, or the cell boundary may be searched along the first direction and the second direction simultaneously. The cell search along the target direction in the table area may be the search for the adjacent cells of the cell along the target direction. When searching for cells, the adjacent cells of the cell may be searched along the first direction and the second direction respectively, or the adjacent cells of the cell may be searched along the first direction and the second direction simultaneously, which is not limited in the present embodiment.
[0056] Step S206 , reconstructing the table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0057] After obtaining the position information of all cells, the server can reconstruct the table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed, or in other words, a reconstructed table corresponding to the table area of the document to be reconstructed. There are many ways to reconstruct the table based on the position information of each cell, including but not limited to determining the number and position of table cells occupied by each cell based on the aspect ratio of the cell, and then reconstructing the table.
[0058] Optionally, in addition to reconstructing the table, the text information in each cell can be written into the corresponding cell in the reconstructed table. For example, each cell image can be detected by pixel projection or deep learning methods to determine the position of the text line in each cell image, and the text line is recognized by a recognition network such as CRNN (Convolutional Recurrent Neural Network) to obtain a recognition result. Combining the recognition results and table structure information, the table can be reconstructed according to user needs to generate output files such as Excel (an office software).
[0059] The output table file can be saved locally on the server, or in a database connected to the server, or sent to the target terminal for saving or display. If the target terminal reconstructs the table, the reconstructed table file can be displayed on the display interface of the terminal, or saved locally on the terminal, or sent to the server for saving, which is not limited in this embodiment.
[0060] Through the above steps, a table is detected on the document to be reconstructed to obtain the area boundary of the table area in the document to be reconstructed and the table lines in the table area; based on the area boundary and the table lines, a cell search is performed along the target direction in the table area to obtain the position information of each cell in the table area, wherein the target direction includes a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary; a table is reconstructed according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed, which solves the problems of high computational complexity and low table reconstruction efficiency in the method of performing table reconstruction based on table lines in the related art, reduces the computational complexity of the algorithm, and improves the table reconstruction efficiency.
[0061] In an exemplary embodiment, based on the region boundary and the table line, searching for cells along the target direction in the table region to obtain the position information of each cell in the table region includes:
[0062] S11, based on the region boundary and the table line, searching for cells along the target direction in the table region to obtain target vertices of each cell, wherein the relative positions of the target vertices of each cell in each cell are the same;
[0063] S12, based on the region boundary and the table line, a cell boundary search is performed along the target direction in the table region with the target vertex of each cell as the starting point to obtain the position information of each cell.
[0064] When searching for cells, you can first search for vertices of each cell based on the region boundaries and table lines. The searched vertices can be vertices at the same position of each cell, for example, the vertex at the upper left corner, the vertex at the lower left corner, the vertex at the upper right corner, and the vertex at the lower right corner. The cells in the table are generally square and have four vertices. Based on the properties of the cells and the region boundaries and table lines in the table area, the target vertex of each cell can be searched when searching along the target direction starting from the target vertex of other cells.
[0065] For the target vertex of each cell, the server can perform a cell boundary search along the target direction in the table area based on the area boundary and the table line, starting from the target vertex of each cell, to determine the boundary of each cell, and then obtain the location information of each cell.
[0066] It should be noted that searching for the target vertex of each cell and searching for the boundary of each cell can be performed serially, that is, after searching for the target vertices of all cells, searching for the boundary of each cell, or they can be performed in parallel, for example, searching for the boundary of the current cell starting from the target vertex of the current cell to obtain the position information of the current cell, and also the target vertices of the adjacent cells of the current cell can be obtained.
[0067] For example, for Figure 3 A table with complex cell merging styles, as shown in Figure 4 A search process for cells in the table is shown in FIG. Figure 4 In , each number represents the cell number of the cell. The cell boundary can be searched rightward (an example of the first direction) and downward (an example of the second direction) from the upper left corner of the table (an example of the target vertex), thereby obtaining the position information of each cell.
[0068] When searching for a cell, the current cell is Figure 3 The search operation for cell No. 1 in the table is as follows: search for white pixels to the right with the upper left corner of the table as the search cell vertex to find the right boundary of the cell, search for white pixels downward to find the lower boundary of the cell, and thus obtain the location information of cell No. 1; then search for adjacent cells to the right and downward with cell No. 1 as the reference, that is, Figure 4 Cells 2 and 6 in .
[0069] The search vertex of cell 2 is a point offset from the upper left corner of the cell to the lower right, which can be inferred from the coordinates of the upper right vertex of cell 1. Repeat the above cell search steps to obtain the location information of cell 2. Similarly, traverse cell 6 adjacent to cell 1, and the search vertex of cell 6 can be inferred from the coordinates of the lower left vertex of cell 1.
[0070] It should be noted that Figure 4 The cell numbers in the table are only for the convenience of description. During the search process, the server can number the searched cells. The numbers of all cells can be obtained after the table area search is completed.
[0071] Through this embodiment, by determining the vertices at the same position of each cell and determining the position information of the cell with the determined vertices as the starting point, the convenience of determining the position information can be improved.
[0072] In an exemplary embodiment, based on the region boundary and the table line, a cell search is performed along the target direction in the table region to obtain the target vertex of each cell, including:
[0073] S21, based on the region boundary and the table line, searching for target vertices of adjacent cells along the target direction in the table region to obtain the target vertices of each cell.
[0074] Based on the characteristics of the table, the target vertex of each cell can be searched at least when searching along the target direction starting from the target vertex of one of its adjacent cells. The server can search along the target direction starting from the target vertex of one cell. If the region boundary is searched, it can be determined that the cell has no adjacent cells in the target direction. If the table line is searched, it can be determined that the cell has adjacent cells in the target direction.
[0075] If a table line is found, the server can continue searching along the target direction to determine whether the target vertex of the adjacent cell of the cell is found. If found, the target vertex of the adjacent cell can be recorded. After searching the target vertices of the adjacent cells of all cells, the server can obtain the target vertex of each cell.
[0076] Through this embodiment, by searching for vertices of adjacent cells along the target direction, the complexity of the search can be reduced and the efficiency of the vertex search can be improved.
[0077] In an exemplary embodiment, based on the region boundary and the table line, searching for target vertices of adjacent cells along the target direction in the table region to obtain the target vertices of each cell includes:
[0078] S31, based on the region boundary and the table line, starting from the target vertex of the first cell, searching for the target vertex of the adjacent cells along the target direction, to obtain the target vertex of the second cell, wherein the first cell is the first searched cell, and the second cell is the adjacent cell of the first cell;
[0079] S32, adding the target vertex of the second cell to the search queue;
[0080] S33, extract the target vertices of the cells from the search queue in sequence as the target vertex of the current cell and perform the following steps until the search queue is empty: based on the region boundary and the table line, search for the target vertices of the adjacent cells along the target direction with the target vertex of the current cell as the starting point to obtain the target vertices of the adjacent cells of the current cell; if the adjacent cells of the current cell have not been searched for the target vertices of the adjacent cells, add the target vertices of the adjacent cells of the current cell to the search queue.
[0081] When searching for the target vertex of a cell, the server can first determine the target vertex of the first searched cell, that is, the target vertex of the first cell; then, based on the area boundary and the table line, start from the target vertex of the first cell and search for the target vertex of the adjacent cells along the target direction to obtain the target vertex of the second cell, and add the target vertex grid of the second cell to the search queue.
[0082] The second cell is a cell adjacent to the first cell in the target direction, and the target direction includes the first direction and the second direction. The second cell may include at least one of the following: a cell adjacent to the first cell in the first direction, and a cell adjacent to the first cell in the second direction.
[0083] For the target vertices of the cells in the search queue, the server may sequentially extract the target vertices of the cells from the search queue as the target vertices of the current cell, search for the target vertices of the adjacent cells of the current cell, and add the target vertices of the adjacent cells of the searched target vertices to the search queue until the search queue is empty.
[0084] When performing a search, the server can search for the target vertices of the adjacent cells along the target direction starting from the target vertex of the current cell based on the region boundary and the table line to obtain the target vertices of the adjacent cells of the current cell. If the adjacent cells of the current cell have not been searched for the target vertices of the adjacent cells, the target vertices of the adjacent cells of the current cell can be added to the search queue.
[0085] For example, for Figure 4 In the search process shown, after searching cell No. 2 and cell No. 6, cell No. 2 and cell No. 6 (the search vertices, which are also target vertices) can be added to the search queue, and the search vertex information (that is, the information of the search vertices that have been searched) can also be recorded to avoid repeated searches.
[0086] At this point, there are cells 2 and 6 in the search queue. Repeat the adjacent cell search steps and search for the upper right and lower left adjacent cells of cell 2, which are cells 5 and 3 respectively. Then, the upper right adjacent cell of cell 6, that is, cell 7, is searched and added to the search queue. Since the table frame boundary has been reached when searching for the lower left adjacent cell of cell 6, the search is stopped.
[0087] Then, based on cells 5, 3, and 7 in the search queue, continue searching for their adjacent cell positions, and stop when the coordinates exceed the table border. The cell adjacent to the lower left of cell 3 is cell 8, and the cell adjacent to the upper right of cell 7 is also cell 8. Since cell 8 has been added to the search queue when searching for cell 3, when cell 8 is searched again during the process of searching for cells adjacent to cell 7, it is found that the search vertex of the cell has been visited, so the cell is skipped.
[0088] Optionally, since the search vertex of cell No. 8 calculated based on the coordinates of cell No. 3 and the search vertex of cell No. 8 calculated based on the coordinates of cell No. 7 are not necessarily completely consistent during the search, a certain error redundancy can be set to determine whether they are the same vertex.
[0089] Through this embodiment, the efficiency of cell search can be improved by recording the adjacent cells that have searched the target vertex and have not been searched in the search queue.
[0090] In an exemplary embodiment, based on the region boundary and the table line, starting from the target vertex of the current cell, searching for the target vertex of the adjacent cell along the target direction, and obtaining the target vertex of the adjacent cell of the current cell includes:
[0091] S41, starting from the target vertex of the current cell, searching for the region boundary and the table line along the target direction, and searching for a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction;
[0092] S42, when the target boundary is not a region boundary, determining a candidate vertex in a third cell adjacent to the current cell in the target direction, wherein the candidate vertex is a point obtained by offsetting the reference point along the target direction by a target distance;
[0093] S43: When the distance between the candidate vertex and the cell boundary of the third cell is less than or equal to the target distance threshold, determine the candidate vertex as the target vertex of the third cell.
[0094] When searching for the target vertex of the adjacent cell, the target vertex of the current cell can be used as the starting point to search the boundary of the current cell along the target direction, that is, at least one of the region boundary and the table line, and the searched boundary is the target boundary. Since the boundary search is performed from a point along a direction, what is found is a point on the target boundary, that is, a reference point on the target boundary.
[0095] If the target boundary is not a region boundary, it can be determined that there is a cell adjacent to the current cell along the target direction, and the adjacent cell is the third cell. The server can determine that the point after the above reference point is offset by a certain distance along the target direction is a candidate vertex of the third cell. For the searched adjacent cells, the server can determine the target vertex of all searched adjacent cells. For example, if the adjacent cell is searched along the first direction, the server can use the candidate vertex as the starting point and search in the opposite direction of the second direction until the boundary of the third cell (i.e., at least one of the region boundary and the table line) is searched. Then the point obtained after the searched boundary point is offset by the target distance along the second direction is determined as the target vertex of the third cell.
[0096] Optionally, the target vertex of each cell can be searched when searching along the target direction starting from the target vertex of one of its adjacent cells. In order to reduce the complexity of cell search, the third cell can be added to the search queue only when the candidate vertex is the target vertex of the third cell.
[0097] The server may determine the distance between the candidate vertex and the cell boundary of the third cell. If the distance between the candidate vertex and the cell boundary of the third cell is less than or equal to the target distance threshold, the candidate vertex may be determined as the target vertex of the third cell, and the target vertex grid of the third cell is added to the search queue; otherwise, the third cell is ignored. Optionally, the target distance threshold is a pre-configured distance threshold that is greater than or equal to the target distance.
[0098] For example, Figure 4 As shown in the figure, when searching for the vertices of adjacent cells to the right and downward from the vertex of a cell, it is necessary to determine whether the vertex is an inner point of the cell before determining the search vertex. Taking cell No. 4 as an example, the vertex of the adjacent cell to the upper right is Figure 4Point A in the figure. Point A is not the real starting point of the cell, but the inner point of cell 5. Before adding the point to the search queue, you need to confirm whether there is a white pixel within a short distance upward from the point. If there is, it means that there is a table line above the point, and the point is a vertex of a new cell and can be added to the search queue; if not, it means that the point is an inner point of the cell and cannot be used as a search vertex for a new cell, so it should be discarded.
[0099] Similarly, search for the lower left vertex of cell 4. Figure 4 When judging whether point B is an inner point, it is necessary to confirm whether there is a white pixel within a short distance to the left of the point, that is, the table line. If there is, the point can be added to the search queue. If not, it is discarded. In the process of confirming whether there is a white pixel upward or left, it stops when encountering the table border. If there is still no white pixel when encountering the table border upward or left, the point can be added to the search queue.
[0100] By analogy, the above steps are repeated. After the cell searches for the position information, the search vertex of the cell is deleted from the search queue. The search process stops when the search queue is empty. The search method described above can be represented by a binary tree. An exemplary search binary tree is as follows: Figure 5 Assume that the width and height of the table are M and N respectively. The time complexity of the cell structure recognition method in the above table is O(M+N) and the space complexity is O(1). Based on the position of the table frame (table border) and the table line, the above cell search algorithm can improve the running efficiency of the contour-based cell search algorithm by about half.
[0101] Through this embodiment, before adding the searched candidate vertices of the adjacent cell to the search queue, it is determined whether the point is an interior point of the cell, and the candidate vertices that are not interior points are determined as search vertices, which can reduce the complexity of the cell search and improve the efficiency of the cell search.
[0102] In an exemplary embodiment, reconstructing a table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed includes:
[0103] S51, determining the cell size of each cell and the minimum cell size among the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the size of the minimum cell in the table area;
[0104] S52, determining a reconstruction size of each cell according to the cell size of each cell and the minimum cell size, wherein the reconstruction size of each cell is used to indicate the minimum number of cells occupied by each cell in the reconstructed table;
[0105] S53, reconstructing the table according to the position information of each cell and the reconstructed size of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0106] When reconstructing the table according to the position information of each cell, the server can determine the cell size of each cell according to the position information of each cell. The server can also obtain a table parameter corresponding to the table area of the document to be reconstructed, which can be used for table reconstruction and can be a parameter for indicating the minimum cell size of the table area, and the minimum cell is the size of the minimum cell in the table area.
[0107] Optionally, the table parameter may be pre-configured. For example, the server may obtain the table parameter from configuration information, where the table parameter is the minimum cell size of the table area. Based on the obtained table parameter, the server may determine the minimum cell size of the table area.
[0108] Optionally, the table parameters may also be input by the user before reconstructing the table. The server may send target prompt information to the target client, the target prompt information being used to prompt the target object to determine the minimum cell in the table area; and receive the table parameters returned by the target client. The table parameters include target position information of the target position point, which is a position point within the target cell selected by the target object from the table area. The target cell may be a minimum cell in the table area. Based on the position information of each cell and the target position information, the server may determine the target cell and the cell size of the target cell, and then determine the cell size of the target cell as the minimum cell size of the table area.
[0109] Optionally, the table parameter includes the minimum number of cells that the target cell occupies in the first table direction (horizontal direction) and the second table direction (vertical direction) input by the target object. Based on the position information of each cell and the target position information, the server can determine the target cell and the cell size of the target cell; based on the cell size of the target cell and the minimum number of cells that the target cell occupies in the two table directions (the first table direction and the second table direction), determine the minimum cell size of the table area.
[0110] Optionally, in this embodiment, the table parameter may be determined by the server according to the cell sizes of each cell. The server may determine the smallest cell size among the cell sizes of each cell as the minimum cell size of the table area.
[0111] According to the cell size and minimum cell size of each cell, the server can determine the reconstruction size of each cell, where the reconstruction size of each cell is used to indicate the minimum number of cells occupied by each cell in the reconstructed table, that is, the number of cells occupied in two table directions of the reconstructed table.
[0112] According to the position information of each cell (ie, the relative position relationship of each cell) and the reconstructed size of each cell, the server may reconstruct the table, thereby obtaining a reconstructed table corresponding to the document to be reconstructed.
[0113] For example, after obtaining the cell location information, the table can be reconstructed. Count the width and height of all cells, record the smallest width as w, the smallest height as h, and w*h as the minimum cell size after reconstruction. Divide the width of all cells by w, and the height by h to obtain the reconstructed cell size of all cells. For example, 3*2 means that after reconstruction, the cell occupies three minimum cell widths in the horizontal direction and two minimum cell heights in the vertical direction. Combined with the cell location information, the table structure can be reconstructed.
[0114] It should be noted that if the ratio of the cell size of a cell to the minimum unit cell size is not an integer, the reconstruction size of each cell can be determined by rounding down, rounding up, or rounding. The method for determining the reconstruction size can be configured as needed and is not limited in this embodiment.
[0115] Through this embodiment, the reconstruction size of each cell is determined according to the proportional relationship between the cell sizes of each cell, and then the table is reconstructed based on the reconstruction size of each cell. The table reconstruction can be completed without the user configuring the cells, thereby improving the convenience of table reconstruction.
[0116] In an exemplary embodiment, reconstructing a table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed includes:
[0117] S61, reconstructing a table according to the search order of each cell and the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0118] When reconstructing a table, the server can be triggered from a vertex to reconstruct the table according to a predetermined reconstruction direction. There can be multiple reconstruction directions, for example, first from left to right and then from top to bottom, that is, starting from the upper left corner, first reconstruct the cells in the table from left to right, and after reconstructing a row of cells, reconstruct the next row of cells from left to right, for example, first from top to bottom and then from left to right, or other similar directions. The above method of reconstructing the table according to the predetermined reconstruction direction requires searching for the cells that need to be reconstructed at the current position according to the position information of each cell, and the complexity of the table reconstruction is high.
[0119] Optionally, in this embodiment, the server can reconstruct the table according to the search order of each cell and the position information of each cell. For example, the server can first determine the reconstruction size of each cell according to the position information of each cell; then, according to the search order of each cell, the cell reconstruction is performed in sequence. Since the server can record the adjacent relationship between cells when searching for cells, the table corresponding to the document to be reconstructed can be reconstructed according to the reconstruction size of the cells, the search order of the cells, and the adjacent relationship between the cells.
[0120] For example, for Figure 5 For the search binary tree shown, when reconstructing the table, the server can reconstruct the cells according to the search order during cell parsing. The order of cell reconstruction can be: 1-2-3-4-8-11-5-9-12-6-7-10.
[0121] Through this embodiment, cell reconstruction is performed according to the search order during cell parsing, which can reduce the reconstruction cost of the table and improve the reconstruction efficiency of the table.
[0122] The table reconstruction method in the embodiment of the present application is explained below with reference to optional examples: the document to be reconstructed is the image to be reconstructed, the search vertex (ie, the target vertex) is the vertex in the upper left corner, the first direction is rightward, and the second direction is downward.
[0123] The table reconstruction method in this optional example can be a solution for reconstructing the table based on table lines, converting the table structure into a binary tree form for traversal and analysis, so as to reduce the time and space complexity of the table reconstruction algorithm and improve the algorithm's operating efficiency.
[0124] Combination Figure 6 As shown, the process of the table reconstruction method in this optional example may include the following steps:
[0125] Step S602, input image.
[0126] The user may input the image to be reconstructed through the client, and the server may obtain the image to be reconstructed input by the user.
[0127] Step S604: table detection.
[0128] The server can perform table line detection on the image to be reconstructed to obtain the table area and table lines in the image to be reconstructed, which can be expressed as follows: Figure 3 The form of white lines on a black background is shown.
[0129] Step S606: table recognition.
[0130] Based on the table lines, the server can identify the table structure. Convert the table structure into a binary tree for retrieval and analysis: Start from the upper left corner of the table (the search vertex of cell No. 1) and search the cell boundaries to the right and downward to obtain Figure 3 1 in the search queue; then use the search vertex of cell 1 as the basis to search the adjacent cells to the right and downward to obtain cells 2 and 6, and add the search vertices of cells 2 and 6 to the search queue. Read the search vertex of the cell from the search queue, and continue to search the adjacent cells to the right and downward based on it, and add the search vertices that have not been visited to the search queue. During the search process, ignore the points in the searched cell. Repeat the above steps until the search queue is empty.
[0131] Step S608: table reconstruction.
[0132] After the search queue is empty, the location information of all cells can be obtained. After obtaining the location information of the cells, the server can reconstruct the table structure and the text content in each cell.
[0133] Step S610, result output.
[0134] After reconstructing the table, the server may output the table to the client for storage, and may also display the table on the client and save the table according to the user's instruction.
[0135] Through this optional example, the table structure is converted into a binary tree data structure for processing, which reduces the time and space complexity of table reconstruction and improves the operating efficiency of table reconstruction. It can well support situations where there are few borders on the left and right sides of the table and complex merged cell styles.
[0136] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all described as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily required by the present application.
[0137] Through the description of the above implementation methods, those skilled in the art can clearly understand that the method according to the above embodiment can be implemented by means of software plus a necessary general hardware platform, and of course it can also be implemented by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM (Read-Only Memory) / RAM (Random Access Memory), a disk, or an optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, a computer, a server, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0138] According to another aspect of an embodiment of the present application, a table reconstruction device for implementing the above table reconstruction method is also provided. Figure 7 is a structural block diagram of an optional table reconstruction device according to an embodiment of the present application, such as Figure 7 As shown, the device may include:
[0139] A detection unit 702, configured to perform table detection on the document to be reconstructed, and obtain the region boundary of the table region in the document to be reconstructed, and the table lines in the table region;
[0140] A search unit 704, connected to the detection unit 702, is used to search for cells along a target direction in the table area based on the area boundary and the table line to obtain position information of each cell in the table area, wherein the target direction includes a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary;
[0141] The reconstruction unit 706 is connected to the search unit 704 and is used to reconstruct the table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0142] It should be noted that the detection unit 702 in this embodiment can be used to execute the above step S202, the search unit 704 in this embodiment can be used to execute the above step S204, and the reconstruction unit 706 in this embodiment can be used to execute the above step S206.
[0143] Through the above module, a table is detected on the document to be reconstructed to obtain the area boundary of the table area in the document to be reconstructed and the table lines in the table area; based on the area boundary and the table lines, a cell search is performed along the target direction in the table area to obtain the position information of each cell in the table area, wherein the target direction includes a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary; the table is reconstructed according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed, which solves the problems of high computational complexity and low table reconstruction efficiency in the method of performing table reconstruction based on table lines in the related art, reduces the computational complexity of the algorithm, and improves the table reconstruction efficiency.
[0144] In an exemplary embodiment, the search unit includes:
[0145] A first search module is used to search cells along a target direction in a table area based on a region boundary and a table line to obtain a target vertex of each cell, wherein the relative position of the target vertex of each cell in each cell is the same;
[0146] The second search module is used to search the cell boundary along the target direction in the table area based on the area boundary and the table line, taking the target vertex of each cell as the starting point, to obtain the position information of each cell.
[0147] In an exemplary embodiment, the first search module includes:
[0148] The search submodule is used to search for target vertices of adjacent cells along the target direction in the table area based on the area boundary and the table line to obtain the target vertices of each cell.
[0149] In an exemplary embodiment, the search submodule includes:
[0150] A search subunit is used to search for target vertices of adjacent cells along a target direction starting from a target vertex of a first cell based on a region boundary and a table line to obtain a target vertex of a second cell, wherein the first cell is a first searched cell and the second cell is an adjacent cell of the first cell;
[0151] Add a subunit for adding the target vertex of the second cell to the search queue;
[0152] The execution subunit is used to extract the target vertices of cells from the search queue in sequence as the target vertices of the current cell and perform the following steps until the search queue is empty: based on the region boundary and the table line, starting from the target vertex of the current cell, search for the target vertices of the adjacent cells along the target direction to obtain the target vertices of the adjacent cells of the current cell; in the case that the adjacent cells of the current cell have not been searched for the target vertices of the adjacent cells, the target vertices of the adjacent cells of the current cell are added to the search queue.
[0153] In an exemplary embodiment, the execution subunit includes:
[0154] A search sub-subunit is used to search for the region boundary and the table line along the target direction starting from the target vertex of the current cell, and search for a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction;
[0155] A first determination sub-subunit is used to determine, when the target boundary is not a region boundary, a candidate vertex in a third cell adjacent to the current cell in the target direction, wherein the candidate vertex is a point obtained by offsetting the reference point along the target direction by a target distance;
[0156] The second determining sub-subunit is configured to determine the candidate vertex as a target vertex of the third cell when the distance between the candidate vertex and the cell boundary of the third cell is less than or equal to a target distance threshold.
[0157] In an exemplary embodiment, the reconstruction unit comprises:
[0158] A first determining module is used to determine the cell size of each cell and the minimum cell size among the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the size of the minimum cell in the table area;
[0159] A second determination module is used to determine the reconstruction size of each cell according to the cell size of each cell and the minimum cell size, wherein the reconstruction size of each cell is used to indicate the minimum number of cells occupied by each cell in the reconstructed table;
[0160] The first reconstruction module is used to reconstruct the table according to the position information of each cell and the reconstruction size of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0161] In an exemplary embodiment, the reconstruction unit comprises:
[0162] The second reconstruction module is used to reconstruct the table according to the search order of each cell and the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0163] It should be noted that the examples and application scenarios implemented by the above modules and corresponding steps are the same, but are not limited to the contents disclosed in the above embodiments. It should be noted that the above modules as part of the device can be run in Figure 1 In the hardware environment shown, it can be implemented by software or by hardware, wherein the hardware environment includes a network environment.
[0164] According to another aspect of the embodiments of the present application, a storage medium is further provided. Optionally, in this embodiment, the storage medium can be used to execute the program code of any of the table reconstruction methods in the embodiments of the present application.
[0165] Optionally, in this embodiment, the storage medium may be located on at least one network device among a plurality of network devices in the network shown in the above embodiment.
[0166] Optionally, in this embodiment, the storage medium is configured to store program codes for executing the following steps:
[0167] S1, performing table detection on the document to be reconstructed to obtain the region boundary of the table region in the document to be reconstructed and the table lines in the table region;
[0168] S2, based on the region boundary and the table line, searching for cells along a target direction in the table region to obtain position information of each cell in the table region, wherein the target direction includes a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary;
[0169] S3, reconstructing the table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0170] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, which will not be described in detail in this embodiment.
[0171] Optionally, in this embodiment, the storage medium may include, but is not limited to, various media that can store program codes, such as a USB flash drive, a ROM, a RAM, a mobile hard disk, a magnetic disk, or an optical disk.
[0172] According to another aspect of an embodiment of the present application, an electronic device for implementing the above table reconstruction method is also provided. The electronic device may be a server, a terminal, or a combination thereof.
[0173] Figure 8is a structural block diagram of an optional electronic device according to an embodiment of the present application, such as Figure 8 As shown, it includes a processor 802, a communication interface 804, a memory 806 and a communication bus 808, wherein the processor 802, the communication interface 804 and the memory 806 communicate with each other through the communication bus 808, wherein,
[0174] Memory 806, used for storing computer programs;
[0175] The processor 802 is used to implement the following steps when executing the computer program stored in the memory 806:
[0176] S1, performing table detection on the document to be reconstructed to obtain the region boundary of the table region in the document to be reconstructed and the table lines in the table region;
[0177] S2, based on the region boundary and the table line, searching for cells along a target direction in the table region to obtain position information of each cell in the table region, wherein the target direction includes a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary;
[0178] S3, reconstructing the table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
[0179] Optionally, in this embodiment, the communication bus may be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 8 The communication interface is used for communication between the electronic device and other devices.
[0180] The memory may include RAM, or may include non-volatile memory, such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0181] As an example, the memory 806 may include but is not limited to the detection unit 702, the search unit 704, and the reconstruction unit 706 in the reconstruction device of the table. In addition, it may also include but is not limited to other module units in the reconstruction device of the table, which will not be repeated in this example.
[0182] The above-mentioned processor can be a general-purpose processor, which can include but not be limited to: CPU (Central Processing Unit), NP (Network Processor), etc.; it can also be DSP (Digital Signal Processing), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0183] Optionally, the specific examples in this embodiment may refer to the examples described in the above embodiments, and this embodiment will not be described in detail here.
[0184] It can be understood by those skilled in the art that Figure 8 The structure shown is for illustration only. The device for implementing the reconstruction method of the above table may be a terminal device, which may be a smart phone (such as an Android phone, an iOS phone, etc.), a tablet computer, a PDA, a mobile Internet device (Mobile Internet Devices, MID), a PAD, and other terminal devices. Figure 8 The structure of the electronic device is not limited. Figure 8 More or fewer components (such as network interfaces, display devices, etc.) shown in, or having Figure 8 Different configurations shown.
[0185] A person of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing the hardware related to the terminal device through a program, and the program can be stored in a computer-readable storage medium, which can include: a flash drive, ROM, RAM, a magnetic disk or an optical disk, etc.
[0186] The serial numbers of the above-mentioned embodiments of the present application are for description only and do not represent the advantages or disadvantages of the embodiments.
[0187] If the integrated units in the above embodiments are implemented in the form of software functional units and sold or used as independent products, they can be stored in the above computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling one or more computer devices (which may be personal computers, servers, or network devices, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application.
[0188] In the above embodiments of the present application, the description of each embodiment has its own emphasis. For parts that are not described in detail in a certain embodiment, please refer to the relevant description of other embodiments.
[0189] In the several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other ways. Among them, the device embodiments described above are only schematic. For example, the division of the units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.
[0190] 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 units may be selected according to actual needs to achieve the purpose of the solution provided in this embodiment.
[0191] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0192] The above is only a preferred implementation of the present application. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present application. These improvements and modifications should also be regarded as the scope of protection of the present application.
Claims
1. A table reconstruction method, characterized in that: include: Performing table detection on the document to be reconstructed to obtain the region boundary of the table region in the document to be reconstructed and the table lines in the table region; Based on the area boundary and the table line, a cell search is performed in the table area along a target direction to obtain position information of each cell in the table area, wherein whether the area boundary or the table line is searched is determined according to the searched color, the target direction includes a first direction parallel to the target area boundary of the table area, and a second direction perpendicular to the target area boundary, and the target area boundary is one of the following: an upper boundary, a lower boundary, a left boundary, and a right boundary; Reconstructing a table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed; Among them, after performing table detection on the document to be reconstructed and obtaining the area boundary of the table area in the document to be reconstructed and the table lines within the table area, the method also includes: setting the area boundary and the table line to a first color, and setting other positions in the document to be reconstructed except the area boundary and the table line to a second color, wherein the searched colors include the first color and the second color.
2. The method according to claim 1, characterized in that: Based on the region boundary and the table line, searching for cells along the target direction in the table region to obtain the position information of each cell in the table region includes: Based on the area boundary and the table line, a cell search is performed along the target direction in the table area to obtain the target vertices of each cell, wherein the relative positions of the target vertices of each cell in the cells are the same; Based on the area boundary and the table line, a cell boundary search is performed along the target direction in the table area with the target vertex of each cell as a starting point to obtain the position information of each cell.
3. The method according to claim 2, characterized in that Based on the area boundary and the table line, a cell search is performed along the target direction in the table area to obtain the target vertex of each cell, including: Based on the area boundary and the table line, the target vertices of adjacent cells are searched along the target direction in the table area to obtain the target vertices of each cell.
4. The method according to claim 3, characterized in that Based on the region boundary and the table line, searching for target vertices of adjacent cells along the target direction within the table region to obtain the target vertices of each cell includes: Based on the region boundary and the table line, starting from the target vertex of the first cell, searching for the target vertex of the adjacent cell along the target direction, to obtain the target vertex of the second cell, wherein the first cell is the first searched cell, and the second cell is the adjacent cell of the first cell; Adding the target vertex of the second cell to the search queue; Extract the target vertices of cells from the search queue in sequence as the target vertices of the current cell and perform the following steps until the search queue is empty: based on the area boundary and the table line, search for the target vertices of adjacent cells along the target direction with the target vertex of the current cell as the starting point to obtain the target vertices of the adjacent cells of the current cell; if the adjacent cells of the current cell have not been searched for the target vertices of the adjacent cells, add the target vertices of the adjacent cells of the current cell to the search queue.
5. The method according to claim 4, characterized in that Based on the region boundary and the table line, starting from the target vertex of the current cell, searching for the target vertex of the adjacent cell along the target direction, and obtaining the target vertex of the adjacent cell of the current cell includes: Taking the target vertex of the current cell as a starting point, searching the region boundary and the table line along the target direction to find a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction; In a case where the target boundary is not the region boundary, determining a candidate vertex in a third cell adjacent to the current cell in the target direction, wherein the candidate vertex is a point obtained by offsetting the reference point by a target distance along the target direction; In a case where the distance between the candidate vertex and the cell border of the third cell is less than or equal to a target distance threshold, the candidate vertex is determined as a target vertex of the third cell.
6. The method according to claim 1, characterized in that Reconstructing the table according to the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed includes: determining the cell size of each cell and the minimum cell size among the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the size of the minimum cell in the table area; Determining a reconstruction size of each cell according to a cell size of each cell and the minimum cell size, wherein the reconstruction size of each cell is used to indicate the number of the minimum cells occupied by each cell in the reconstructed table; The table is reconstructed according to the position information of each cell and the reconstructed size of each cell to obtain the reconstructed table corresponding to the document to be reconstructed.
7. The method according to any one of claims 1 to 6, characterized in that Reconstructing the table according to the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed includes: The table is reconstructed according to the search order of each cell and the position information of each cell to obtain the reconstructed table corresponding to the document to be reconstructed.
8. A table reconstruction device, characterized in that: include: A detection unit, configured to perform table detection on the document to be reconstructed, and obtain a region boundary of a table region in the document to be reconstructed, and a table line in the table region; A search unit, configured to search for cells in the table area along a target direction based on the area boundary and the table line, to obtain position information of each cell in the table area, wherein whether the area boundary or the table line is searched is determined according to the searched color, the target direction includes a first direction parallel to the target area boundary of the table area, and a second direction perpendicular to the target area boundary, and the target area boundary is one of the following: an upper boundary, a lower boundary, a left boundary, and a right boundary; A reconstruction unit, configured to reconstruct a table according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed; The device is further used to: set the area boundary and the table line to a first color, and set other positions in the document to be reconstructed except the area boundary and the table line to a second color, wherein the searched colors include the first color and the second color.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium includes a stored program, wherein the program executes the method according to any one of claims 1 to 7 when executed.
10. An electronic device comprising a memory and a processor, characterized in that: A computer program is stored in the memory, and the processor is configured to execute the method according to any one of claims 1 to 7 through the computer program.
Citation Information
Patent Citations
File format conversion method and device, equipment and storage medium
CN107885713A
Table vector analysis method and apparatus for PDF document
CN108446264A
A method and apparatus for parsing a document table in a portable document format
CN109446487A
Method and system for analyzing table in PDF document, storage medium and electronic equipment
CN110472208A
Method and device for automatically identifying paper table structure
CN112036294A
