[go: up one dir, main page]

CN113486638B - Table reconstruction method and device, storage medium and electronic device - Google Patents

Table reconstruction method and device, storage medium and electronic device Download PDF

Info

Publication number
CN113486638B
CN113486638B CN202110867193.0A CN202110867193A CN113486638B CN 113486638 B CN113486638 B CN 113486638B CN 202110867193 A CN202110867193 A CN 202110867193A CN 113486638 B CN113486638 B CN 113486638B
Authority
CN
China
Prior art keywords
cell
target
boundary
cells
reconstructed
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN202110867193.0A
Other languages
Chinese (zh)
Other versions
CN113486638A (en
Inventor
李亚红
熊剑平
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN202110867193.0A priority Critical patent/CN113486638B/en
Publication of CN113486638A publication Critical patent/CN113486638A/en
Application granted granted Critical
Publication of CN113486638B publication Critical patent/CN113486638B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/177Editing, e.g. inserting or deleting of tables; using ruled lines
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F40/00Handling natural language data
    • G06F40/10Text processing
    • G06F40/166Editing, e.g. inserting or deleting
    • G06F40/183Tabulation, i.e. one-dimensional positioning

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Health & Medical Sciences (AREA)
  • Artificial Intelligence (AREA)
  • Audiology, Speech & Language Pathology (AREA)
  • Computational Linguistics (AREA)
  • General Health & Medical Sciences (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Image Analysis (AREA)

Abstract

The application discloses a method and a device for reconstructing a table, a storage medium and an electronic device, wherein the method comprises the following steps: carrying out 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 region boundary and the table line, searching cells in the table region along a target direction to obtain position information of each cell in the table region, wherein the target direction comprises a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary; and carrying out table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed. According to the method and the device, the calculation complexity of table reconstruction according to the table grid lines can be reduced, and the table reconstruction efficiency is improved.

Description

Table reconstruction method and device, storage medium and electronic device
Technical Field
The present application relates to the field of communications, and in particular, to a method and apparatus for reconstructing a table, a storage medium, and an electronic apparatus.
Background
Currently, many businesses are migrating to intelligent offices and many paper document data need to be electronically. Tables are important components of a document, and table spreadsheet is relevant to table reconstruction.
The table reconstruction method provided in the related art is as follows: acquiring a form image to be reconstructed; dividing the to-be-reconstructed table image to obtain a first table grid line and a second table grid line; acquiring intersection points of the first table grid lines and the second table grid lines; acquiring intersection point coordinates corresponding to all intersection points; and connecting corresponding intersection points according to the coordinates of each intersection point to reconstruct the table.
For the table reconstruction mode, after the table transverse and vertical lines are obtained, the intersection point profiles are detected, the intersection points are determined, and then the table is ordered according to the intersection point coordinates, so that the calculation complexity is high. At the same time, the reconstruction logic for tables with complex patterns of merging cells will be more complex.
Therefore, the method of table reconstruction according to the table grid lines in the related art has the problems of high calculation complexity and low table reconstruction efficiency.
Disclosure of Invention
The embodiment of the application provides a method and a device for reconstructing a table, a storage medium and an electronic device, which are used for at least reducing the calculation complexity of table reconstruction according to table grid lines and improving the table reconstruction efficiency.
According to an aspect of an embodiment of the present application, there is provided a method for reconstructing a table, including: performing table detection on a document to be reconstructed to obtain the region boundary of a table region in the document to be reconstructed and a table line in the table region; performing cell search in the table area along a target direction based on the area boundary and the table grid line to obtain position information of each cell in the table area, wherein the target direction comprises a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary; and carrying out table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
In an exemplary embodiment, performing a cell search along the target direction in the table area based on the area boundary and the table grid line, and obtaining the position information of each cell in the table area includes: based on the region boundary and the table grid lines, cell searching is carried out in the table region along the target direction to obtain target vertexes of all the cells, wherein the relative positions of the target vertexes of all the cells in all the cells are the same; and carrying out cell boundary search in the table area along the target direction by taking the target vertex of each cell as a starting point based on the area boundary and the table grid line to obtain the position information of each cell.
In an exemplary embodiment, performing a cell search along the target direction in the table area based on the area boundary and the table grid line, and obtaining the target vertex of each cell includes: and searching target vertexes of adjacent cells along the target direction in the table area based on the area boundary and the table grid lines to obtain the target vertexes of each cell.
In an exemplary embodiment, searching for the target vertex of the neighboring cell along the target direction within the table area based on the area boundary and the table grid line, the obtaining the target vertex of each cell includes: searching target vertexes of adjacent cells along the target direction by taking target vertexes of first cells as starting points on the basis of the region boundary and the table grid lines to obtain target vertexes of second cells, wherein the first cells are first searched cells, and the second cells are adjacent cells of the first cells; adding the target vertex of the second cell to a search queue; sequentially extracting target vertexes of the cells from the search queue as target vertexes of the current cells, and executing the following steps until the search queue is empty: searching target vertexes of adjacent cells along the target direction by taking the target vertexes of the current cells as starting points based on the region boundary and the table grid lines to obtain the target vertexes of the adjacent cells of the current cells; and adding the target vertex of the adjacent cell of the current cell into the search queue under the condition that the adjacent cell of the current cell is not subjected to the search operation of the target vertex of the adjacent cell.
In an exemplary embodiment, based on the region boundary and the table grid line, searching the target vertex of the neighboring cell along the target direction with the target vertex of the current cell as a starting point, and obtaining the target vertex of the neighboring cell of the current cell includes: searching the region boundary and the table grid lines along the target direction by taking the target vertex of the current cell as a starting point, and searching a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction; determining candidate vertexes in a third cell adjacent to the current cell in the target direction under the condition that the target boundary is not the region boundary, wherein the candidate vertexes are points obtained by shifting the reference point by a target distance along the target direction; and determining 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.
In an exemplary embodiment, performing table reconstruction according to the location information of each cell, and obtaining the reconstruction table corresponding to the document to be reconstructed includes: determining the cell size of each cell and the minimum cell size in the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the minimum cell size of the table area; 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 for indicating the number of the minimum cells occupied by each cell in a reconstructed table; and carrying out table reconstruction according to the position information of each cell and the reconstruction size of each cell to obtain the reconstruction table corresponding to the document to be reconstructed.
In an exemplary embodiment, performing table reconstruction according to the location information of each cell, and obtaining the reconstruction table corresponding to the document to be reconstructed includes: and carrying out table reconstruction according to the search sequence of each cell and the position information of each cell to obtain the reconstruction table corresponding to the document to be reconstructed.
According to another aspect of the embodiment of the present application, there is also provided a table reconstruction apparatus, including: the detection unit is used for carrying out 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; a search unit, configured to perform cell search in the table area along a target direction based on the area boundary and the table ruled line, to obtain location information of each cell in the table area, where 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 reconstruction unit is used for carrying out table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
In an exemplary embodiment, the search unit includes: the first search module is used for searching cells in the table area along the target direction based on the area boundary and the table grid lines to obtain target vertexes of all the cells, wherein the relative positions of the target vertexes of all the cells in all the cells are the same; and the second search module is used for searching cell boundaries in the table area along the target direction by taking the target vertexes of the cells as starting points based on the area boundaries and the table grid lines to obtain the position information of the cells.
In an exemplary embodiment, the first search module includes: and the searching sub-module is used for searching the target vertexes of the adjacent cells along the target direction in the table area based on the area boundary and the table grid lines to obtain the target vertexes of the cells.
In an exemplary embodiment, the search sub-module includes: the searching subunit is configured to search, based on the region boundary and the table grid line, for a target vertex of a neighboring cell along the target direction with a target vertex of a first cell as a starting point, to obtain a target vertex of a second cell, where the first cell is a first searched cell, and the second cell is a neighboring cell of the first cell; an adding subunit, configured to add the target vertex of the second cell to a search queue; an execution subunit, configured to sequentially extract, from the search queue, a target vertex of a cell as a target vertex of a current cell, and execute the following steps until the search queue is empty: searching target vertexes of adjacent cells along the target direction by taking the target vertexes of the current cells as starting points based on the region boundary and the table grid lines to obtain the target vertexes of the adjacent cells of the current cells; and adding the target vertex of the adjacent cell of the current cell into the search queue under the condition that the adjacent cell of the current cell is not subjected to the search operation of the target vertex of the adjacent cell.
In one exemplary embodiment, the execution subunit includes: a search sub-unit, configured to search the region boundary and the table grid line along the target direction with a target vertex of the current cell as a starting point, and search a reference point on a target boundary, where the target boundary is a boundary of the current cell in the target direction; a first determining subunit, configured to determine, when the target boundary is not the region boundary, a candidate vertex in a third cell adjacent to the current cell in the target direction, where the candidate vertex is a point obtained by shifting the reference point by a target distance along the target direction; and a second determining subunit, configured to determine the candidate vertex as a target vertex of the third cell when a distance between the candidate vertex and a cell boundary of the third cell is less than or equal to a target distance threshold.
In an exemplary embodiment, the reconstruction unit includes: a first determining module, configured to determine, according to the position information of each cell, a cell size of each cell, and a minimum cell size of the cell sizes of each cell, where the minimum cell size is a size of a minimum cell of the table area; a second determining module, configured to determine a reconstruction size of each cell according to a cell size of each cell and the minimum cell size, where the reconstruction size of each cell is used to indicate a number of the minimum cells occupied by each cell in a reconstructed table; and the first reconstruction module is used for carrying out table reconstruction according to the position information of each cell and the reconstruction size of each cell to obtain the reconstruction table corresponding to the document to be reconstructed.
In an exemplary embodiment, the reconstruction unit includes: and the second reconstruction module is used for reconstructing the table according to the search sequence of each cell and the position information of each cell to obtain the reconstruction table corresponding to the document to be reconstructed.
According to a further aspect of embodiments of the present application, there is also provided a computer readable storage medium having a computer program stored therein, wherein the computer program is arranged to perform the above-described method of reconstructing a table when run.
According to still another aspect of the embodiments of the present application, there is further provided an electronic device including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the method for reconstructing the table by using the computer program.
In the embodiment of the application, a mode of converting a table structure into a mode of performing cell traversal and analysis along a specific direction is adopted, and a region boundary of a table region in a document to be reconstructed and a table line in the table region are obtained by performing table detection on the document to be reconstructed; based on the region boundary and the table line, searching cells in the table region along a target direction to obtain position information of each cell in the table region, wherein the target direction comprises a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary; the method comprises the steps of carrying out table reconstruction according to the position information of each cell to obtain a reconstructed table corresponding to a document to be reconstructed, and determining the position information of each cell based on the region boundary and the table line by carrying out cell traversal and analysis along a specific direction in a detected table region without carrying out operations such as detecting intersection point outlines, sorting according to intersection point coordinates and the like, so that the technical effects of reducing the calculation complexity of an algorithm and improving the table reconstruction efficiency are achieved, and the problems of high calculation complexity and low table reconstruction efficiency in a table reconstruction mode according to table grid lines in the related art are solved.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the application or the technical solutions of the prior art, the drawings which are used in the description of the embodiments or the prior art will be briefly described, and it will be obvious to a person skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a schematic diagram of a hardware environment of an alternative form reconstruction method according to an embodiment of the present application;
FIG. 2 is a flow chart of an alternative method of table reconstruction in accordance with an embodiment of the present application;
FIG. 3 is a schematic diagram of an alternative form reconstruction method according to an embodiment of the present application;
FIG. 4 is a schematic diagram of an alternative form reconstruction method according to an embodiment of the present application;
FIG. 5 is a schematic diagram of an alternative search binary tree according to an embodiment of the present application;
FIG. 6 is a flow chart of another alternative method of table reconstruction in accordance with an embodiment of the present application;
FIG. 7 is a block diagram of an alternative form reconstruction device according to an embodiment of the present application;
fig. 8 is a block diagram of an alternative electronic device according to an embodiment of the application.
Detailed Description
In order that those skilled in the art will better understand the present application, a technical solution in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present application without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
According to an aspect of an embodiment of the present application, a method for reconstructing a table is provided. Alternatively, in the present embodiment, the above-described method of reconstructing the table may be applied to a hardware environment constituted by the terminal 102 and the server 104 as shown in fig. 1. As shown in fig. 1, the server 104 is connected to the terminal 102 through a network, and may be used to provide services (such as application services, etc.) to the terminal or to clients installed on the terminal, and a database may be provided on the server or independent of the server, for providing data storage services to the server 104.
The network may include, but is not limited to, at least one of: wired network, wireless network. The wired network may include, but is not limited to, at least one of: a wide area network, a metropolitan area network, a local area network, and the wireless network may include, but is not limited to, at least one of: WIFI (WIRELESS FIDELITY ), bluetooth. The terminal 102 may not be limited to a PC (Personal Computer ), a mobile phone, a tablet computer, or the like.
The method for reconstructing the table according to the embodiment of the present application may be performed by the server 104, may be performed by the terminal 102, or may be performed by both the server 104 and the terminal 102. The method for reconstructing the table by the terminal 102 according to the embodiment of the present application may be performed by a client installed thereon.
Taking the example that the server 104 performs the method for reconstructing the table in the present embodiment, fig. 2 is a schematic flow chart of an alternative method for reconstructing the table according to an embodiment of the present application, as shown in fig. 2, the flow chart of the method may include the following steps:
Step S202, carrying out 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 grid lines in the table region.
The method for reconstructing the table in the embodiment can be applied to reconstructing a scene of a corresponding table for a table area in a document, wherein the document needing to reconstruct the corresponding table area is a document to be reconstructed, namely, the document to be reconstructed is the document of the corresponding table. The document to be reconstructed may have various formats, such as PDF (Portable Document Format ), image, or other document formats that may include a table area, and in this embodiment, the document format of the document to be reconstructed is not limited.
The target terminal can be operated with a target client with a form reconstruction function, and a document to be subjected to form reconstruction, namely, a document to be reconstructed is selected through the target client. The target client may directly execute the table reconstruction operation on the document to be reconstructed, or may send the document to be reconstructed to the background server through communication connection with the background server, and the background server executes the table reconstruction operation.
The server (i.e., a background server) may obtain the document to be reconstructed, and perform table detection on the document to be reconstructed to obtain an area boundary of a table area in the document to be reconstructed and table grid lines in the table area. For example, the background server may process the document to be reconstructed based on a deep learning technique or morphology to obtain a table area and a table line of the document to be reconstructed.
Alternatively, after the table region and the table line of the document to be reconstructed are detected, the region boundary and the table line of the table region in the document to be reconstructed may be set to a first color (for example, white), and the other positions in the document to be reconstructed except for the region boundary and the table line of the table region may be set to a second color (for example, black), so that whether the region boundary or the table line is searched may be determined according to the searched color.
For example, after the document to be reconstructed is an image to be reconstructed and the form detection is performed on the image to be reconstructed, the detected form area and form line may be set to white, and the other positions may be set to black, resulting in an image area as shown in fig. 3.
Step S204, based on the region boundary and the table line, searching cells in the table region along the target direction to obtain the position information of each cell in the table region, wherein the target direction comprises a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary.
Based on the region boundaries and the table lines, the server may conduct a cell search along the target direction within the table region. The target direction may include a first direction parallel to a target region boundary of the table region and a second direction perpendicular to the target region boundary, that is, a second direction perpendicular to the first direction.
For example, the target region boundary may be an upper boundary (or a lower boundary) of the table region, the first direction being a horizontal left direction (or a horizontal right direction), and the second direction being a vertically upward direction (or a vertically downward direction). For another example, the target region boundary may be a left boundary (or right boundary) of the table region, the first direction being a vertically upward direction (or vertically downward direction), and the second direction being a horizontally leftward direction (or horizontally rightward direction).
In performing the cell search, the search may be started with one position point (search start point) of the table area as a start point, which may be one table vertex of the table area. For example, the top left corner of the table area may be used as the search cell vertex. To avoid line width effects, the table vertex may not be a strict table vertex (i.e., not the intersection of region boundaries), but a point located within the table region and at a target distance from the target vertex of the table region. For example, as shown in FIG. 3, the starting point of the search cell may be a point where the top left corner of the table area has a small distance to the bottom right and no white pixel value is surrounding.
From the search start point, the server may perform a cell search along a first direction, and if a region boundary or a table grid line is searched, it may be determined that the boundary of the current cell is searched. The server may also perform a cell search along the second direction and if a region boundary or table grid line is searched, may determine that the boundary of the current cell is searched. Based on the searched cell boundaries, the location information of the current cell may be determined.
In addition to searching for cells from the table vertex, the cell search may be performed 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), so as to determine four boundaries of the current cell.
After searching for the location area of the current cell, the boundary of the neighboring cell of the current cell may be searched for along the target direction based on the area boundary and the table line. The search starting point is updated to a point within the adjacent cell. The search start point of the neighboring cell may be determined according to the search start point of the current cell. For example, if the adjacent cell is adjacent to the current cell in the first direction, the search start point of the adjacent cell is a point obtained by searching the table line along the first direction with the search start point of the current cell and then shifting the table line a small distance along the first direction.
It should be noted that, to avoid searching the searched cell, it may be determined whether the cell to be searched currently has been searched based on the position information of the searched cell, thereby improving the efficiency of cell search.
Alternatively, the cell search may be performed in a progressive manner, for example, searching for adjacent cells of cells along the target direction, and searching for adjacent cells of adjacent cells along the target direction until all cells have been searched. The cell search may be performed in a random manner, for example, a location point may be randomly selected in a non-searched table area, a boundary of a cell where the location point is located is searched along a target direction, the location area of the cell is determined, the non-searched table area is updated, and the location point is selected again for searching until the non-searched table area is empty.
It should be noted that searching for cells along the target direction in the table area may be searching for boundaries of cells along the target direction. In the case of searching for cells, the boundaries of the cells may be searched for in the first direction and the second direction, respectively, or the boundaries of the cells may be searched for in the first direction and the second direction at the same time. Cell search along the target direction within the table area may also be to search for neighboring cells of the cell along the target direction. In the case of searching for cells, the cells may be adjacent cells to each other in the first direction and the second direction, or may be adjacent cells to each other in both the first direction and the second direction, which is not limited in this embodiment.
Step S206, performing table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
After obtaining the position information of all the 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 a reconstructed table corresponding to the table area of the document to be reconstructed. There are various ways to reconstruct the table based on the position information of each cell, which may include, but are not limited to, determining the number and positions of the table cells occupied by each cell based on the aspect ratio of the cell, and reconstructing the table.
Alternatively, in addition to reconstructing the table, the text information in each cell may be written into a corresponding cell in the reconstructed table. For example, each cell image may perform text line detection by using a pixel projection or a deep learning method, determine a text line position in each cell image, and identify a text line through an identification network such as CRNN (Convolutional Recurrent Neural Network, convolutional cyclic neural network) to obtain an identification result. By combining the identification result and the table structure information, the table reconstruction can be realized according to the user requirement, and output files such as excel (office software) and the like are generated.
The output form file can be stored locally in the server or in a database connected with the server, and can also be sent to the target terminal for storage or display. If the target terminal performs the table reconstruction, the reconstructed table file may be displayed on the display interface of the terminal, or may be stored locally in the terminal, or may be sent to the server for storage, which is not limited in this embodiment.
Through the steps, the document to be reconstructed is subjected to form detection, and the area boundary of the form area in the document to be reconstructed and the form line in the form area are obtained; based on the region boundary and the table line, searching cells in the table region along a target direction to obtain position information of each cell in the table region, wherein the target direction comprises a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary; and (3) carrying out table reconstruction according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed, thereby solving the problems of high calculation complexity and low table reconstruction efficiency in the related art in a mode of carrying out table reconstruction according to the table grid lines, reducing the calculation complexity of an algorithm and improving the table reconstruction efficiency.
In one exemplary embodiment, performing a cell search along a target direction within a table region based on a region boundary and a table line, obtaining location information of each cell within the table region includes:
S11, searching cells in a table area along a target direction based on the area boundary and the table line to obtain target vertexes of all the cells, wherein the relative positions of the target vertexes of all the cells in all the cells are the same;
And S12, based on the region boundary and the table grid lines, carrying out cell boundary search in the table region along the target direction by taking the target vertex of each cell as a starting point, and obtaining the position information of each cell.
In performing the cell search, the vertices of each cell may be searched first based on the region boundary and the table line, and the searched vertices may be vertices at the same position of each cell, for example, a top left corner vertex, a bottom left corner vertex, a top right corner vertex, and a bottom right corner vertex. The cells in the table are generally square and have four vertices. Based on the attributes of the cells and the region boundaries and table lines in the table region, the target vertex of each cell may be searched when searching along the target direction starting from the target vertices of other cells.
For the target vertex of each cell, the server may search the cell boundary in the table area along the target direction with the target vertex of each cell as a starting point based on the area boundary and the table grid line, determine the boundary of each cell, and further obtain the position information of each cell.
It should be noted that, searching the target vertex of each cell and searching the boundary of each cell may be performed in series, that is, searching the boundary of each cell after searching the target vertices of all cells, or may be performed in parallel, for example, searching the boundary of the current cell with the target vertex of the current cell as the starting point, to obtain the position information of the current cell, or may obtain the target vertex of the adjacent cell of the current cell.
For example, for a table with complex cell merge patterns as shown in FIG. 3, one search process for cells in the table is shown in FIG. 4. In fig. 4, each number represents the cell number of the cell. Cell boundaries may be searched starting from the top left corner of the table (an example of a target vertex) to the right (an example of a first direction) and downward (an example of a second direction), resulting in location information for each cell.
When searching for a cell, the current cell is cell No.1 in fig. 3, and the search operation is as follows: searching the white pixels rightward by taking the top left corner of the table as the vertex of the search cell, finding the right boundary of the cell, searching the white pixels downward, and finding the lower boundary of the cell, thereby obtaining the position information of the cell No. 1; adjacent cells, i.e., cell numbers 2 and 6 in fig. 4, are then searched rightward and downward with reference to cell number 1.
The search vertex of the cell No. 2 is a point where the upper left corner of the cell is offset to the right and below by a distance, and can be deduced from the upper right vertex coordinates of the cell No. 1. And repeating the cell searching step to obtain the position information of the number 2 cell. Similarly, traversing cell number 6 adjacent to cell number 1, the search vertex for cell number 6 may be inferred from the lower left vertex coordinates of cell number 1.
It should be noted that, the cell numbers in fig. 4 are only for describing the identification for convenience, and in the searching process, the server may number the searched cells, and after the searching of the table area is completed, the numbers of all the cells may be obtained.
By the embodiment, the convenience of determining the position information can be improved by determining the vertexes of the same positions of the cells and determining the position information of the cells by taking the determined vertexes as the starting points.
In one exemplary embodiment, performing a cell search along a target direction within a table region based on a region boundary and a table line, obtaining a target vertex for each cell includes:
S21, searching target vertexes of adjacent cells along the target direction in the table area based on the area boundary and the table line to obtain the target vertexes of each cell.
Based on the characteristics of the table, the target vertex of each cell can be searched at least when searching along the target direction from the target vertex of one cell adjacent to the target vertex. The server may search along the target direction starting from the target vertex of one cell. If a region boundary is searched, it may be determined that the cell has no neighboring cells in the target direction. If a table line is searched, it may be determined that the cell has a neighboring cell in the target direction.
If the table line is searched, the server can continue searching along the target direction to determine whether the target vertex of the adjacent cell of the cell is searched, if so, the target vertex of the adjacent cell can be recorded, and after the target vertices of the adjacent cells of all the cells are searched, the server can acquire the target vertices of all the cells.
By searching the vertexes of the adjacent cells along the target direction, the embodiment can reduce the searching complexity and improve the efficiency of vertex searching.
In one exemplary embodiment, searching for a target vertex of an adjacent cell along a target direction within a table region based on a region boundary and a table line, the obtaining the target vertex of each cell includes:
S31, searching target vertexes of adjacent cells along a target direction by taking target vertexes of first cells as starting points based on the region boundary and the table lines to obtain target vertexes of second cells, wherein the first cells are first searched cells, and the second cells are adjacent cells of the first cells;
s32, adding the target vertex of the second cell to the search queue;
S33, sequentially extracting target vertexes of the cells from the search queue as target vertexes of the current cells, and executing the following steps until the search queue is empty: searching target vertexes of adjacent cells along a target direction by taking the target vertexes of the current cells as starting points based on the region boundary and the table grid lines to obtain the target vertexes of the adjacent cells of the current cells; in the case that the adjacent cell of the current cell is not subjected to the search operation of the target vertex of the adjacent cell, the target vertex of the adjacent cell of the current cell is added to the search queue.
In searching for the target vertex of the cell, the server may first determine the target vertex of the first searched cell, i.e., the target vertex of the first cell; then, based on the region boundary and the table line, searching the target vertex of the adjacent cell along the target direction by taking the target vertex of the first cell as a starting point to obtain the target vertex of the second cell, and adding the target vertex of the second cell into the search queue.
The second cell is a cell adjacent to the first cell in a target direction, the target direction including the first direction and the second direction, the second cell may include at least one of: cells adjacent to the first cell in the first direction, cells adjacent to the first cell in the second direction.
For the target vertexes of the cells in the search queue, the server can sequentially extract the target vertexes of the cells from the search queue as the target vertexes of the current cells, search the target vertexes of the adjacent cells of the current cells, and add the target vertexes of the adjacent cells searched to the target vertexes to the search queue until the search queue is empty.
When the search is performed once, the server may search the target vertex of the adjacent cell along the target direction with the target vertex of the current cell as the starting point based on the region boundary and the table line, to obtain the target vertex of the adjacent cell of the current cell. If the neighbor cell of the current cell has not been subjected to the search operation of the target vertex of the neighbor cell, the target vertex of the neighbor cell of the current cell may be added to the search queue.
For example, with the search process shown in fig. 4, after cell No. 2 and cell No. 6 are searched, cell No. 2 and cell No. 6 (search vertices, that is, target vertices) may be added to the search queue, and search vertex information (that is, information of searched search vertices) may be recorded, avoiding repeated searches.
At this time, there are No. 2 cells and No. 6 cells in the search queue, the search steps of the adjacent cells are repeated, the upper right and lower left adjacent cells of the No. 2 cells are sequentially searched, no. 5 cells and No. 3 cells are respectively searched, the upper right adjacent cell of the No. 6 cells, that is, no. 7 cells are added to the search queue. Since the lower left adjacent cell of cell No. 6 has reached the table frame boundary when searching for it, the search is stopped.
And continuing to search the positions of adjacent cells by taking the cells 5, 3 and 7 in the search queue as references, and stopping when the coordinates exceed the range of the table frame. The cell adjacent to the lower left of the cell No. 3 is the cell No. 8, and the cell adjacent to the upper right of the cell No. 7 is the cell No. 8. Since cell No. 8 is already added to the search queue when cell No. 3 is searched, when cell No. 8 is searched again in the process of searching for the adjacent cell of cell No. 7, the cell is skipped if the search vertex of the cell is found to be accessed.
Alternatively, since the search vertex of the cell No. 8 calculated from the cell No. 3 coordinate and the search vertex of the cell No. 8 calculated from the cell No. 7 coordinate are not necessarily identical to each other, a certain error redundancy may be set to determine whether they are the same vertex.
According to the embodiment, the adjacent cells which are searched for the target vertex and are not searched for are recorded through the search queue, so that the efficiency of cell search can be improved.
In one exemplary embodiment, searching for the target vertex of the neighboring cell along the target direction with the target vertex of the current cell as a starting point based on the region boundary and the table grid line, the obtaining the target vertex of the neighboring cell of the current cell includes:
S41, searching a region boundary and a table line along a target direction by taking a target vertex of a current cell as a starting point, and searching a reference point on the target boundary, wherein the target boundary is a boundary of the current cell in the target direction;
s42, determining candidate vertexes in a third cell adjacent to the current cell in the target direction under the condition that the target boundary is not the region boundary, wherein the candidate vertexes are points obtained by shifting the reference point by the target distance along the target direction;
S43, determining 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 smaller than or equal to the target distance threshold.
When searching for the target vertex of the neighboring cell, the boundary of the current cell, that is, at least one of the region boundary and the table grid line, may be searched for along the target direction with the target vertex of the current cell as a starting point, and the searched boundary is the target boundary. Since the boundary search is performed from one point along one direction, one point on the target boundary, that is, the reference point on the target boundary is searched.
If the target boundary is not a region boundary, it may be determined that there is a cell adjacent to the current cell along the target direction, the adjacent cell being a third cell. The server may determine that a point after the reference point is shifted by a certain distance along the target direction is a candidate vertex of the third cell. For the searched neighboring cells, the server may determine the target vertices of all the neighboring cells searched. For example, if it is a neighboring cell searched along the first direction, the server may search in the opposite direction to the second direction with the candidate vertex as a starting point until the boundary (i.e., at least one of the region boundary and the table grid line) of the third cell is searched. And then determining the point obtained after the searched boundary point is shifted by the target distance along the second direction as the target vertex of the third cell.
Alternatively, the target vertex based on each cell may be searched at least when searching along the target direction from the target vertex of one cell adjacent thereto as a starting point. To reduce the complexity of cell search, a third cell may be added to the search queue only if the candidate vertex is the target vertex for the third cell.
The server may determine a distance between the candidate vertex and a cell boundary of the third cell, and if the distance between the candidate vertex and the cell boundary of the third cell is less than or equal to a target distance threshold, may determine the candidate vertex as a target vertex of the third cell, and add the target vertex cell of the third cell to the search queue; otherwise, the third cell is ignored. Optionally, the target distance threshold is a preconfigured distance threshold that is greater than or equal to the target distance.
For example, as shown in fig. 4, when searching for the vertex of an adjacent cell from the vertex of one cell to the right and downward, it is first necessary to determine whether the vertex is an interior point of the cell before determining to search for the vertex. Taking cell number 4 as an example, the vertex of the upper right neighbor cell is searched as point a in fig. 4. The point a is not the true cell starting point, but is the interior point of cell number 5. Before adding the point to the search queue, it is necessary to confirm whether the point has a white pixel within a small distance above it. If so, indicating that a table line is arranged above the vicinity of the point, wherein the point is the vertex of a new cell and can be added into a search queue; if not, it is indicated that the point is an interior point of the cell and cannot be discarded as a search vertex for the new cell.
Similarly, the lower left vertex of the search cell No. 4 is the point B in fig. 4, and when determining whether the point is an inner point, it is necessary to confirm whether there is a white pixel in a small distance to the left of the point, i.e. a table grid line, if there is a white pixel, the point may be added to the search queue, and if not, the point is discarded. In confirming whether a white pixel exists upward or leftward, the table frame is encountered, and the table frame is stopped, and if no white pixel exists when the table frame is encountered upward or leftward, the table frame is still encountered, the table frame is added into a search queue.
And repeating the steps, deleting the search vertex of the cell from the search queue after the cell is searched to obtain the position information, and stopping the search process until the search queue is empty. The search method described above may be represented by a binary tree, and an exemplary search binary tree is shown in fig. 5, where the width and height of a table are assumed to be M and N, respectively, and the time complexity of the cell structure identification method in the table is O (m+n), and the space complexity is O (1). On the basis of obtaining the positions (table boundaries) of the table frames and the table grid lines, the operation efficiency of the cell search algorithm can be improved by about half compared with that of a contour-based cell search algorithm.
According to the embodiment, before the searched candidate vertexes of the adjacent cells are added into the search queue, whether the point is the inner point of the cell is judged, and the candidate vertexes of the non-inner points are determined as the search vertexes, so that the complexity of cell search can be reduced, and the efficiency of cell search can be improved.
In an exemplary embodiment, performing table reconstruction according to the position information of each cell, and obtaining a reconstructed table corresponding to a document to be reconstructed includes:
S51, determining the cell size of each cell and the minimum cell size in 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 of the table area;
s52, determining the reconstruction size of each cell according to the cell size and the minimum cell size of each cell, wherein the reconstruction size of each cell is used for indicating the number of the minimum cells occupied by each cell in the reconstructed table;
s53, carrying out table reconstruction according to the position information of each cell and the reconstruction size of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
When the table reconstruction is performed 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 may also obtain a table parameter corresponding to a table region of the document to be reconstructed, where the table parameter may be used for performing table reconstruction, and may be a parameter for indicating a minimum cell size of the table region, where the minimum cell is a size of a minimum cell of the table region.
Alternatively, the table parameters may be preconfigured. For example, the server may obtain the table parameter from the configuration information, where the table parameter is the minimum cell size of the table area. Based on the acquired form parameters, the server may determine a minimum cell size for the form area.
Alternatively, the form parameters may be entered by the user prior to reconstructing the form. The server may send target prompt information to the target client, where the target prompt information is used to prompt the target object to determine a minimum cell in the table area; and receiving the form parameters returned by the target client. The table parameters include target location information for a target location point, which is a location point within a target cell selected from the table area by the target object. The target cell may be a smallest cell within the table area. According to the position information and the target position information of each cell, the server can determine the target cell and the cell size of the target cell, and further determine the cell size of the target cell as the minimum cell size of the table area.
Optionally, the table parameter includes a minimum number of cells occupied by the target cell in the first table direction (horizontal direction) and the second table direction (vertical direction) input by the target object. According to 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; and determining the minimum cell size of the table area according to the cell size of the target cell and the number of the minimum cells occupied by the target cell in the two table directions (the first table direction and the second table direction).
Alternatively, in this embodiment, the table parameter may be determined by the server according to the cell size of each cell. The server may determine the minimum cell size among the cell sizes of the respective cells as the minimum cell size of the table area.
Based on the cell size and the minimum cell size of each cell, the server may determine a reconstructed size of each cell, where the reconstructed size of each cell is used to indicate the number of minimum cells occupied by each cell in the reconstructed table, that is, the number of cells occupied in two table directions of the reconstructed table.
Based on the positional information of each cell (i.e., the relative positional relationship of each cell) and the reconstruction size of each cell, the server may perform table reconstruction, thereby obtaining a reconstructed table corresponding to the document to be reconstructed.
For example, after the location information of the cells is obtained, the table may be reconstructed. Counting the width and height of all the cells, recording the minimum width as w, the minimum height as h, and the w x h is the minimum cell size after reconstruction. The width of all cells divided by w and the height divided by h gives the reconstructed cell size of all cells, e.g., 3*2 represents that after reconstruction the cell is horizontally three minimum cell widths and vertically two minimum cell heights. The table structure can be reconstructed in combination with the position information of the cells.
If the ratio of the cell size of the cell to the minimum cell size is not an integer, the reconstructed size of each cell may be determined by rounding down, rounding up, or rounding down. The manner of determining the reconstruction size may be configured as needed, and is not limited in this embodiment.
According to the embodiment, the reconstruction size of each cell is determined according to the proportional relation among the cell sizes of each cell, and then the table is reconstructed based on the reconstruction size of each cell, so that the table can be reconstructed without cell configuration by a user, and convenience in table reconstruction is improved.
In an exemplary embodiment, performing table reconstruction according to the position information of each cell, and obtaining a reconstructed table corresponding to a document to be reconstructed includes:
s61, carrying out table reconstruction according to the search sequence of each cell and the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
In the case of a table reconstruction, the server may trigger from a vertex and perform the table reconstruction according to a predetermined reconstruction direction, where the reconstruction direction may be various, for example, a left-to-right direction, a top-to-bottom direction, that is, an upper left corner, a left-to-right direction, a row of cells is reconstructed, and then a next row of cells is reconstructed from left to right, for example, a top-to-bottom direction, a left-to-right direction, and other similar directions. In the above method for performing the table reconstruction according to the predetermined reconstruction direction, the cells whose current positions need to be reconstructed need to be searched according to the position information of each cell, and the complexity of the table reconstruction is high.
Optionally, in this embodiment, the server may reconstruct the table according to the search sequence of each cell and the position information of each cell, for example, the server may determine the reconstruction size of each cell according to the position information of each cell first; then, cell reconstruction is sequentially performed according to the search order of the respective cells. When the cell search is performed, the server can record the adjacent relation among the cells, so that the table corresponding to the document to be reconstructed can be reconstructed according to the reconstruction size of the cells, the search sequence of the cells and the adjacent relation among the cells.
For example, for a search binary tree as shown in fig. 5, when performing a table reconstruction, the server may perform a cell reconstruction in the search order at the time of cell analysis, and the order of cell reconstruction may be: 1-2-3-4-8-11-5-9-12-6-7-10.
According to the embodiment, the cell reconstruction is performed according to the search sequence during cell analysis, so that the reconstruction cost of the table can be reduced, and the reconstruction efficiency of the table can be improved.
The following explains the method of reconstructing the table in the embodiment of the present application with reference to an alternative example. The document to be reconstructed is an image to be reconstructed, the search vertex (i.e., the target vertex) is the vertex of the upper left corner, the first direction is rightward, and the second direction is downward.
The table reconstruction method in the alternative example can be a scheme for performing table reconstruction according to the table grid lines, and the table structure is converted into a binary tree form for traversing and analyzing, so that the time and space complexity of a table reconstruction algorithm is reduced, and the operation efficiency of the algorithm is improved.
As shown in connection with fig. 6, the flow of the method for reconstructing a table in this alternative example may include the following steps:
in step S602, an image is input.
The user can input the image to be reconstructed through the client, and the server can acquire the image to be reconstructed input by the user.
In step S604, a table is detected.
The server may perform table line detection on the image to be reconstructed to obtain a table region and a table line in the image to be reconstructed, which may be represented in the form of a black matrix white line as shown in fig. 3.
Step S606, form identification.
Based on the table grid lines, the server may perform table structure identification. Converting the table structure into a binary tree for searching and analyzing: searching the cell boundaries right and downward starting from the top left corner of the table (search vertex of cell number 1), resulting in cell number 1 in fig. 3; and then searching the adjacent cells rightward and downward by taking the search vertex of the cell No.1 as a reference to obtain cells No. 2 and No.6, and adding the search vertices of the cells No. 2 and No.6 into a search queue. And reading the search vertex of the cell from the search queue, continuously searching the adjacent cell rightward and downward by taking the search vertex as a reference, and adding the searched search vertex which is not accessed into the search queue. During the search, the searched intra-cell points are ignored. And repeatedly executing the steps until the search queue is empty.
In step S608, the table is reconstructed.
After the search queue is empty, the location information of all the cells can be obtained. After the position information of the cells is obtained, the server can reconstruct the table, and reconstruct the structure of the table and the text content in each cell.
Step S610, outputting a result.
After the form is reconstructed, the server can output the form to the client for storage, can display the form on the client, and can store the form according to the instruction of the user.
Through the optional example, the table structure is converted into the binary tree data structure for processing, so that the time and space complexity of the table reconstruction is reduced, the running efficiency of the table reconstruction is improved, and the conditions of fewer frames on the left side and the right side of the table and complicated merging cell patterns can be well supported.
It should be noted that, for simplicity of description, s is shown as a series of acts, but it should be understood by those skilled in the art that the present application is not limited by the order of acts, as some steps may be performed in other order or concurrently in accordance with the present application. Further, those skilled in the art will also appreciate that the embodiments described in the specification are all preferred embodiments, and that the acts and modules referred to are not necessarily required for the present application.
From the description of the above embodiments, it will be clear to a person skilled in the art that the method according to the above embodiments may be implemented by means of software plus the necessary general hardware platform, but of course also by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM (Read-Only Memory)/RAM (Random Access Memory), magnetic disk, optical disk) and including instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method according to the embodiments of the present application.
According to another aspect of the embodiment of the present application, there is also provided a table reconstruction device for implementing the above table reconstruction method. Fig. 7 is a block diagram of an apparatus for reconstructing an alternative form according to an embodiment of the present application, and as shown in fig. 7, the apparatus may include:
a detection unit 702, configured to perform table detection on a document to be reconstructed to obtain an area boundary of a table area in the document to be reconstructed and a table line in the table area;
A search unit 704, coupled to the detection unit 702, for performing a cell search in the table area along a target direction based on the area boundary and the table line, to obtain location information of each cell in the table area, where 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 a reconstruction unit 706, connected to the search unit 704, for performing table reconstruction according to the position information of each cell, so as to obtain a reconstructed table corresponding to the document to be reconstructed.
It should be noted that, the detecting unit 702 in this embodiment may be used to perform the step S202 described above, the searching unit 704 in this embodiment may be used to perform the step S204 described above, and the reconstructing unit 706 in this embodiment may be used to perform the step S206 described above.
Through the module, carrying out 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 region boundary and the table line, searching cells in the table region along a target direction to obtain position information of each cell in the table region, wherein the target direction comprises a first direction parallel to the target region boundary of the table region and a second direction perpendicular to the target region boundary; and (3) carrying out table reconstruction according to the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed, thereby solving the problems of high calculation complexity and low table reconstruction efficiency in the related art in a mode of carrying out table reconstruction according to the table grid lines, reducing the calculation complexity of an algorithm and improving the table reconstruction efficiency.
In one exemplary embodiment, the search unit includes:
The first search module is used for searching cells along the target direction in the table area based on the area boundary and the table line to obtain target vertexes of all the cells, wherein the relative positions of the target vertexes of all the cells in all the cells are the same;
and the second search module is used for searching cell boundaries in the table area along the target direction by taking the target vertexes of the cells as starting points based on the area boundaries and the table grid lines to obtain the position information of the cells.
In one exemplary embodiment, the first search module includes:
and the searching sub-module is used for searching the target vertexes of the adjacent cells along the target direction in the table area based on the area boundary and the table line to obtain the target vertexes of the cells.
In one exemplary embodiment, the search sub-module includes:
The searching subunit is used for searching the target vertex of the adjacent cell along the target direction by taking the target vertex of the first cell as a starting point based on the region boundary and the table line 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;
An adding subunit, configured to add the target vertex of the second cell to the search queue;
The execution subunit is configured to sequentially extract, from the search queue, the target vertices of the cells as the target vertices of the current cell, and execute the following steps until the search queue is empty: searching target vertexes of adjacent cells along a target direction by taking the target vertexes of the current cells as starting points based on the region boundary and the table grid lines to obtain the target vertexes of the adjacent cells of the current cells; in the case that the adjacent cell of the current cell is not subjected to the search operation of the target vertex of the adjacent cell, the target vertex of the adjacent cell of the current cell is added to the search queue.
In one exemplary embodiment, the execution subunit includes:
searching a secondary subunit, wherein the secondary subunit is used for searching a region boundary and a table line along a target direction by taking a target vertex of a current cell as a starting point, and searching a reference point on the target boundary, and the target boundary is the boundary of the current cell in the target direction;
A first determining subunit, configured 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, where the candidate vertex is a point obtained by offsetting the reference point by the target distance along the target direction;
And a second determining subunit configured 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 the target distance threshold.
In one exemplary embodiment, the reconstruction unit includes:
the first determining module is used for determining the cell size of each cell and the minimum cell size in 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 of the table area;
A second determining module, configured to determine a reconstruction size of each cell according to a cell size and a minimum cell size of each cell, where the reconstruction size of each cell is used to indicate a number of minimum cells occupied by each cell in the reconstructed table;
and the first reconstruction module is used for carrying out table reconstruction according to the position information of each cell and the reconstruction size of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
In one exemplary embodiment, the reconstruction unit includes:
And the second reconstruction module is used for reconstructing the table according to the search sequence of each cell and the position information of each cell to obtain a reconstructed table corresponding to the document to be reconstructed.
It should be noted that the above modules are the same as examples and application scenarios implemented by the corresponding steps, but are not limited to what is disclosed in the above embodiments. It should be noted that the above modules may be implemented in software or in hardware as part of the apparatus shown in fig. 1, where the hardware environment includes a network environment.
According to yet another aspect of an embodiment of the present application, there is also provided a storage medium. Alternatively, in this embodiment, the storage medium may be used to execute the program code of the method for reconstructing any of the tables described above in the embodiment of the present application.
Alternatively, in this embodiment, the storage medium may be located on at least one network device of the plurality of network devices in the network shown in the above embodiment.
Alternatively, in the present embodiment, the storage medium is configured to store program code for performing the steps of:
S1, carrying out table detection on a document to be reconstructed to obtain the region boundary of a table region in the document to be reconstructed and table lines in the table region;
S2, searching cells in the table area along a target direction based on the area boundary and the table line to obtain the position information of each cell in the table area, wherein the target direction comprises a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary;
s3, carrying out table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
Alternatively, specific examples in the present embodiment may refer to examples described in the above embodiments, which are not described in detail in the present embodiment.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to: various media capable of storing program codes, such as a U disk, ROM, RAM, a mobile hard disk, a magnetic disk or an optical disk.
According to still another aspect of the embodiments of the present application, there is also provided an electronic device for implementing the method for reconstructing a table as described above, where the electronic device may be a server, a terminal, or a combination thereof.
Fig. 8 is a block diagram of an alternative electronic device, according to an embodiment of the present application, as shown in fig. 8, including 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 via the communication bus 808, wherein,
A memory 806 for storing a computer program;
the processor 802, when executing the computer program stored on the memory 806, performs the following steps:
S1, carrying out table detection on a document to be reconstructed to obtain the region boundary of a table region in the document to be reconstructed and table lines in the table region;
S2, searching cells in the table area along a target direction based on the area boundary and the table line to obtain the position information of each cell in the table area, wherein the target direction comprises a first direction parallel to the target area boundary of the table area and a second direction perpendicular to the target area boundary;
s3, carrying out table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed.
Alternatively, in the present embodiment, the communication bus may be a PCI (PERIPHERAL COMPONENT INTERCONNECT, peripheral component interconnect standard) bus, or an EISA (Extended Industry Standard Architecture ) bus, or the like. The communication bus may be classified as an address bus, a data bus, a control bus, or the like. For ease of illustration, only one thick line is shown in fig. 8, but not only one bus or one type of bus. The communication interface is used for communication between the electronic device and other equipment.
The memory may include RAM or may include non-volatile memory (non-volatile memory), such as at least one disk memory. Optionally, the memory may also be at least one memory device located remotely from the aforementioned processor.
As an example, the above memory 806 may be, but is not limited to, the detection unit 702, the search unit 704, and the reconstruction unit 706 in the reconstruction apparatus including the above table. In addition, other module units in the reconstruction device of the table may be included, but are not limited to, and are not described in detail in this example.
The processor may be a general purpose processor and may include, but is not limited to: CPU (Central Processing Unit ), NP (Network Processor, network processor), etc.; but may also be a DSP (DIGITAL SIGNAL Processing), ASIC (Application SPECIFIC INTEGRATED Circuit), FPGA (Field-Programmable gate array) or other Programmable logic device, discrete gate or transistor logic device, discrete hardware components.
Alternatively, specific examples in this embodiment may refer to examples described in the foregoing embodiments, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the structure shown in fig. 8 is only illustrative, and the device implementing the above table reconstruction method may be a terminal device, and the terminal device may be a smart phone (such as an Android Mobile phone, an iOS Mobile phone, etc.), a tablet computer, a palm computer, a Mobile internet device (Mobile INTERNET DEVICES, MID), a PAD, etc. Fig. 8 is not limited to the structure of the electronic device. For example, the electronic device may also include more or fewer components (e.g., network interfaces, display devices, etc.) than shown in FIG. 8, or have a different configuration than shown in FIG. 8.
Those of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be implemented by a program for instructing a terminal device to execute in association with hardware, the program may be stored in a computer readable storage medium, and the storage medium may include: flash disk, ROM, RAM, magnetic or optical disk, etc.
The foregoing embodiment numbers of the present application are merely for the purpose of description, and do not represent the advantages or disadvantages of the embodiments.
The integrated units in the above embodiments may be stored in the above-described computer-readable storage medium if implemented in the form of software functional units and sold or used as separate products. Based on such understanding, the technical solution of the present application may be embodied in essence or a part contributing to the prior art or all or part of the technical solution in the form of a software product stored in a storage medium, comprising several instructions for causing one or more computer devices (which may be personal computers, servers or network devices, etc.) to perform all or part of the steps of the method described in the embodiments of the present application.
In the foregoing embodiments of the present application, the descriptions of the embodiments are emphasized, and for a portion of this disclosure that is not described in detail in this embodiment, reference is made to the related descriptions of other embodiments.
In several embodiments provided by the present application, it should be understood that the disclosed client may be implemented in other manners. The above-described embodiments of the apparatus are merely exemplary, and the division of the units, such as the division of the units, is merely a logical function division, and may be implemented in another manner, for example, multiple units or components may be combined or may be integrated into another system, or some features may be omitted, or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be through some interfaces, units or modules, or may be in electrical or other forms.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution provided in the present embodiment.
In addition, each functional unit in the embodiments of the present application may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The foregoing is merely a preferred embodiment of the present application and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present application, which are intended to be comprehended within the scope of the present application.

Claims (10)

1. A method for reconstructing a form, comprising:
Performing table detection on a document to be reconstructed to obtain the region boundary of a table region in the document to be reconstructed and a table line in the table region;
Performing cell search in the table area along a target direction based on the area boundary and the table grid line to obtain position information of each cell in the table area, wherein whether the area boundary is searched or the table grid line is determined according to the searched color, the target direction comprises a first direction parallel to a 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: upper, lower, left, right;
performing table reconstruction according to the position information of each cell to obtain a reconstruction table corresponding to the document to be reconstructed;
After performing table detection on the document to be reconstructed to obtain an area boundary of the table area and a table line in the table area in the document to be reconstructed, the method further comprises: setting the region boundary and the table line as a first color, and setting other positions except the region boundary and the table line in the document to be reconstructed as a second color, wherein the searched color comprises the first color and the second color.
2. The method of claim 1, wherein performing a cell search along the target direction within the table region based on the region boundary and the table grid lines, obtaining location information for the respective cells within the table region comprises:
Based on the region boundary and the table grid lines, cell searching is carried out in the table region along the target direction to obtain target vertexes of all the cells, wherein the relative positions of the target vertexes of all the cells in all the cells are the same;
and carrying out cell boundary search in the table area along the target direction by taking the target vertex of each cell as a starting point based on the area boundary and the table grid line to obtain the position information of each cell.
3. The method of claim 2, wherein performing a cell search along the target direction within the table region based on the region boundary and the table grid lines, obtaining target vertices for the respective cells comprises:
and searching target vertexes of adjacent cells along the target direction in the table area based on the area boundary and the table grid lines to obtain the target vertexes of each cell.
4. The method of claim 3, wherein searching for the target vertices of neighboring cells along the target direction within the table region based on the region boundaries and the table grid lines, the target vertices of the respective cells comprising:
Searching target vertexes of adjacent cells along the target direction by taking target vertexes of first cells as starting points on the basis of the region boundary and the table grid lines to obtain target vertexes of second cells, wherein the first cells are first searched cells, and the second cells are adjacent cells of the first cells;
adding the target vertex of the second cell to a search queue;
Sequentially extracting target vertexes of the cells from the search queue as target vertexes of the current cells, and executing the following steps until the search queue is empty: searching target vertexes of adjacent cells along the target direction by taking the target vertexes of the current cells as starting points based on the region boundary and the table grid lines to obtain the target vertexes of the adjacent cells of the current cells; and adding the target vertex of the adjacent cell of the current cell into the search queue under the condition that the adjacent cell of the current cell is not subjected to the search operation of the target vertex of the adjacent cell.
5. The method of claim 4, wherein searching for the target vertex of the neighboring cell along the target direction with the target vertex of the current cell as a starting point based on the region boundary and the table grid line, the target vertex of the neighboring cell of the current cell comprising:
Searching the region boundary and the table grid lines along the target direction by taking the target vertex of the current cell as a starting point, and searching a reference point on the target boundary, wherein the target boundary is the boundary of the current cell in the target direction;
Determining candidate vertexes in a third cell adjacent to the current cell in the target direction under the condition that the target boundary is not the region boundary, wherein the candidate vertexes are points obtained by shifting the reference point by a target distance along the target direction;
And determining 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.
6. The method according to claim 1, wherein performing table reconstruction 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 in the cell sizes of each cell according to the position information of each cell, wherein the minimum cell size is the minimum cell size of the table area;
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 for indicating the number of the minimum cells occupied by each cell in a reconstructed table;
And carrying out table reconstruction according to the position information of each cell and the reconstruction size of each cell to obtain the reconstruction table corresponding to the document to be reconstructed.
7. The method according to any one of claims 1 to 6, wherein performing table reconstruction from the positional information of the respective cells to obtain the reconstruction table corresponding to the document to be reconstructed includes:
and carrying out table reconstruction according to the search sequence of each cell and the position information of each cell to obtain the reconstruction table corresponding to the document to be reconstructed.
8. A form reconstruction apparatus, comprising:
the detection unit is used for carrying out 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;
A search unit, configured to search cells in the table area along a target direction based on the area boundary and the table ruled line, to obtain location information of each cell in the table area, where whether the area boundary is searched or the table ruled line is determined according to the searched color, 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, and the target area boundary is one of: upper, lower, left, right;
A reconstruction unit, configured to perform table reconstruction according to the position information of each cell, so as to obtain a reconstructed table corresponding to the document to be reconstructed;
Wherein the device is further for: setting the region boundary and the table line as a first color, and setting other positions except the region boundary and the table line in the document to be reconstructed as a second color, wherein the searched color comprises the first color and the second color.
9. A computer-readable storage medium, characterized in that the computer-readable storage medium comprises a stored program, wherein the program when run performs the method of any one of claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to execute the method according to any of claims 1 to 7 by means of the computer program.
CN202110867193.0A 2021-07-29 2021-07-29 Table reconstruction method and device, storage medium and electronic device Active CN113486638B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110867193.0A CN113486638B (en) 2021-07-29 2021-07-29 Table reconstruction method and device, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110867193.0A CN113486638B (en) 2021-07-29 2021-07-29 Table reconstruction method and device, storage medium and electronic device

Publications (2)

Publication Number Publication Date
CN113486638A CN113486638A (en) 2021-10-08
CN113486638B true CN113486638B (en) 2024-09-24

Family

ID=77944629

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110867193.0A Active CN113486638B (en) 2021-07-29 2021-07-29 Table reconstruction method and device, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN113486638B (en)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114005126A (en) * 2021-11-26 2022-02-01 成都数联云算科技有限公司 Table reconstruction method, apparatus, computer equipment and readable storage medium
CN114419647B (en) * 2021-12-31 2024-07-26 北京译图智讯科技有限公司 Table information extraction method and system
CN117350260B (en) * 2023-12-06 2024-02-27 北京车主邦新能源科技有限公司 Reconstruction method and device for PDF page table contents

Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108446264A (en) * 2018-03-26 2018-08-24 阿博茨德(北京)科技有限公司 Table vector analysis method and device in PDF document

Family Cites Families (12)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
JP4848221B2 (en) * 2006-07-31 2011-12-28 富士通株式会社 Form processing program, recording medium recording the program, form processing apparatus, and form processing method
KR101038198B1 (en) * 2009-05-15 2011-06-01 이승은 Unit information dot pattern structure
KR102056709B1 (en) * 2017-04-25 2019-12-17 한다시스템 주식회사 Method and computer program for extracting table record from spread sheet
CN107885713B (en) * 2017-11-28 2021-12-14 广州视源电子科技股份有限公司 File format conversion method, device, equipment and storage medium
US11200413B2 (en) * 2018-07-31 2021-12-14 International Business Machines Corporation Table recognition in portable document format documents
CN109446487A (en) * 2018-11-01 2019-03-08 北京神州泰岳软件股份有限公司 A kind of method and device parsing portable document format document table
CN112818812B (en) * 2018-12-13 2024-03-12 北京金山数字娱乐科技有限公司 Identification method and device for table information in image, electronic equipment and storage medium
US10846525B2 (en) * 2019-02-15 2020-11-24 Wipro Limited Method and system for identifying cell region of table comprising cell borders from image document
CN110472208A (en) * 2019-06-26 2019-11-19 上海恒生聚源数据服务有限公司 The method, system of form analysis, storage medium and electronic equipment in PDF document
CN112036294B (en) * 2020-08-28 2023-08-25 山谷网安科技股份有限公司 Method and device for automatically identifying paper form structure
CN112528813B (en) * 2020-12-03 2021-07-23 上海云从企业发展有限公司 Table recognition method, device and computer readable storage medium
CN112580594B (en) * 2020-12-29 2024-06-18 浙江大华技术股份有限公司 Document identification method, device, computer equipment and storage medium

Patent Citations (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108446264A (en) * 2018-03-26 2018-08-24 阿博茨德(北京)科技有限公司 Table vector analysis method and device in PDF document

Also Published As

Publication number Publication date
CN113486638A (en) 2021-10-08

Similar Documents

Publication Publication Date Title
CN113486638B (en) Table reconstruction method and device, storage medium and electronic device
CN110502985B (en) Form identification method and device and form identification equipment
JP7026165B2 (en) Text recognition method and text recognition device, electronic equipment, storage medium
CN107545262A (en) A kind of method and device that text is detected in natural scene image
CN110968375B (en) Interface control method and device, intelligent terminal and computer readable storage medium
CN109508189B (en) Layout template processing method and device and computer readable storage medium
CN108734304B (en) Training method and device of data model and computer equipment
CN111124888A (en) Method and device for generating recording script and electronic device
CN110399760A (en) A batch two-dimensional code positioning method, device, electronic device and storage medium
CN114429637B (en) Document classification method, device, equipment and storage medium
CN114241499A (en) Table picture identification method, device and equipment and readable storage medium
CN114005126A (en) Table reconstruction method, apparatus, computer equipment and readable storage medium
CN112988557A (en) Search box positioning method, data acquisition device and medium
CN115546809A (en) Table structure identification method based on cell constraint and application thereof
CN116152171A (en) Intelligent construction target counting method, electronic equipment and storage medium
US9373193B2 (en) Method and apparatus for detecting and avoiding conflicts of space entity element annotations
CN109740074B (en) Method, device and equipment for processing parameter configuration information
CN113886745B (en) Page picture testing method and device and electronic equipment
CN115270711A (en) Electronic signature method, electronic signature device, electronic apparatus, and storage medium
CN112286785B (en) Abnormality detection method and device for user interface
CN115457581A (en) Table extraction method and device and computer equipment
CN110399581B (en) Page rendering method, equipment, storage medium and device based on machine learning
CN115271015A (en) Two-dimensional code generation method, scanning method, device, system, equipment and medium
CN116524386A (en) Video detection method, apparatus, device, readable storage medium, and program product
CN113158632A (en) Form reconstruction method for CAD drawing and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant