WO2021147252A1 - 基于ocr的表格版式恢复方法、装置、电子设备及存储介质 - Google Patents

基于ocr的表格版式恢复方法、装置、电子设备及存储介质 Download PDF

Info

Publication number
WO2021147252A1
WO2021147252A1 PCT/CN2020/098981 CN2020098981W WO2021147252A1 WO 2021147252 A1 WO2021147252 A1 WO 2021147252A1 CN 2020098981 W CN2020098981 W CN 2020098981W WO 2021147252 A1 WO2021147252 A1 WO 2021147252A1
Authority
WO
WIPO (PCT)
Prior art keywords
picture
restored
preset
cell
text
Prior art date
Application number
PCT/CN2020/098981
Other languages
English (en)
French (fr)
Inventor
何嘉欣
刘鹏
刘玉宇
肖京
Original Assignee
平安科技(深圳)有限公司
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 平安科技(深圳)有限公司 filed Critical 平安科技(深圳)有限公司
Publication of WO2021147252A1 publication Critical patent/WO2021147252A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/40Document-oriented image-based pattern recognition
    • G06V30/41Analysis of document content
    • G06V30/413Classification of content, e.g. text, photographs or tables
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/40Document-oriented image-based pattern recognition
    • G06V30/41Analysis of document content
    • G06V30/414Extracting the geometrical structure, e.g. layout tree; Block segmentation, e.g. bounding boxes for graphics or text
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06VIMAGE OR VIDEO RECOGNITION OR UNDERSTANDING
    • G06V30/00Character recognition; Recognising digital ink; Document-oriented image-based pattern recognition
    • G06V30/10Character recognition

Definitions

  • This application relates to the field of image recognition, and in particular to an OCR-based method, device, electronic device, and storage medium for restoring form layouts.
  • this application provides an OCR-based method, device, electronic device, and computer-readable storage medium for restoring table layouts, the main purpose of which is to improve the accuracy of restoring table layouts.
  • this application provides an OCR-based form format restoration method, which includes:
  • Receiving step receiving a form format recovery instruction issued by a user, where the form format recovery instruction includes the form picture to be recovered and the picture type of the form picture to be recovered;
  • Recognition step performing first OCR recognition on the table picture to be restored to obtain a first recognition result, the first recognition result including a plurality of text boxes of the picture to be restored and text information corresponding to the plurality of text boxes;
  • Cutting step determining a cutting line of the table picture to be restored based on the first recognition result and a preset cutting rule, and determining a target table structure based on the cutting line;
  • the first restoring step writing the multiple text boxes into the cells in the target table structure based on a preset filling rule to generate a first table;
  • the second recovery step identify abnormal cells from the first table based on preset identification rules, intercept the abnormal areas corresponding to the abnormal cells, send the abnormal areas to a preset terminal, and receive the preset
  • the abnormal cell information corresponding to the abnormal area returned by the terminal updates the first table based on the abnormal cell information to obtain the target table;
  • Feedback step feedback the target form to the user.
  • this application also provides an OCR-based form format restoration device, including:
  • a receiving module configured to receive a form format recovery instruction issued by a user, the form format recovery instruction including the form picture to be recovered and the picture type of the form picture to be recovered;
  • a recognition module configured to perform a first OCR recognition on the table picture to be restored to obtain a first recognition result, the first recognition result including a plurality of text boxes of the picture to be restored and text corresponding to the plurality of text boxes information;
  • a cutting module configured to determine a cutting line of the table picture to be restored based on the first recognition result and a preset cutting rule, and determine a target table structure based on the cutting line;
  • the first recovery module is configured to write the multiple text boxes into the cells in the target table structure based on a preset filling rule to generate a first table;
  • the second recovery module is configured to identify abnormal cells from the first table based on preset identification rules, intercept the abnormal areas corresponding to the abnormal cells, send the abnormal areas to the preset terminal, and receive the Preset the abnormal cell information corresponding to the abnormal area returned by the terminal, and update the first table based on the abnormal cell information to obtain the target table; and
  • the feedback module is used to feed back the target form to the user.
  • the present application also provides an electronic device, which includes a memory and a processor.
  • the memory stores an OCR-based table layout recovery program that can run on the processor.
  • OCR-based table layout restoration program is executed by the processor, the following steps are implemented:
  • the form layout recovery instruction including the form picture to be recovered and the picture type of the form picture to be recovered;
  • Identify abnormal cells from the first table based on a preset recognition rule intercept the abnormal area corresponding to the abnormal cell, send the abnormal area to a preset terminal, and receive the return from the preset terminal Update the first table based on the abnormal cell information corresponding to the abnormal area to obtain the target table;
  • the present application also provides a computer-readable storage medium that includes an OCR-based table layout recovery program that is executed when the OCR-based table layout recovery program is executed by a processor. To achieve the following steps:
  • the form layout recovery instruction including the form picture to be recovered and the picture type of the form picture to be recovered;
  • Identify abnormal cells from the first table based on a preset recognition rule intercept the abnormal area corresponding to the abnormal cell, send the abnormal area to a preset terminal, and receive the return from the preset terminal Update the first table based on the abnormal cell information corresponding to the abnormal area to obtain the target table;
  • the OCR-based method, device, electronic device, and computer-readable storage medium for restoring table layouts proposed in this application generate the target table structure after OCR recognition is performed on the table image to be restored and the row/column cutting line is determined, and the OCR recognition result is used Fill in the cells of the target table structure in sequence to obtain the first table, and generate the target table to feed back to the user by identifying and processing the abnormal cells in the first table. By identifying abnormal cells in the first table (a.
  • the improvement is improved
  • the accuracy of the content of each cell improves the accuracy of the table layout restoration; by using the column ratio of the header page in the table picture to be restored to map the column cutting line for the headerless page, the headerless page is improved
  • the recognition accuracy of the column cutting line of the page lays the foundation for improving the accuracy of the recovery of the table layout.
  • FIG. 1 is a flowchart of a preferred embodiment of a method for restoring form layout based on OCR in this application;
  • FIG. 2 is a schematic diagram of a preferred embodiment of the electronic device of this application.
  • FIG. 3 is a schematic diagram of modules of a preferred embodiment of an OCR-based table layout restoration device of the present application.
  • This application provides an OCR-based form layout restoration method.
  • the method can be executed by an electronic device, and the electronic device can be implemented by software and/or hardware.
  • FIG. 1 it is a flowchart of a preferred embodiment of a method for restoring a form layout based on OCR of this application.
  • the OCR-based form layout restoration method includes: step S1-step S6.
  • Step S1 receiving a form format recovery instruction issued by a user, the form format recovery instruction including the form picture to be recovered and the picture type of the form picture to be recovered.
  • the electronic device is used as the execution subject to describe each embodiment of the present application.
  • the picture of the table to be restored is a table without a table line.
  • the table pictures to be restored need to meet several characteristics: the rows and columns are arranged neatly; there is a certain distance between the rows and columns (the larger the distance, the higher the accuracy); the table has a header And each column of information corresponds to the header; the header information of the same type of table is fixed.
  • the picture type of the table picture to be restored is used to distinguish table pictures corresponding to different application scenarios.
  • different tables of the same type correspond to the same header information.
  • the header information includes: “unit price”, “quantity”, “amount”, “project name”, etc.
  • the header information includes: “project”, “this Years”, “Amount”, “Balance at the beginning of the year”, etc.
  • the user selects the table picture to be restored and its corresponding picture type through the APP on the client, and sends out a table format restoration instruction.
  • the electronic device After receiving the instruction sent by the client, the electronic device performs the operation of extracting the detailed content of the table on the picture of the table to be restored carried in the instruction.
  • Step S2 Perform a first OCR recognition on the table picture to be restored to obtain a first recognition result.
  • the first recognition result includes a plurality of text boxes of the picture to be restored and text information corresponding to the plurality of text boxes.
  • the recognition result obtained by performing the first OCR recognition on the table picture to be restored includes: multiple text boxes, coordinate information of the multiple text boxes, and text information corresponding to the text boxes. In view of the mature OCR recognition technology in the prior art, it will not be repeated here.
  • Step S3 Determine a cutting line of the table picture to be restored based on the first recognition result and a preset cutting rule, and determine a target table structure based on the cutting line.
  • the determining the cutting line of the table picture to be restored according to the first recognition result and the preset cutting rule includes:
  • the performing row cutting on the table picture to be restored based on the first recognition result and a preset row cutting rule, and determining the row cutting line of the table picture to be restored includes:
  • the range of the aforementioned preset angle can be set from -1° to 1°, with a step length of 0.1°.
  • the projected coordinates of each text box on the y-axis are obtained, and the current projected coordinates are determined based on the projected coordinates of each text box.
  • Rotate the projection interval corresponding to the rotation angle and record the number and coordinates of overlapping projection segments. Select the angle with the most overlapping projection segments among these angles, and draw a line cutting line based on the overlapping projection segments.
  • the determining the row cutting lines of the multiple text boxes at the target angle according to the overlapping projection segments corresponding to the target angle includes:
  • the finally determined rotated table picture to be restored and the row cutting line can determine the row information of the rotated table picture to be restored and the text box corresponding to each row.
  • the determining the header information corresponding to the table picture to be restored according to the picture type includes:
  • mapping data of the predetermined picture type and the header keyword set from a preset storage path, and determine the header keyword set corresponding to the table picture to be restored according to the picture type and the mapping data;
  • Each picture type in the above-mentioned mapping data corresponds to a keyword set. It should be noted that it is necessary to pre-determine the header information corresponding to multiple image types, determine the keyword set corresponding to multiple image types, generate the mapping data of the image type and the keyword set, and save the mapping data to the preset storage path middle.
  • the column dividing line is calculated using the position information of the header.
  • tables of the same type have similar header content, and the header content generally does not appear in the redundant information at the top of the table, nor does it appear in the detailed entries. Therefore, it is an effective method to locate the header by searching keywords.
  • searching keywords Taking the expense list as an example, after row cutting is performed on the table picture to be restored, the text boxes of each row of the table picture to be restored are determined, and the text boxes of each row are arranged from top to bottom, and the text information of the text boxes and the determined The keyword set is compared. When the keywords "unit price”, "quantity”, and "amount" appear, the search stops, and the row where the element is located is found. This row is the header.
  • the column cutting line is further determined according to the header information.
  • the performing column cutting on the table picture to be restored based on the header information and preset column cutting rules, and determining the column cutting line of the table picture to be restored includes:
  • header information contains 6 header elements
  • the header information contains 6 header elements
  • the position information of each text box that is, the coordinates
  • determine the rightmost point of the text box and set the 6
  • the 6 rightmost points corresponding to the header elements are used as column cutting points, and vertical cutting lines are used to cut the columns.
  • the column cutting of the table picture to be restored is performed based on the header information and a preset column cutting rule, and the column cutting line of the table picture to be restored is determined ,Also includes:
  • a vertical dividing line is used to initially locate the column cutting point on the far right of the outer border of each header element.
  • Such a column cutting point may be inaccurate.
  • the column cutting line of a certain header element may be Go through its corresponding detailed content.
  • the horizontal arrangement of the table details is relatively neat, with certain boundaries, usually aligned to the left or right in the table. This feature can be used in the correction of column cutting.
  • the standard deviation represents whether this column has features that are aligned to the left or right.
  • the table can be considered to have alignment features, and the corresponding column
  • the cutting point is moved to the average of the boundary points (for example, the x-axis coordinate of the rightmost point) of the text box of the column, otherwise the initially positioned column cutting point remains unchanged.
  • the accuracy of the column cutting line adjusted through the above steps is improved.
  • Step S4 Write the multiple text boxes into cells in the target table structure based on a preset filling rule to generate a first table.
  • the writing of the multiple text boxes into the cells in the target table structure based on a preset filling rule includes:
  • the text box corresponding to each cell In the process of filling cells, you must first determine the text box corresponding to each cell. It should be noted that the same text box may be located between two adjacent cells in the target table structure. In order to further ensure the accuracy of table details extraction, the calculation in each cell should be composed of column cutting lines and row cutting lines The quadrilateral area of, and the overlap area of the text box that has an intersection with it. If the overlap area occupies more than 0.5 of the area of the text box, the text box is considered to belong to the corresponding cell. In other embodiments, if there are multiple text boxes that meet the above conditions, they are placed according to the priority of the upper and left positions.
  • the text information corresponding to the text box is filled into the cells in a preset order.
  • the above-mentioned preset order is: in the order of rows/columns from top to bottom, and from left to right.
  • Step S5 Identify an abnormal cell from the first table based on a preset identification rule, intercept the abnormal area corresponding to the abnormal cell, send the abnormal area to a preset terminal, and receive the preset terminal return
  • the first table is updated based on the abnormal cell information corresponding to the abnormal area, and the target table is obtained.
  • the above-mentioned preset terminal is a terminal used by a designated reviewer, for example, a crowdsourcer.
  • the abnormal area corresponding to the abnormal cell includes: the abnormal cell and the area formed by the left and right cells close to the abnormal cell.
  • the abnormality of the cells in the first table In order to improve the accuracy of extracting the details of the table, it is necessary to identify the abnormality of the cells in the first table.
  • the abnormal area corresponding to the abnormal cell is fed back to the terminal used by the crowdsourced personnel for the public.
  • the package staff will confirm the modification and feedback to deal with the abnormal cells.
  • the identifying abnormal cells from the first table based on a preset identification rule includes:
  • the first cell is a cell with content
  • the second cell is a cell with empty content.
  • the first cell and the second cell in each column of cells are determined in sequence from left to right. Count the number of the first cell and the total number of cells in the column, and calculate the proportion of the column of the first cell to the total number of cells. If the proportion of rows with content in a column exceeds 70%, judge the remaining empty rows There is an exception.
  • the cells that are suspected of structural errors are processed to ensure that the contents of each cell are not missing or merged.
  • the identifying abnormal cells from the first table based on a preset recognition rule further includes:
  • the recognition models in the first OCR recognition and the second OCR recognition are different.
  • the first OCR recognition model is CNN+RNN+CTC
  • the second OCR recognition model is: CNN+Seq2Seq+Attention
  • the training data must be Are mutually independent, so that the recognition results of different recognition models are also independent of each other.
  • the training data of the first OCR recognition model only includes letters, symbols, and numbers
  • the training data of the second OCR recognition model includes Chinese characters, letters, numbers, etc., so that different recognition models can accurately recognize different objects.
  • the accuracy of model A is x and the accuracy of model B is y. If a picture is recognized in model A and recognized in model B If the result is the same, the probability that the result is an incorrect result is (1-x)*(1-y). For example, if x is 98% and y is 97.5%, the error probability when the recognition result is the same is 0.05% , which is approximately 0. Therefore, when the recognition results obtained by two mutually independent models are the same, the probability that this result is correct is 99.95%. Based on this, this part of the result can be regarded as a correct result, and the part with different results from the two models can be regarded as a suspected wrong result.
  • Step S6 feeding back the target form to the user.
  • the target form obtained through form layout restoration is fed back to the user through the client.
  • the target table structure is generated, and the cells of the target table structure are sequentially filled with the OCR recognition result to obtain
  • the first form generates a target form for feedback to the user by identifying and processing abnormal cells in the first form.
  • the same table file has a similar row and column structure.
  • the long part will be paged, and the paged part may not have header information. Due to the error of the angle and three-dimensional rotation between each picture during the photographing and scanning process, the cutting line may not be possible. It is directly determined that, in order to further improve the accuracy of the column cutting line, in other embodiments, when the table picture to be restored includes a header page and a page without header having the same row and column structure, the step S3 further includes:
  • the ratio is within this range for column cutting mapping.
  • the minimum boundary point can be understood as the point corresponding to the minimum value of x in the coordinate value of the first text box
  • the maximum boundary point can be understood as the point corresponding to the maximum value of x in the coordinate value of the last text box.
  • FIG. 2 is a schematic diagram of a preferred embodiment of the electronic device of this application.
  • the electronic device 1 may be a terminal device with data processing functions such as a server, a smart phone, a tablet computer, a portable computer, a desktop computer, etc.
  • the server may be a rack server, a blade server, or a tower. Server or rack server.
  • the electronic device 1 includes a memory 11, a processor 12 and a network interface 13.
  • the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), magnetic memory, magnetic disk, optical disk, and the like.
  • the memory 11 may be an internal storage unit of the electronic device 1 in some embodiments, such as a hard disk of the electronic device 1.
  • the memory 11 may also be an external storage device of the electronic device 1, such as a plug-in hard disk, a smart media card (SMC), and a secure digital (Secure Digital) equipped on the electronic device 1. , SD) card, flash card (Flash Card), etc.
  • the memory 11 may also include both an internal storage unit of the electronic device 1 and an external storage device.
  • the memory 11 can be used not only to store application software and various types of data installed in the electronic device 1, such as an OCR-based table layout recovery program 10, etc., but also to temporarily store data that has been output or will be output.
  • the processor 12 may be a central processing unit (CPU), controller, microcontroller, microprocessor or other data processing chip in some embodiments, and is used to run the program code or processing stored in the memory 11 Data, for example, OCR-based table layout recovery program 10, etc.
  • CPU central processing unit
  • controller microcontroller
  • microprocessor microprocessor or other data processing chip in some embodiments, and is used to run the program code or processing stored in the memory 11 Data, for example, OCR-based table layout recovery program 10, etc.
  • the network interface 13 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface), and is usually used to establish a communication connection between the electronic device 1 and other electronic devices, for example, a client (not marked in the figure). ).
  • the components 11-13 of the electronic device 1 communicate with each other via a communication bus.
  • FIG. 2 only shows the electronic device 1 with components 11-13. Those skilled in the art can understand that the structure shown in FIG. 2 does not constitute a limitation on the electronic device 1, and may include fewer or more components than shown in the figure. Multiple components, or a combination of certain components, or different component arrangements.
  • the electronic device 1 may also include a user interface.
  • the user interface may include a display (Display) and an input unit such as a keyboard (Keyboard).
  • the optional user interface may also include a standard wired interface and a wireless interface.
  • the display may be an LED display, a liquid crystal display, a touch-sensitive liquid crystal display, an organic light-emitting diode (OLED) touch device, and the like.
  • the display may also be called a display screen or a display unit, which is used to display the information processed in the electronic device 1 and to display a visualized user interface.
  • the memory 11 which is a computer storage medium, stores the program code of the OCR-based table layout recovery program 10, and the processor 12 executes the program of the OCR-based table layout recovery program 10
  • the processor 12 executes the program of the OCR-based table layout recovery program 10
  • the receiving step is to receive a form layout recovery instruction issued by a user, the form layout recovery instruction includes the form picture to be recovered and the picture type of the form picture to be recovered.
  • the picture of the table to be restored is a table without a table line.
  • the table pictures to be restored need to meet several characteristics: the rows and columns are arranged neatly; there is a certain distance between the rows and columns (the larger the distance, the higher the accuracy); the table has a header And each column of information corresponds to the header; the header information of the same type of table is fixed.
  • the picture type of the table picture to be restored is used to distinguish table pictures corresponding to different application scenarios.
  • different tables of the same type correspond to the same header information.
  • the header information includes: “unit price”, “quantity”, “amount”, “project name”, etc.
  • the header information includes: “project”, “this Years”, “Amount”, “Balance at the beginning of the year”, etc.
  • the user selects the table picture to be restored and its corresponding picture type through the APP on the client, and sends out a table format restoration instruction.
  • the electronic device 1 After receiving the instruction sent by the client, the electronic device 1 performs the operation of extracting the detailed content of the table on the picture of the table to be restored carried in the instruction.
  • a first OCR recognition is performed on the table picture to be restored to obtain a first recognition result
  • the first recognition result includes a plurality of text boxes of the picture to be restored and text information corresponding to the plurality of text boxes.
  • the recognition result obtained by performing the first OCR recognition on the table picture to be restored includes: multiple text boxes, coordinate information of the multiple text boxes, and text information corresponding to the text boxes. In view of the mature OCR recognition technology in the prior art, it will not be repeated here.
  • a cutting line of the table picture to be restored is determined based on the first recognition result and a preset cutting rule, and a target table structure is determined based on the cutting line.
  • the determining the cutting line of the table picture to be restored according to the first recognition result and the preset cutting rule includes:
  • the performing row cutting on the table picture to be restored based on the first recognition result and a preset row cutting rule, and determining the row cutting line of the table picture to be restored includes:
  • the range of the aforementioned preset angle can be set from -1° to 1°, with a step length of 0.1°.
  • the projected coordinates of each text box on the y-axis are obtained, and the current projected coordinates are determined based on the projected coordinates of each text box.
  • Rotate the projection interval corresponding to the rotation angle and record the number and coordinates of overlapping projection segments. Select the angle with the most overlapping projection segments among these angles, and draw a line cutting line based on the overlapping projection segments.
  • the determining the row cutting lines of the multiple text boxes at the target angle according to the overlapping projection segments corresponding to the target angle includes:
  • the finally determined rotated table picture to be restored and the row cutting line can determine the row information of the rotated table picture to be restored and the text box corresponding to each row.
  • the determining the header information corresponding to the table picture to be restored according to the picture type includes:
  • mapping data of the predetermined picture type and the header keyword set from a preset storage path, and determine the header keyword set corresponding to the table picture to be restored according to the picture type and the mapping data;
  • Each picture type in the above-mentioned mapping data corresponds to a keyword set. It should be noted that it is necessary to pre-determine the header information corresponding to multiple image types, determine the keyword set corresponding to multiple image types, generate the mapping data of the image type and the keyword set, and save the mapping data to the preset storage path middle.
  • the column dividing line is calculated using the position information of the header.
  • tables of the same type have similar header content, and the header content generally does not appear in the redundant information at the top of the table, nor does it appear in the detailed entries. Therefore, it is an effective method to locate the header by searching keywords. Take the expense list as an example. After row cutting of the table picture to be restored is performed to determine the text box of each row of the table picture to be restored, the text boxes of each row are arranged from top to bottom, and the text information of the text box and the determined The keyword set is compared. When the keywords "unit price”, "quantity”, and "amount" appear, the search stops, and the row where the element is located is found. This row is the header.
  • the column cutting line is further determined according to the header information.
  • the performing column cutting on the table picture to be restored based on the header information and preset column cutting rules, and determining the column cutting line of the table picture to be restored includes:
  • header information contains 6 header elements
  • the header information contains 6 header elements
  • the position information of each text box that is, the coordinates
  • determine the rightmost point of the text box and set the 6
  • the 6 rightmost points corresponding to the header elements are used as column cutting points, and vertical cutting lines are used to cut the columns.
  • the column cutting of the table picture to be restored is performed based on the header information and a preset column cutting rule, and the column cutting line of the table picture to be restored is determined ,Also includes:
  • a vertical dividing line is used to initially locate the column cutting point on the far right of the outer border of each header element.
  • Such a column cutting point may be inaccurate.
  • the column cutting line of a certain header element may be Go through its corresponding detailed content.
  • the horizontal arrangement of the table details is relatively neat, with certain boundaries, usually aligned to the left or right in the table. This feature can be used in the correction of column cutting.
  • the standard deviation represents whether this column has features that are aligned to the left or right.
  • the table can be considered to have alignment features, and the corresponding column
  • the cutting point is moved to the average of the boundary points (for example, the x-axis coordinate of the rightmost point) of the text box of the column, otherwise the initially positioned column cutting point remains unchanged.
  • the accuracy of the column cutting line adjusted through the above steps is improved.
  • the first restoring step is to write the multiple text boxes into the cells in the target table structure based on a preset filling rule to generate a first table.
  • the writing of the multiple text boxes into the cells in the target table structure based on a preset filling rule includes:
  • the text box corresponding to each cell In the process of filling cells, you must first determine the text box corresponding to each cell. It should be noted that the same text box may be located between two adjacent cells in the target table structure. In order to further ensure the accuracy of table details extraction, the calculation in each cell should be composed of column cutting lines and row cutting lines The quadrilateral area of, and the overlap area of the text box that has an intersection with it. If the overlap area occupies more than 0.5 of the area of the text box, the text box is considered to belong to the corresponding cell. In other embodiments, if there are multiple text boxes that meet the above conditions, they are placed according to the priority of the upper and left positions.
  • the text information corresponding to the text box is filled into the cells in a preset order.
  • the above-mentioned preset order is: in the order of rows/columns from top to bottom, and from left to right.
  • the second restoration step is to identify abnormal cells from the first table based on preset identification rules, intercept the abnormal areas corresponding to the abnormal cells, send the abnormal areas to a preset terminal, and receive the preset
  • the abnormal cell information corresponding to the abnormal area returned by the terminal updates the first table based on the abnormal cell information to obtain the target table.
  • the above-mentioned preset terminal is a terminal used by a designated reviewer, for example, a crowdsourcer.
  • the abnormal area corresponding to the abnormal cell includes: the abnormal cell and the area formed by the left and right cells close to the abnormal cell.
  • the abnormality of the cells in the first table In order to improve the accuracy of extracting the details of the table, it is necessary to identify the abnormality of the cells in the first table.
  • the abnormal area corresponding to the abnormal cell is fed back to the terminal used by the crowdsourced personnel for the public.
  • the package staff will confirm the modification and feedback to deal with the abnormal cells.
  • the identifying abnormal cells from the first table based on a preset identification rule includes:
  • the first cell is a cell with content
  • the second cell is a cell with empty content.
  • the first cell and the second cell in each column of cells are determined in sequence from left to right. Count the number of the first cell and the total number of cells in the column, and calculate the proportion of the column of the first cell to the total number of cells. If the proportion of rows with content in a column exceeds 70%, judge the remaining empty rows There is an exception.
  • the cells that are suspected of structural errors are processed to ensure that the contents of each cell are not missing or merged.
  • the identifying abnormal cells from the first table based on a preset recognition rule further includes:
  • the recognition models in the first OCR recognition and the second OCR recognition are different.
  • the first OCR recognition model is CNN+RNN+CTC
  • the second OCR recognition model is: CNN+Seq2Seq+Attention
  • the training data must be Are mutually independent, so that the recognition results of different recognition models are also independent of each other.
  • the training data of the first OCR recognition model only includes letters, symbols, and numbers
  • the training data of the second OCR recognition model includes Chinese characters, letters, numbers, etc., so that different recognition models can accurately recognize different objects.
  • the accuracy of model A is x and the accuracy of model B is y. If a picture is recognized in model A and recognized in model B If the result is the same, the probability that the result is an incorrect result is (1-x)*(1-y). For example, if x is 98% and y is 97.5%, the error probability when the recognition result is the same is 0.05% , which is approximately 0. Therefore, when the recognition results obtained by two mutually independent models are the same, the probability that this result is correct is 99.95%. Based on this, this part of the result can be regarded as a correct result, and the part with different results from the two models can be regarded as a suspected wrong result.
  • the target form is fed back to the user.
  • FIG. 3 is a schematic diagram of modules of the OCR-based table layout restoration apparatus 100 of this application.
  • the OCR-based table layout restoration device 100 includes: modules 110-160, wherein:
  • the receiving module 110 is configured to receive a form format recovery instruction issued by a user, where the form format recovery instruction includes a form picture to be recovered and a picture type of the form picture to be recovered;
  • the recognition module 120 is configured to perform a first OCR recognition on the table picture to be restored to obtain a first recognition result, and the first recognition result includes a plurality of text boxes of the picture to be restored and corresponding text boxes Text message
  • the cutting module 130 is configured to determine a cutting line of the table picture to be restored based on the first recognition result and a preset cutting rule, and determine a target table structure based on the cutting line;
  • the first recovery module 140 is configured to write the multiple text boxes into cells in the target table structure based on a preset filling rule to generate a first table;
  • the second recovery module 150 is configured to identify abnormal cells from the first table based on a preset identification rule, intercept the abnormal area corresponding to the abnormal cell, send the abnormal area to a preset terminal, and receive all the abnormal cells.
  • the feedback module 160 is configured to feed back the target form to the user.
  • modules 110-160 are all similar to the above, and will not be described in detail here.
  • the embodiment of the present application also proposes a computer-readable storage medium.
  • the computer-readable storage medium may be non-volatile or volatile.
  • the computer-readable storage medium includes an OCR-based table format.
  • a restoration program 10 which implements any steps of the OCR-based table layout restoration method when the OCR-based table layout restoration program 10 is executed by a processor.
  • the specific implementation of the computer-readable storage medium of the present application is substantially the same as the foregoing method embodiment, and will not be repeated here.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Vision & Pattern Recognition (AREA)
  • Physics & Mathematics (AREA)
  • Artificial Intelligence (AREA)
  • General Physics & Mathematics (AREA)
  • Multimedia (AREA)
  • Theoretical Computer Science (AREA)
  • Computer Graphics (AREA)
  • Geometry (AREA)
  • Character Input (AREA)

Abstract

一种基于OCR的表格版式恢复方法、装置、电子设备及计算机存储介质,涉及图像处理领域。所述方法包括:接收用户发出的携带待恢复表格图片的指令;对待恢复表格图片进行OCR识别并确定行/列切割线后,生成目标表格结构;利用OCR识别结果依次填充目标表格结构的单元格,得到第一表格;识别并处理第一表格中的异常单元格生成目标表格,并将所述目标表格发送给所述用户。该方法可以提高表格版式恢复的准确性。

Description

基于OCR的表格版式恢复方法、装置、电子设备及存储介质
本申请要求于2020年1月22日提交中国专利局、申请号为CN202010076368.1、发明名称为“基于OCR的表格版式恢复方法、装置及存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及图像识别领域,尤其涉及一种基于OCR的表格版式恢复方法、装置、电子设备及存储介质。
背景技术
随着办公中纸质表格使用的增加,随之而来的是大量需要处理与统计的表格数据,处理这些数据需要耗费大量人力。若通过计算机对扫描后的表格图像进行提取并还原成电子表格,就能够通过程序批量处理并分析表格的各项数据,提高办公效率。
在通用OCR识别的检测和识别准确率都很高的情况下,对于规范的段落文章和带表格线的表格已经有成熟的方法提取结构化数据,例如,使用深度学习方式从图像中直接提取表格特征的方法,发明人意识到这种方式识别率不高;还可以利用形态学来检测表格的一些特征,如表格框线,但这种方式依赖表格框线的特性,若遇到无框线的表格,这种方法便失效。因此,对于无表格线的表格图片,在结构化时还有很大挑战,难度主要在于如何把单元格划分出来。
另外,相当一部分表格图片两列的文本距离并非通用识别检测可有效分离的,有时两列文本甚至会交叉。这种情况下仅靠通用识别和相关切割逻辑无法有效将合并在一起的文本框分离。因此,亟需提供一种更准确、适用范围更广的表格明细结构化提取方法。
发明内容
鉴于以上内容,本申请提供一种基于OCR的表格版式恢复方法、装置、电子设备及计算机可读存储介质,其主要目的在于提高表格版式恢复的准确性。
为实现上述目的,本申请提供一种基于OCR的表格版式恢复方法,该方法包括:
接收步骤:接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
识别步骤:对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
切割步骤:基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
第一恢复步骤:基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
第二恢复步骤:基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
反馈步骤:将所述目标表格反馈至所述用户。
为实现上述目的,本申请还提供一种基于OCR的表格版式恢复装置,包括:
接收模块,用于接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
识别模块,用于对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
切割模块,用于基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
第一恢复模块,用于基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
第二恢复模块,用于基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
反馈模块,用于将所述目标表格反馈至所述用户。
此外,为实现上述目的,本申请还提供一种电子设备,该电子设备包括:存储器、处理器,所述存储器中存储有可在所述处理器上运行的基于OCR的表格版式恢复程序,所述基于OCR的表格版式恢复程序被所述处理器执行时实现如下步骤:
接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
将所述目标表格反馈至所述用户。
此外,为实现上述目的,本申请还提供一种计算机可读存储介质,所述计算机可读存储介质中包括基于OCR的表格版式恢复程序,所述基于OCR的表格版式恢复程序被处理器执行时实现如下步骤:
接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
将所述目标表格反馈至所述用户。
本申请提出的基于OCR的表格版式恢复方法、装置、电子设备及计算机可读存储介质,在对待恢复表格图片进行OCR识别并确定行/列切割线后,生成目标表格结构,并利用OCR识别结果依次填充目标表格结构的单元格,得到第一表格,通过识别并处理第一表格中的异常单元格生成目标表格反馈至用户。通过识别出第一表格中的异常单元格(a. 存在合并或重叠的单元格;及文本信息可能不准确的单元格),并将异常单元格反馈到预设终端以供修改确认,提高了每个单元格内容的准确性,从而提高了表格版式恢复的准确性;通过利用待恢复表格图片中的有表头页的列比例映射出无表头页的列切割线,提高了无表头页的列切割线的识别准确性,为了提高表格版式恢复的准确性奠定基础。
附图说明
图1为本申请基于OCR的表格版式恢复方法较佳实施例的流程图;
图2为本申请电子设备较佳实施例的示意图;
图3为本申请基于OCR的表格版式恢复装置较佳实施例的模块示意图。
本申请目的的实现、功能特点及优点将结合实施例,参照附图做进一步说明。
具体实施方式
应当理解,此处所描述的具体实施例仅仅用以解释本申请,并不用于限定本申请。
本申请提供一种基于OCR的表格版式恢复方法。该方法可以由一个电子设备执行,该电子设备可以由软件和/或硬件实现。
参照图1所示,为本申请基于OCR的表格版式恢复方法较佳实施例的流程图。
在本申请基于OCR的表格版式恢复方法一较佳实施例中,所述基于OCR的表格版式恢复方法包括:步骤S1-步骤S6。
步骤S1,接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型。
以下以电子设备作为执行主体对本申请各实施例进行说明。
在本实施例中,所述待恢复表格图片为无表格线的表格。需要说明的是,为了保证表格版式恢复的准确性,待恢复表格图片需满足几个特点:行、列排列整齐;行列间有一定间距(间距越大,准确性越高);表格具有表头且每一列信息与表头对应;同一类型的表格的表头信息固定。
所述待恢复表格图片的图片类型用于区分不同应用场景对应的表格图片,本实施例默认同一类型的不同表格对应相同的表头信息。例如,费用清单这类表格图片,表头信息包括:“单价”、“数量”、“金额”、“项目名称”等,财务报表这类表格图片,表头信息包括:“项目”、“本年数”、“金额”、“年初余额”等。
用户通过客户端上的APP选择待恢复表格图片及其对应的图片类型,并发出表格版式恢复指令。电子设备接收到客户端发出的指令后,对指令中携带的待恢复表格图片进行提取表格明细内容的操作。
步骤S2,对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息。
上述对待恢复表格图片进行第一OCR识别得到的识别结果包括:多个文本框、所述多个文本框的坐标信息及所述文本框对应的文本信息。鉴于现有技术中已经有成熟的OCR识别技术,故在此不作赘述。
步骤S3,基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构。
在提取表格明细之前,需先分析待恢复表格图片的行切割线及列切割线,以确定图片中的表格结构。在本实施例中,所述根据所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,包括:
a1、基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线;
a2、根据所述图片类型确定所述待恢复表格图片对应的表头信息,基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割 线;及
a3、根据所述待恢复表格图片的行切割线及列切割线确定所述目标表格结构。
在本实施例中,所述基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线,包括:
b1、按照多个预设角度对所述识别结果中的所述多个文本框进行旋转,对旋转后的所述多个文本框在y轴上进行投影,确定在y轴上所述多个预设角度对应的多个投影区间及多个重叠投影片段;
b2、选择所述多个投影区间中投影区间最小,或者,选择所述多个重叠投影片段中重叠投影片段最多的预设角度作为目标角度,确定所述目标角度对应的重叠投影片段;
b3、根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行切割线;及
b4、根据所述目标角度下所述多个文本框的行切割线,确定每一行对应的文本框。
一般来说,在整齐的表格图片上,行与行之间有一定间距,在算法表现上,通用OCR识别的文本框在y轴的投影也有比较整齐的规律,同一行的文本框在y轴上的投影比较接近。
上述预设角度的范围可以设置为-1°~1°,步长为0.1°。
通过以待恢复表格图片的中心依次旋转图片,并对旋转后的图片的所有文本框在y轴投影,得到每个文本框在y轴上的投影坐标,基于每个文本框的投影坐标确定当前旋转角度对应的投影区间,并记录重叠投影片段的数量及坐标。选取这些角度中重叠投影片段最多的一个角度,并根据重叠投影片段画出行切割线。
具体地,所述根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行切割线,包括:
获取所述目标角度对应的重叠投影片段中每一个重叠投影片段的坐标,以每一个重叠投影片段的最小坐标作为一行的下切割线,以每一个重叠的投影片段的最大坐标作为一行的上切割线。
将最终确定的经过旋转后的待恢复表格图片及行切割线可确定旋转后的待恢复表格图片的行信息及每一行对应的文本框。
确定待恢复表格图片的行信息后,需进一步确定待恢复表格图片的列信息。需要说明的是,一般情况下表格的列信息与表格的表头信息紧密相关,因此,需先确定待恢复表格图片中的表头信息。在本实施例中,所述根据所述图片类型确定所述待恢复表格图片对应的表头信息,包括:
c1、从预设存储路径获取预先确定的图片类型与表头关键词集合的映射数据,根据所述图片类型及所述映射数据确定所述待恢复表格图片对应的表头关键词集合;
c2、根据所述行切割线确定所述待恢复表格图片中每一行的文本框的文本信息,将所述每一行的文本框的文本信息与所述关键词集合进行匹配;及
c3、当存在与所述关键词集合匹配的文本信息时,将与所述关键词集合匹配的文本信息对应的一行文本框作为所述待恢复表格图片的表头信息。
上述映射数据中每一种图片类型对应一个关键词集合。需要说明的是,需要预先确定多种图片类型分别对应的表头信息,确定多种图片类型对应的关键词集合,生成图片类型与关键词集合的映射数据,将映射数据保存至预设存储路径中。
由于没有表格线作辅助,无法精准的进行列分割。在本实施例中,利用表头的位置信息计算列分割线。在实际业务场景中,同一类的表格具有类似的表头内容,且表头内容一般不会出现在表格顶部的冗余信息中,也不会出现在明细条目里。所以通过检索关键字定位表头是有效的方法。以费用清单为例,对待恢复表格图片进行行切割确定所述待恢复表格图片的每一行的文本框后,将每一行文本框从上至下排列,并依次将文本框的文本信息 与确定的关键词集合进行比对,但凡出现关键字“单价”、“数量”、“金额”则检索停止,找到该元素所在的行,这一行就是表头。
确定表头信息后,进一步根据表头信息确定列切割线。在本实施例中,所述基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线,包括:
d1、获取所述表头信息中的每一个表头元素,在所述每一个表头元素对应的文本框的最右方作垂直切割线;及
d2、将所述垂直切割线作为所述待恢复表格图片的列切割线。
例如,表头信息中包含6个表头元素时,分别确定6个表头元素对应的文本框,读取每一个文本框的位置信息,即坐标,确定文本框的最右点,将6个表头元素对应的6个最右点作为列切割点,并作垂直切割线进行列切割。
为了确保列分割的准确性,在其他实施例中,所述基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线,还包括:
e1、将所述垂直切割线作为第一列切割线;
e2、计算所述第一切割结果中每个文本框的中心点,记录中心点在所述第一列切割线内的文本框,计算每一列文本框外框边界点在X轴方向上的平均数及标准差;
e3、当所述标准差小于或等于预设标准差阈值时,根据所述平均数调整对应的一列文本框的第一列切割线,生成第二列切割线;及
e4、将所述第二列切割线作为所述待恢复表格图片的列切割线。
可以理解的是,在每一个表头元素的外边框的最右方作垂直分割线初步定位列切割点,这样的列切割点可能不准确,例如,某一个表头元素的列切割线可能会穿过其对应的明细内容。虽然存在偏差,但是表格明细的横向排列也是相对整齐的,有一定的边界,通常在表格中是靠左或靠右对齐。这个特点可以利用到列切割的矫正中。先把中心点在两条相邻列分割线内的文本框记录起来,计算每一列的文本框外边框边界点(例如,最右点的x轴坐标)的平均数和其标准差。标准差代表这一列是否有靠左、靠右对齐的特征,如果标准差低于预设标准差阈值(例如,图片中字符的平均宽度),则可以认为表格有对齐特征,可把对应的列切割点移动到该列的文本框外边框边界点(例如,最右点的x轴坐标)的平均数上,否则初步定位的列切割点保持不变。相较于将比直接画外边界线,通过上述步骤调整得到的列切割线准确性得到提高。
步骤S4,基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格。
新建一个与目标表格结构相同的空表,将目标表格结构范围内的文本框的文本信息依次填充至表格单元格中,以提取出待恢复表格图片中的表格明细内容。
在本实施例中,所述基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,包括:
f1、确定所述目标表格结构中每个单元格对应的多个交集文本框,分别计算所述多个交集文本框面积及所述多个交集文本框与所述单元格的重叠面积;及
f2、当所述重叠面积与所述交集文本框面积的比例超过预设比例阈值时,判断所述交集文本框为所述单元格对应的目标文本框,将所述目标文本框的文本信息写入所述单元格中。
在填充单元格的过程中,需首先确定每个单元格分别对应的文本框。需要说明的是,同一个文本框可能处于目标表格结构中两相邻单元格之间,为了进一步保证表格明细提取的准确性,在每个单元格中计算该由列切割线和行切割线构成的四边形面积,和与其有交集的文本框的重叠面积,如果重叠面积占文本框面积的0.5以上,则认为该文本框属于对应单元格。在其他实施例中,如果有多个文本框符合以上条件,则按照位置靠上、靠左的 优先级放置。
进一步地,为了避免文本信息遗漏或被重复填充,确定每个单元格对应的文本框后,将文本框对应的文本信息按照预设顺序填充至单元格中。在本实施例中,上述预设顺序为:按照行/列从上至下,从左到右的顺序。
步骤S5,基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格。
上述预设终端为指定审核人员使用的终端,例如,众包人员。
上述异常单元格对应的异常区域包括:异常单元格及靠近异常单元格的左右两单元格构成的区域。
为了提高表格明细提取的准确性,需对第一表格中的单元格进行异常识别,当识别出异常单元格时,将异常单元格对应的异常区域反馈至众包人员使用的终端,以供众包人员进行修改确认及反馈,以对异常单元格进行处理。
在本实施例中,所述基于预设识别规则从所述第一表格中识别异常单元格,包括:
g1、分别从所述第一表格中获取每一列单元格,确定每一列的第一单元格及第二单元格;及
g2、分别计算每一列单元格中所述第一单元格占比,将所述占比大于预设比例阈值的列中的所述第二单元格作为异常单元格。
其中,第一单元格为由内容的单元格,第二单元格为内容为空的单元格。例如,按照从左到右的顺序依次确定每一列单元格中第一单元格及第二单元格。统计第一单元格的数量及该列单元格总数,计算第一单元格该列与单元格总数的占比,如果一列中有内容的行的占比超过70%,则判断剩下的空行存在异常。
基于上述步骤,对疑似结构化错误的单元格进行处理,保证了每个单元格内容没有缺失或合并的情况。
为了进一步提高表格明细提取的准确性,在其他实施例中,所述基于预设识别规则从所述第一表格中识别异常单元格,还包括:
h1、获取所述第一表格中各单元格对应的文本框,对所述各单元格对应的文本框进行第二OCR识别,所述各单元格对应的文本框的二次识别结果;
h2、将所述各单元格对应的文本框的二次识别结果与所述第一表格中各单元格对应的文本信息进行比对;及
h3、将比对结果为不一致的单元格作为所述异常单元格。
需要说明的是,第一OCR识别与第二OCR识别中识别模型不同,例如,第一OCR识别模型为CNN+RNN+CTC;第二OCR识别模型为:CNN+Seq2Seq+Attention,且训练数据必须是相互独立的,使得不同的识别模型的识别结果也是相互独立的。例如,第一OCR识别模型的训练数据仅包括字母、符号及数字;第二OCR识别模型的训练数据包括汉字、字母、数字等,使得不同的识别模型能准确识别的对象有所区别。
可以理解的是,在概率上,如果有两套文本识别模型,模型A的准确率为x,模型B的准确率为y,如果一张图片在模型A中识别结果与在模型B中的识别结果相同,则该结果为错误结果的概率为(1-x)*(1-y),举例来说,如x为98%,y为97.5%,则识别结果相同时的错误概率为0.05%,近似为0。由此可得用两个相互独立的模型得出的识别结果相同时,这个结果为正确的概率为99.95%。以这点为基础,可以把这部分结果认为是正确的结果,把两个模型结果不相同的部分认为疑似错误结果。
通过利用两个独立的识别模型互相校验的方法识别出异常单元格进行处理,保证了每一个单元格的识别结果准确性,从而提高了表格明细提取的准确性。
步骤S6,将所述目标表格反馈至所述用户。
将经过表格版式恢复得到的目标表格通过客户端反馈至用户。
上述实施例提出的基于OCR的表格版式恢复方法,在对待恢复表格图片进行OCR识别并确定行/列切割线后,生成目标表格结构,并利用OCR识别结果依次填充目标表格结构的单元格,得到第一表格,通过识别并处理第一表格中的异常单元格生成目标表格反馈至用户。通过识别出第一表格中的异常单元格(a.存在合并或重叠的单元格;及文本信息可能不准确的单元格),并将异常单元格反馈到预设终端以供修改确认,提高了每个单元格内容的准确性,从而提高了表格版式恢复的准确性。
需要说明的是,同一份表格文件具有相似的行列结构。然而,由于打印机限制,过长的部分会被分页,而被分页的部分可能没有表头信息,由于在拍照、扫描过程中,每张图片间的角度和三维旋转的误差,故切割线可能无法直接确定,为了进一步提高列切割线的准确性,在其他实施例中,当所述待恢复表格图片包括具有相同行列结构的有表头页和无表头页时,所述步骤S3还包括:
k1、识别出所述有表头页的列切割线并计算所述有表头页的列切割比例;
k2、基于所述预设行切割规则对所述无表头页进行行切割得到所述无表头页的行切割线,根据所述行切割线确定所述无表头页中文本框最多的行;及
k3、根据所述有表头页的列切割比例对所述无表头页中文本框最多的行进行列切割线映射,得到所述无表头页的列切割线对所述无表头页的第一切割结果进行列切割,得到所述无表头页的第二切割结果。
需要说明的是,有表头页的列切割规则及预设行切割规则的具体实施方式与上述实施例中相同,在此不作赘述。
在计算有表头页的列切割比例时,以有表头页中最开始有内容的列的外边界线切割线为起点,以最后有内容的列的外边界线为终点,计算每一列的比例,即,确定每一条列切割线的相对位置。
在确定上述无表头页中文本框最多的行的过程中,文本框数量越接近有表头页的表头的列数,确定的列切割线越准确。
确定行与列切割比例后,以文本框最多的行的第一个文本框的水平方向最小边界点为起点,以最后一个文本框的水平方向最大边界点为终点,确定一个范围,按照列切割比例在该范围内进行列切割映射。其中,最小边界点可以理解为第一个文本框的坐标值中x最小值对应的点,最大边界点可以理解为最后一个文本框的坐标值中x最大值对应的点。
本申请还提出一种电子设备。参照图2所示,为本申请电子设备较佳实施例的示意图。
在本实施例中,电子设备1可以是服务器、智能手机、平板电脑、便携计算机、桌上型计算机等具有数据处理功能的终端设备,所述服务器可以是机架式服务器、刀片式服务器、塔式服务器或机柜式服务器。
该电子设备1包括存储器11、处理器12及网络接口13。
其中,存储器11至少包括一种类型的可读存储介质,所述可读存储介质包括闪存、硬盘、多媒体卡、卡型存储器(例如,SD或DX存储器等)、磁性存储器、磁盘、光盘等。存储器11在一些实施例中可以是所述电子设备1的内部存储单元,例如该电子设备1的硬盘。存储器11在另一些实施例中也可以是所述电子设备1的外部存储设备,例如该电子设备1上配备的插接式硬盘,智能存储卡(Smart Media Card,SMC),安全数字(Secure Digital,SD)卡,闪存卡(Flash Card)等。进一步地,存储器11还可以既包括该电子设备1的内部存储单元也包括外部存储设备。
存储器11不仅可以用于存储安装于该电子设备1的应用软件及各类数据,例如,基于OCR的表格版式恢复程序10等,还可以用于暂时地存储已经输出或者将要输出的数据。
处理器12在一些实施例中可以是一中央处理器(Central Processing Unit,CPU)、控制器、微控制器、微处理器或其他数据处理芯片,用于运行存储器11中存储的程序代码或 处理数据,例如,基于OCR的表格版式恢复程序10等。
网络接口13可选的可以包括标准的有线接口、无线接口(如WI-FI接口),通常用于在该电子设备1与其他电子设备之间建立通信连接,例如,客户端(图中未标识)。电子设备1的组件11-13通过通信总线相互通信。
图2仅示出了具有组件11-13的电子设备1,本领域技术人员可以理解的是,图2示出的结构并不构成对电子设备1的限定,可以包括比图示更少或者更多的部件,或者组合某些部件,或者不同的部件布置。
可选地,该电子设备1还可以包括用户接口,用户接口可以包括显示器(Display)、输入单元比如键盘(Keyboard),可选的用户接口还可以包括标准的有线接口、无线接口。
可选地,在一些实施例中,显示器可以是LED显示器、液晶显示器、触控式液晶显示器以及有机发光二极管(Organic Light-Emitting Diode,OLED)触摸器等。其中,显示器也可以称为显示屏或显示单元,用于显示在电子设备1中处理的信息以及用于显示可视化的用户界面。
在图2所示的电子设备1实施例中,作为一种计算机存储介质的存储器11中存储基于OCR的表格版式恢复程序10的程序代码,处理器12执行基于OCR的表格版式恢复程序10的程序代码时,实现如下步骤:
接收步骤,接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型。
在本实施例中,所述待恢复表格图片为无表格线的表格。需要说明的是,为了保证表格版式恢复的准确性,待恢复表格图片需满足几个特点:行、列排列整齐;行列间有一定间距(间距越大,准确性越高);表格具有表头且每一列信息与表头对应;同一类型的表格的表头信息固定。
所述待恢复表格图片的图片类型用于区分不同应用场景对应的表格图片,本实施例默认同一类型的不同表格对应相同的表头信息。例如,费用清单这类表格图片,表头信息包括:“单价”、“数量”、“金额”、“项目名称”等,财务报表这类表格图片,表头信息包括:“项目”、“本年数”、“金额”、“年初余额”等。
用户通过客户端上的APP选择待恢复表格图片及其对应的图片类型,并发出表格版式恢复指令。电子设备1接收到客户端发出的指令后,对指令中携带的待恢复表格图片进行提取表格明细内容的操作。
识别步骤,对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息。
上述对待恢复表格图片进行第一OCR识别得到的识别结果包括:多个文本框、所述多个文本框的坐标信息及所述文本框对应的文本信息。鉴于现有技术中已经有成熟的OCR识别技术,故在此不作赘述。
切割步骤,基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构。
在提取表格明细之前,需先分析待恢复表格图片的行切割线及列切割线,以确定图片中的表格结构。在本实施例中,所述根据所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,包括:
a1、基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线;
a2、根据所述图片类型确定所述待恢复表格图片对应的表头信息,基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线;及
a3、根据所述待恢复表格图片的行切割线及列切割线确定所述目标表格结构。
在本实施例中,所述基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线,包括:
b1、按照多个预设角度对所述识别结果中的所述多个文本框进行旋转,对旋转后的所述多个文本框在y轴上进行投影,确定在y轴上所述多个预设角度对应的多个投影区间及多个重叠投影片段;
b2、选择所述多个投影区间中投影区间最小,或者,选择所述多个重叠投影片段中重叠投影片段最多的预设角度作为目标角度,确定所述目标角度对应的重叠投影片段;
b3、根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行切割线;及
b4、根据所述目标角度下所述多个文本框的行切割线,确定每一行对应的文本框。
一般来说,在整齐的表格图片上,行与行之间有一定间距,在算法表现上,通用OCR识别的文本框在y轴的投影也有比较整齐的规律,同一行的文本框在y轴上的投影比较接近。
上述预设角度的范围可以设置为-1°~1°,步长为0.1°。
通过以待恢复表格图片的中心依次旋转图片,并对旋转后的图片的所有文本框在y轴投影,得到每个文本框在y轴上的投影坐标,基于每个文本框的投影坐标确定当前旋转角度对应的投影区间,并记录重叠投影片段的数量及坐标。选取这些角度中重叠投影片段最多的一个角度,并根据重叠投影片段画出行切割线。
具体地,所述根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行切割线,包括:
获取所述目标角度对应的重叠投影片段中每一个重叠投影片段的坐标,以每一个重叠投影片段的最小坐标作为一行的下切割线,以每一个重叠的投影片段的最大坐标作为一行的上切割线。
将最终确定的经过旋转后的待恢复表格图片及行切割线可确定旋转后的待恢复表格图片的行信息及每一行对应的文本框。
确定待恢复表格图片的行信息后,需进一步确定待恢复表格图片的列信息。需要说明的是,一般情况下表格的列信息与表格的表头信息紧密相关,因此,需先确定待恢复表格图片中的表头信息。在本实施例中,所述根据所述图片类型确定所述待恢复表格图片对应的表头信息,包括:
c1、从预设存储路径获取预先确定的图片类型与表头关键词集合的映射数据,根据所述图片类型及所述映射数据确定所述待恢复表格图片对应的表头关键词集合;
c2、根据所述行切割线确定所述待恢复表格图片中每一行的文本框的文本信息,将所述每一行的文本框的文本信息与所述关键词集合进行匹配;及
c3、当存在与所述关键词集合匹配的文本信息时,将与所述关键词集合匹配的文本信息对应的一行文本框作为所述待恢复表格图片的表头信息。
上述映射数据中每一种图片类型对应一个关键词集合。需要说明的是,需要预先确定多种图片类型分别对应的表头信息,确定多种图片类型对应的关键词集合,生成图片类型与关键词集合的映射数据,将映射数据保存至预设存储路径中。
由于没有表格线作辅助,无法精准的进行列分割。在本实施例中,利用表头的位置信息计算列分割线。在实际业务场景中,同一类的表格具有类似的表头内容,且表头内容一般不会出现在表格顶部的冗余信息中,也不会出现在明细条目里。所以通过检索关键字定位表头是有效的方法。以费用清单为例,对待恢复表格图片进行行切割确定所述待恢复表格图片的每一行的文本框后,将每一行文本框从上至下排列,并依次将文本框的文本信息与确定的关键词集合进行比对,但凡出现关键字“单价”、“数量”、“金额”则检索停止,找到该元素所在的行,这一行就是表头。
确定表头信息后,进一步根据表头信息确定列切割线。在本实施例中,所述基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线,包括:
d1、获取所述表头信息中的每一个表头元素,在所述每一个表头元素对应的文本框的最右方作垂直切割线;及
d2、将所述垂直切割线作为所述待恢复表格图片的列切割线。
例如,表头信息中包含6个表头元素时,分别确定6个表头元素对应的文本框,读取每一个文本框的位置信息,即坐标,确定文本框的最右点,将6个表头元素对应的6个最右点作为列切割点,并作垂直切割线进行列切割。
为了确保列分割的准确性,在其他实施例中,所述基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线,还包括:
e1、将所述垂直切割线作为第一列切割线;
e2、计算所述第一切割结果中每个文本框的中心点,记录中心点在所述第一列切割线内的文本框,计算每一列文本框外框边界点在X轴方向上的平均数及标准差;
e3、当所述标准差小于或等于预设标准差阈值时,根据所述平均数调整对应的一列文本框的第一列切割线,生成第二列切割线;及
e4、将所述第二列切割线作为所述待恢复表格图片的列切割线。
可以理解的是,在每一个表头元素的外边框的最右方作垂直分割线初步定位列切割点,这样的列切割点可能不准确,例如,某一个表头元素的列切割线可能会穿过其对应的明细内容。虽然存在偏差,但是表格明细的横向排列也是相对整齐的,有一定的边界,通常在表格中是靠左或靠右对齐。这个特点可以利用到列切割的矫正中。先把中心点在两条相邻列分割线内的文本框记录起来,计算每一列的文本框外边框边界点(例如,最右点的x轴坐标)的平均数和其标准差。标准差代表这一列是否有靠左、靠右对齐的特征,如果标准差低于预设标准差阈值(例如,图片中字符的平均宽度),则可以认为表格有对齐特征,可把对应的列切割点移动到该列的文本框外边框边界点(例如,最右点的x轴坐标)的平均数上,否则初步定位的列切割点保持不变。相较于将比直接画外边界线,通过上述步骤调整得到的列切割线准确性得到提高。
第一恢复步骤,基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格。
新建一个与目标表格结构相同的空表,将目标表格结构范围内的文本框的文本信息依次填充至表格单元格中,以提取出待恢复表格图片中的表格明细内容。
在本实施例中,所述基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,包括:
f1、确定所述目标表格结构中每个单元格对应的多个交集文本框,分别计算所述多个交集文本框面积及所述多个交集文本框与所述单元格的重叠面积;及
f2、当所述重叠面积与所述交集文本框面积的比例超过预设比例阈值时,判断所述交集文本框为所述单元格对应的目标文本框,将所述目标文本框的文本信息写入所述单元格中。
在填充单元格的过程中,需首先确定每个单元格分别对应的文本框。需要说明的是,同一个文本框可能处于目标表格结构中两相邻单元格之间,为了进一步保证表格明细提取的准确性,在每个单元格中计算该由列切割线和行切割线构成的四边形面积,和与其有交集的文本框的重叠面积,如果重叠面积占文本框面积的0.5以上,则认为该文本框属于对应单元格。在其他实施例中,如果有多个文本框符合以上条件,则按照位置靠上、靠左的优先级放置。
进一步地,为了避免文本信息遗漏或被重复填充,确定每个单元格对应的文本框后, 将文本框对应的文本信息按照预设顺序填充至单元格中。在本实施例中,上述预设顺序为:按照行/列从上至下,从左到右的顺序。
第二恢复步骤,基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格。
上述预设终端为指定审核人员使用的终端,例如,众包人员。
上述异常单元格对应的异常区域包括:异常单元格及靠近异常单元格的左右两单元格构成的区域。
为了提高表格明细提取的准确性,需对第一表格中的单元格进行异常识别,当识别出异常单元格时,将异常单元格对应的异常区域反馈至众包人员使用的终端,以供众包人员进行修改确认及反馈,以对异常单元格进行处理。
在本实施例中,所述基于预设识别规则从所述第一表格中识别异常单元格,包括:
g1、分别从所述第一表格中获取每一列单元格,确定每一列的第一单元格及第二单元格;及
g2、分别计算每一列单元格中所述第一单元格占比,将所述占比大于预设比例阈值的列中的所述第二单元格作为异常单元格。
其中,第一单元格为由内容的单元格,第二单元格为内容为空的单元格。例如,按照从左到右的顺序依次确定每一列单元格中第一单元格及第二单元格。统计第一单元格的数量及该列单元格总数,计算第一单元格该列与单元格总数的占比,如果一列中有内容的行的占比超过70%,则判断剩下的空行存在异常。
基于上述步骤,对疑似结构化错误的单元格进行处理,保证了每个单元格内容没有缺失或合并的情况。
为了进一步提高表格明细提取的准确性,在其他实施例中,所述基于预设识别规则从所述第一表格中识别异常单元格,还包括:
h1、获取所述第一表格中各单元格对应的文本框,对所述各单元格对应的文本框进行第二OCR识别,所述各单元格对应的文本框的二次识别结果;
h2、将所述各单元格对应的文本框的二次识别结果与所述第一表格中各单元格对应的文本信息进行比对;及
h3、将比对结果为不一致的单元格作为所述异常单元格。
需要说明的是,第一OCR识别与第二OCR识别中识别模型不同,例如,第一OCR识别模型为CNN+RNN+CTC;第二OCR识别模型为:CNN+Seq2Seq+Attention,且训练数据必须是相互独立的,使得不同的识别模型的识别结果也是相互独立的。例如,第一OCR识别模型的训练数据仅包括字母、符号及数字;第二OCR识别模型的训练数据包括汉字、字母、数字等,使得不同的识别模型能准确识别的对象有所区别。
可以理解的是,在概率上,如果有两套文本识别模型,模型A的准确率为x,模型B的准确率为y,如果一张图片在模型A中识别结果与在模型B中的识别结果相同,则该结果为错误结果的概率为(1-x)*(1-y),举例来说,如x为98%,y为97.5%,则识别结果相同时的错误概率为0.05%,近似为0。由此可得用两个相互独立的模型得出的识别结果相同时,这个结果为正确的概率为99.95%。以这点为基础,可以把这部分结果认为是正确的结果,把两个模型结果不相同的部分认为疑似错误结果。
通过利用两个独立的识别模型互相校验的方法识别出异常单元格进行处理,保证了每一个单元格的识别结果准确性,从而提高了表格明细提取的准确性。
反馈步骤,将所述目标表格反馈至所述用户。
将经过表格版式恢复得到的目标表格通过客户端反馈至用户。
Figure PCTCN2020098981-appb-000001
参照图3所示,为本申请基于OCR的表格版式恢复装置100的模块示意图。
在所述基于OCR的表格版式恢复装置100一实施例中,基于OCR的表格版式恢复装置100包括:模块110-160,其中:
接收模块110,用于接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
识别模块120,用于对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
切割模块130,用于基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
第一恢复模块140,用于基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
第二恢复模块150,用于基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
反馈模块160,用于将所述目标表格反馈至所述用户。
所述模块110-160所实现的功能或操作步骤均与上文类似,此处不再详述。
此外,本申请实施例还提出一种计算机可读存储介质,所述计算机可读存储介质可以是非易失性,也可以是易失性,所述计算机可读存储介质中包括基于OCR的表格版式恢复程序10,所述基于OCR的表格版式恢复程序10被处理器执行时实现所述基于OCR的表格版式恢复方法的任意步骤。本申请计算机可读存储介质的具体实施方式与上述方法实施例大致相同,在此不再赘述。
上述本申请实施例序号仅仅为了描述,不代表实施例的优劣。
需要说明的是,在本文中,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、装置、物品或者方法不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、装置、物品或者方法所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括该要素的过程、装置、物品或者方法中还存在另外的相同要素。
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到上述实施例方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在如上所述的一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例所述的方法。
以上仅为本申请的优选实施例,并非因此限制本申请的专利范围,凡是利用本申请说明书及附图内容所作的等效结构或等效流程变换,或直接或间接运用在其它相关的技术领域,均同理包括在本申请的专利保护范围内。

Claims (20)

  1. 一种基于OCR的表格版式恢复方法,适用于电子设备,其中,该方法包括:
    接收步骤:接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
    识别步骤:对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
    切割步骤:基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
    第一恢复步骤:基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
    第二恢复步骤:基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
    反馈步骤:将所述目标表格反馈至所述用户。
  2. 根据权利要求1所述的基于OCR的表格版式恢复方法,其中,所述基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构,包括:
    基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线;
    根据所述图片类型确定所述待恢复表格图片对应的表头信息,基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线;及
    根据所述待恢复表格图片的行切割线及列切割线确定所述目标表格结构。
  3. 根据权利要求2所述的基于OCR的表格版式恢复方法,其中,所述基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线,包括:
    按照多个预设角度对所述第一识别结果中的所述多个文本框进行旋转,对旋转后的所述多个文本框在y轴上进行投影,确定在y轴上所述多个预设角度对应的多个投影区间及多个重叠投影片段;
    选择所述多个投影区间中投影区间最小,或者,选择所述多个重叠投影片段中重叠投影片段最多的预设角度作为目标角度,确定所述目标角度对应的重叠投影片段;
    根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行切割线;及
    根据所述目标角度下所述多个文本框的行切割线,确定每一行对应的文本框。
  4. 根据权利要求2所述的基于OCR的表格版式恢复方法,其中,所述根据所述图片类型确定所述待恢复表格图片对应的表头信息,包括:
    从预设存储路径获取预先确定的图片类型与表头关键词集合的映射数据,根据所述图片类型及所述映射数据确定所述待恢复表格图片对应的表头关键词集合;
    根据所述行切割线确定所述待恢复表格图片中每一行的文本框的文本信息,将所述每一行的文本框的文本信息与所述关键词集合进行匹配;及
    当存在与所述关键词集合匹配的文本信息时,将与所述关键词集合匹配的文本信息对应的一行文本框作为所述待恢复表格图片的表头信息。
  5. 根据权利要求2所述的基于OCR的表格版式恢复方法,其中,所述基于所述表头 信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线,包括:
    获取所述表头信息中的每一个表头元素,在所述每一个表头元素对应的文本框的最右方作垂直切割线;及
    将所述垂直切割线作为所述待恢复表格图片的列切割线。
  6. 根据权利要求5所述的基于OCR的表格版式恢复方法,其中,所述基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,包括:
    确定所述目标表格结构中每个单元格对应的多个交集文本框,分别计算所述多个交集文本框面积及所述多个交集文本框与所述单元格的重叠面积;及
    当所述重叠面积与所述交集文本框面积的比例超过预设比例阈值时,判断所述交集文本框为所述单元格对应的目标文本框,将所述目标文本框的文本信息写入所述单元格中。
  7. 根据权利要求1至6中任意一项所述的基于OCR的表格版式恢复方法,其中,所述基于预设识别规则从所述第一表格中识别异常单元格,包括:
    分别从所述第一表格中获取每一列单元格,确定每一列的第一单元格及第二单元格;及
    分别计算每一列单元格中所述第一单元格占比,将所述占比大于预设比例阈值的列中的所述第二单元格作为异常单元格。
  8. 根据权利要求1所述的基于OCR的表格版式恢复方法,其中,所述基于预设识别规则从所述第一表格中识别异常单元格,还包括:
    获取所述第一表格中各单元格对应的文本框,对所述各单元格对应的文本框进行第二OCR识别,所述各单元格对应的文本框的二次识别结果;
    将所述各单元格对应的文本框的二次识别结果与所述第一表格中各单元格对应的文本信息进行比对;及
    将比对结果为不一致的单元格作为所述异常单元格。
  9. 一种基于OCR的表格版式恢复装置,其中,包括:
    接收模块,用于接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
    识别模块,用于对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
    切割模块,用于基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
    第一恢复模块,用于基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
    第二恢复模块,用于基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
    反馈模块,用于将所述目标表格反馈至所述用户。
  10. 一种电子设备,其中,该电子设备包括存储器及处理器,所述存储器中存储有可在所述处理器上运行的基于OCR的表格版式恢复程序,所述基于OCR的表格版式恢复程序被所述处理器执行时实现如下步骤:
    接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
    对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
    基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
    基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
    基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
    将所述目标表格反馈至所述用户。
  11. 根据权利要求10所述的电子设备,其中,所述基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构,包括:
    基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线;
    根据所述图片类型确定所述待恢复表格图片对应的表头信息,基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线;及
    根据所述待恢复表格图片的行切割线及列切割线确定所述目标表格结构。
  12. 根据权利要求11所述的电子设备,其中,所述基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线,包括:
    按照多个预设角度对所述第一识别结果中的所述多个文本框进行旋转,对旋转后的所述多个文本框在y轴上进行投影,确定在y轴上所述多个预设角度对应的多个投影区间及多个重叠投影片段;
    选择所述多个投影区间中投影区间最小,或者,选择所述多个重叠投影片段中重叠投影片段最多的预设角度作为目标角度,确定所述目标角度对应的重叠投影片段;
    根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行切割线;及
    根据所述目标角度下所述多个文本框的行切割线,确定每一行对应的文本框。
  13. 根据权利要求11所述的电子设备,其中,所述根据所述图片类型确定所述待恢复表格图片对应的表头信息,包括:
    从预设存储路径获取预先确定的图片类型与表头关键词集合的映射数据,根据所述图片类型及所述映射数据确定所述待恢复表格图片对应的表头关键词集合;
    根据所述行切割线确定所述待恢复表格图片中每一行的文本框的文本信息,将所述每一行的文本框的文本信息与所述关键词集合进行匹配;及
    当存在与所述关键词集合匹配的文本信息时,将与所述关键词集合匹配的文本信息对应的一行文本框作为所述待恢复表格图片的表头信息。
  14. 根据权利要求11所述的电子设备,其中,所述基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线,包括:
    获取所述表头信息中的每一个表头元素,在所述每一个表头元素对应的文本框的最右方作垂直切割线;及
    将所述垂直切割线作为所述待恢复表格图片的列切割线。
  15. 根据权利要求14所述的电子设备,其中,所述基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,包括:
    确定所述目标表格结构中每个单元格对应的多个交集文本框,分别计算所述多个交集文本框面积及所述多个交集文本框与所述单元格的重叠面积;及
    当所述重叠面积与所述交集文本框面积的比例超过预设比例阈值时,判断所述交集文本框为所述单元格对应的目标文本框,将所述目标文本框的文本信息写入所述单元格中。
  16. 根据权利要求10至15中任意一项所述的电子设备,其中,所述基于预设识别规则从所述第一表格中识别异常单元格,包括:
    分别从所述第一表格中获取每一列单元格,确定每一列的第一单元格及第二单元格;及
    分别计算每一列单元格中所述第一单元格占比,将所述占比大于预设比例阈值的列中的所述第二单元格作为异常单元格。
  17. 根据权利要求10所述的电子设备,其中,所述基于预设识别规则从所述第一表格中识别异常单元格,还包括:
    获取所述第一表格中各单元格对应的文本框,对所述各单元格对应的文本框进行第二OCR识别,所述各单元格对应的文本框的二次识别结果;
    将所述各单元格对应的文本框的二次识别结果与所述第一表格中各单元格对应的文本信息进行比对;及
    将比对结果为不一致的单元格作为所述异常单元格。
  18. 一种计算机可读存储介质,其中,所述计算机可读存储介质中包括基于OCR的表格版式恢复程序,所述基于OCR的表格版式恢复程序被处理器执行时实现如下步骤:
    接收用户发出的表格版式恢复指令,所述表格版式恢复指令包括待恢复表格图片及所述待恢复表格图片的图片类型;
    识别步骤:对所述待恢复表格图片进行第一OCR识别得到第一识别结果,所述第一识别结果包括所述待恢复图片的多个文本框及所述多个文本框对应的文本信息;
    基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构;
    基于预设填充规则将所述多个文本框分别写入所述目标表格结构中的单元格,生成第一表格;
    基于预设识别规则从所述第一表格中识别异常单元格,截取所述异常单元格对应的异常区域,将所述异常区域发送至预设终端,并接收所述预设终端返回的所述异常区域对应的异常单元格信息,基于所述异常单元格信息更新所述第一表格,得到目标表格;及
    将所述目标表格反馈至所述用户。
  19. 根据权利要求18所述的计算机可读存储介质,其中,所述基于所述第一识别结果及预设切割规则确定所述待恢复表格图片的切割线,并基于所述切割线确定目标表格结构,包括:
    基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线;
    根据所述图片类型确定所述待恢复表格图片对应的表头信息,基于所述表头信息及预设列切割规则对所述待恢复表格图片进行列切割,确定所述待恢复表格图片的列切割线;及
    根据所述待恢复表格图片的行切割线及列切割线确定所述目标表格结构。
  20. 根据权利要求19所述的计算机可读存储介质,其中,所述基于所述第一识别结果及预设行切割规则对所述待恢复表格图片进行行切割,确定所述待恢复表格图片的行切割线,包括:
    按照多个预设角度对所述第一识别结果中的所述多个文本框进行旋转,对旋转后的所述多个文本框在y轴上进行投影,确定在y轴上所述多个预设角度对应的多个投影区间及多个重叠投影片段;
    选择所述多个投影区间中投影区间最小,或者,选择所述多个重叠投影片段中重叠投影片段最多的预设角度作为目标角度,确定所述目标角度对应的重叠投影片段;
    根据所述目标角度对应的重叠投影片段确定在所述目标角度下所述多个文本框的行 切割线;及
    根据所述目标角度下所述多个文本框的行切割线,确定每一行对应的文本框。
PCT/CN2020/098981 2020-01-22 2020-06-29 基于ocr的表格版式恢复方法、装置、电子设备及存储介质 WO2021147252A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010076368.1 2020-01-22
CN202010076368.1A CN111325110B (zh) 2020-01-22 2020-01-22 基于ocr的表格版式恢复方法、装置及存储介质

Publications (1)

Publication Number Publication Date
WO2021147252A1 true WO2021147252A1 (zh) 2021-07-29

Family

ID=71173205

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/098981 WO2021147252A1 (zh) 2020-01-22 2020-06-29 基于ocr的表格版式恢复方法、装置、电子设备及存储介质

Country Status (2)

Country Link
CN (1) CN111325110B (zh)
WO (1) WO2021147252A1 (zh)

Cited By (9)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113591746A (zh) * 2021-08-05 2021-11-02 上海金仕达软件科技有限公司 一种文档表格结构检测方法及装置
CN113849552A (zh) * 2021-09-27 2021-12-28 中国平安财产保险股份有限公司 结构化数据转换方法、装置、电子设备及介质
CN113987112A (zh) * 2021-12-24 2022-01-28 杭州恒生聚源信息技术有限公司 表格信息抽取方法、装置、存储介质及电子设备
CN114926852A (zh) * 2022-03-17 2022-08-19 支付宝(杭州)信息技术有限公司 表格识别重构方法、装置、设备、介质及程序产品
CN115841679A (zh) * 2023-02-23 2023-03-24 江西中至科技有限公司 图纸表格提取方法、系统、计算机及可读存储介质
CN116469120A (zh) * 2023-05-31 2023-07-21 国网浙江省电力有限公司营销服务中心 电费单据自动数据处理方法、装置及存储介质
CN117115839A (zh) * 2023-08-10 2023-11-24 广州方舟信息科技有限公司 一种基于自循环神经网络的发票字段识别方法和装置
CN117173725A (zh) * 2023-11-03 2023-12-05 之江实验室 表格信息处理方法、装置、计算机设备和存储介质
CN117649675A (zh) * 2024-01-29 2024-03-05 广州亚信技术有限公司 一种表格生成方法、装置、设备及存储介质

Families Citing this family (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111325110B (zh) * 2020-01-22 2024-04-05 平安科技(深圳)有限公司 基于ocr的表格版式恢复方法、装置及存储介质
CN112232198A (zh) * 2020-10-15 2021-01-15 北京来也网络科技有限公司 基于rpa及ai的表格内容提取方法、装置、设备及介质
CN112906532B (zh) * 2021-02-07 2024-01-05 杭州睿胜软件有限公司 图像处理方法和装置、电子设备和存储介质
CN112926421B (zh) * 2021-02-07 2024-01-09 杭州睿胜软件有限公司 图像处理方法和装置、电子设备和存储介质
CN113204555B (zh) * 2021-05-21 2023-10-31 北京字跳网络技术有限公司 数据表处理方法、装置、电子设备和存储介质
CN113255566B (zh) * 2021-06-11 2022-12-06 支付宝(杭州)信息技术有限公司 表格图像识别方法及装置
CN114463766B (zh) * 2021-07-16 2023-05-12 荣耀终端有限公司 一种表格的处理方法及电子设备
CN114022888B (zh) * 2022-01-06 2022-04-08 上海朝阳永续信息技术股份有限公司 用于识别pdf表格的方法、设备和介质
CN115249362B (zh) * 2022-09-20 2022-12-27 京华信息科技股份有限公司 基于像素在稳定方向上连通性的ocr表格识别方法及系统
CN117475459B (zh) * 2023-12-28 2024-04-09 杭州恒生聚源信息技术有限公司 表格信息处理方法、装置、电子设备及存储介质

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030123727A1 (en) * 1998-09-11 2003-07-03 Tomotoshi Kanatsu Table recognition method and apparatus, and storage medium
US20100246958A1 (en) * 2009-03-30 2010-09-30 Digital Business Processes, Inc. Table grid detection and separation
CN101976232A (zh) * 2010-09-19 2011-02-16 深圳市万兴软件有限公司 一种识别文档中数据表格的方法及装置
CN110147774A (zh) * 2019-05-23 2019-08-20 阳光保险集团股份有限公司 表格式图片版面分析方法和计算机存储介质
CN110399878A (zh) * 2019-06-14 2019-11-01 南京火眼锐视信息科技有限公司 表格版式恢复方法,计算机可读介质以及计算机
CN111310426A (zh) * 2020-01-22 2020-06-19 平安科技(深圳)有限公司 基于ocr的表格版式恢复方法、装置及存储介质
CN111325110A (zh) * 2020-01-22 2020-06-23 平安科技(深圳)有限公司 基于ocr的表格版式恢复方法、装置及存储介质

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US9430470B2 (en) * 2010-05-26 2016-08-30 Content Catalyst Limited Automated report service tracking system and method
US10560583B2 (en) * 2014-11-01 2020-02-11 Somos, Inc. Toll-free numbers metadata tagging, analysis and reporting
CN110008809B (zh) * 2019-01-04 2020-08-25 阿里巴巴集团控股有限公司 表格数据的获取方法、装置和服务器

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20030123727A1 (en) * 1998-09-11 2003-07-03 Tomotoshi Kanatsu Table recognition method and apparatus, and storage medium
US20100246958A1 (en) * 2009-03-30 2010-09-30 Digital Business Processes, Inc. Table grid detection and separation
CN101976232A (zh) * 2010-09-19 2011-02-16 深圳市万兴软件有限公司 一种识别文档中数据表格的方法及装置
CN110147774A (zh) * 2019-05-23 2019-08-20 阳光保险集团股份有限公司 表格式图片版面分析方法和计算机存储介质
CN110399878A (zh) * 2019-06-14 2019-11-01 南京火眼锐视信息科技有限公司 表格版式恢复方法,计算机可读介质以及计算机
CN111310426A (zh) * 2020-01-22 2020-06-19 平安科技(深圳)有限公司 基于ocr的表格版式恢复方法、装置及存储介质
CN111325110A (zh) * 2020-01-22 2020-06-23 平安科技(深圳)有限公司 基于ocr的表格版式恢复方法、装置及存储介质

Cited By (15)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113591746A (zh) * 2021-08-05 2021-11-02 上海金仕达软件科技有限公司 一种文档表格结构检测方法及装置
CN113849552B (zh) * 2021-09-27 2024-05-31 中国平安财产保险股份有限公司 结构化数据转换方法、装置、电子设备及介质
CN113849552A (zh) * 2021-09-27 2021-12-28 中国平安财产保险股份有限公司 结构化数据转换方法、装置、电子设备及介质
CN113987112A (zh) * 2021-12-24 2022-01-28 杭州恒生聚源信息技术有限公司 表格信息抽取方法、装置、存储介质及电子设备
CN114926852A (zh) * 2022-03-17 2022-08-19 支付宝(杭州)信息技术有限公司 表格识别重构方法、装置、设备、介质及程序产品
CN115841679A (zh) * 2023-02-23 2023-03-24 江西中至科技有限公司 图纸表格提取方法、系统、计算机及可读存储介质
CN115841679B (zh) * 2023-02-23 2023-05-05 江西中至科技有限公司 图纸表格提取方法、系统、计算机及可读存储介质
CN116469120A (zh) * 2023-05-31 2023-07-21 国网浙江省电力有限公司营销服务中心 电费单据自动数据处理方法、装置及存储介质
CN116469120B (zh) * 2023-05-31 2023-09-05 国网浙江省电力有限公司营销服务中心 电费单据自动数据处理方法、装置及存储介质
CN117115839A (zh) * 2023-08-10 2023-11-24 广州方舟信息科技有限公司 一种基于自循环神经网络的发票字段识别方法和装置
CN117115839B (zh) * 2023-08-10 2024-04-16 广州方舟信息科技有限公司 一种基于自循环神经网络的发票字段识别方法和装置
CN117173725A (zh) * 2023-11-03 2023-12-05 之江实验室 表格信息处理方法、装置、计算机设备和存储介质
CN117173725B (zh) * 2023-11-03 2024-04-09 之江实验室 表格信息处理方法、装置、计算机设备和存储介质
CN117649675A (zh) * 2024-01-29 2024-03-05 广州亚信技术有限公司 一种表格生成方法、装置、设备及存储介质
CN117649675B (zh) * 2024-01-29 2024-03-29 广州亚信技术有限公司 一种表格生成方法、装置、设备及存储介质

Also Published As

Publication number Publication date
CN111325110B (zh) 2024-04-05
CN111325110A (zh) 2020-06-23

Similar Documents

Publication Publication Date Title
WO2021147252A1 (zh) 基于ocr的表格版式恢复方法、装置、电子设备及存储介质
WO2021147222A1 (zh) 基于ocr的表格版式恢复方法、装置、电子设备及存储介质
US11138425B2 (en) Named entity recognition with convolutional networks
JP6710483B2 (ja) 損害賠償請求書類の文字認識方法、装置、サーバ及び記憶媒体
WO2019104879A1 (zh) 表格类图像的信息识别方法、电子装置及可读存储介质
US10120537B2 (en) Page-independent multi-field validation in document capture
US11631265B2 (en) Automated learning of document data fields
WO2021184578A1 (zh) 基于ocr的目标字段识别方法、装置、电子设备及存储介质
US20220343062A1 (en) Table detection in spreadsheet
WO2021151270A1 (zh) 图像结构化数据提取方法、装置、设备及存储介质
WO2018233055A1 (zh) 保单信息录入的方法、装置、计算机设备及存储介质
US20090226090A1 (en) Information processing system, information processing apparatus, information processing method, and storage medium
TW201617971A (zh) 資訊識別方法及裝置
CN112434496B (zh) 一种公告文档表格数据识别方法及终端
CN111340020A (zh) 一种公式识别方法、装置、设备及存储介质
WO2021143058A1 (zh) 基于图像的信息比对方法、装置、电子设备及计算机可读存储介质
CN110688995B (zh) 地图查询的处理方法,计算机可读存储介质和移动终端
JP5229102B2 (ja) 帳票検索装置、帳票検索プログラムおよび帳票検索方法
CN111159997B (zh) 一种企业投标文档的智能校验方法
CN110688842B (zh) 一种文档标题层级的分析方法、装置及服务器
CN105095826A (zh) 一种文字识别方法及装置
CN115147858A (zh) 手写体表单图像数据生成方法、装置、设备及介质
JP4521466B2 (ja) 帳票処理装置
WO2021184178A1 (zh) 标注方法和装置
JP2022095391A (ja) 情報処理装置、及び情報処理プログラム

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20916038

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20916038

Country of ref document: EP

Kind code of ref document: A1