Table character recognition method and system based on OCR
Through OCR-based methods, combined with deep learning and morphological processing, the problems of complexity and low accuracy in table recognition are solved, accurate detection and recognition of tables and text are achieved, and the accuracy of cell information extraction is improved.
Patent Information
- Application Number
- CN202410893313.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-04
- Publication Date
- 2024-10-08
- Estimated Expiration
- 2044-07-04
AI Technical Summary
The existing technology has problems of low recognition complexity and low accuracy in table recognition. Especially when dealing with tables that merge different rows and columns and have diverse content text types, it is difficult to accurately detect and extract cell information.
Using an OCR-based method, the PDF file is parsed, converted into image data, layout analysis is performed to determine table elements, and deep learning and morphological processing are combined to detect table outlines and calculate intersections to obtain cell coordinate information and use PaddleOCR performs text recognition and outputs the text content of each line.
It improves the accuracy of table detection and cell text recognition rate, ensures the accurate distinction between tables and text parts, and outputs the completeness and accuracy of recognition results.
Smart Images

Figure CN118747902A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of optical character recognition, and in particular, relates to a table text recognition method and system based on OCR. Background Art
[0002] OCR, Optical Character Recognition, is one of the important directions of computer vision. The traditional definition of OCR is generally aimed at scanned document objects. Nowadays, OCR generally refers to scene text recognition, mainly for natural scenes. OCR technology has a wide range of application scenarios. A typical scenario is the vertical structured text recognition widely used in daily life, such as license plate recognition, bank card information recognition, ID card information recognition, train ticket information recognition, etc. The common feature of these small vertical categories is that the format is fixed, so it is very suitable for OCR technology to be automated, which can greatly reduce labor costs and improve efficiency.
[0003] Table text recognition aims to divide the table area into several cells, extract and recognize the content in each cell, and return the text information consistent with the position of the table. It belongs to the category of document structured recognition. With the gradual maturity of OCR technology and the strong demand for structured information extraction, various technologies related to intelligent document analysis, such as layout analysis, table recognition, and key information extraction, have received more and more attention and research. Among them, layout analysis mainly classifies the content of document images, and the categories generally include: plain text, title, table, and picture. Existing methods generally detect or segment different layouts in documents as different targets. The task of table recognition is to identify the table information in the document and extract information. The types and styles of tables in text images are complex and diverse, for example, different row and column merges, different content text types, etc.; the above challenges make table recognition always a research difficulty in the field of document understanding. Summary of the invention
[0004] In view of the defects in the prior art, the object of the present invention is to provide a table text recognition method and system based on OCR.
[0005] According to the present invention, a table text recognition method based on OCR is provided, comprising:
[0006] Step S1: Parse the PDF file and convert the PDF file into image data;
[0007] Step S2: Perform layout analysis on the image data to obtain layout analysis results;
[0008] Step S3: Based on the layout analysis results, determine whether there is a table element; if the result is yes, save the coordinate information of the table detection area; if the result is no, identify it as plain text; based on the deep learning network, obtain the number and area of the table detection box;
[0009] Step S4: Based on the image data, find the contour in the image through morphological processing; and obtain the number and area of the table detection box according to the contour;
[0010] Step S5: Determine whether the number of detection frames obtained in step S3 is equal to the number of detection frames obtained in step S4. If yes, use the number of detection frames obtained in step S4 as the input item; if no, use the result with more detection frames as the input item;
[0011] Step S6: based on the input item, obtain cell information, and filter the cell information to obtain cell coordinate information;
[0012] Step S7: Based on the cell coordinate information, the coordinate information of each text box and the identified content in the text box are obtained, and the text content of each row is returned to obtain the result data.
[0013] Preferably, in step S2: according to the actual layout of the page of the layout analysis result, the layout elements in the layout analysis result are output from top to bottom;
[0014] The layout analysis results include layout elements and coordinate areas of the layout elements in the image;
[0015] The layout elements include: text, title, table, and picture.
[0016] Preferably, in step S3, the number and area of table detection frames are obtained based on a deep learning method;
[0017] In step S4:
[0018] Step S4.1: After the image data is binarized, morphological processing is performed to obtain the horizontal and vertical lines of the table in the image, and the intersection of the horizontal and vertical lines is calculated;
[0019] Step S4.2: Based on the intersection of the horizontal and vertical lines, the contour in the image is obtained through OpenCV, and based on the circumscribed rectangle table detection method, the number and area of the table detection box are obtained.
[0020] In step S5, when the number of detection frames obtained by the deep learning method is greater than the number of detection frames obtained by the circumscribed rectangular table detection method, and the number of detection frames obtained by the circumscribed rectangular table detection method is greater than or equal to one, it is determined whether the position of the frame obtained by the circumscribed rectangular table detection method is within the frame obtained by the deep learning method;
[0021] If the result is yes, the position information of the box detected by the deep learning method is replaced by the box detected by the bounding rectangle table detection method;
[0022] If the result is no, the position information of the box detected by deep learning method is used.
[0023] Preferably, in step S6:
[0024] Step S6.1: Based on the table detection results obtained in step S5, binarization and morphological processing are performed on each table detection result, that is, each table, and then the binary images of the horizontal and vertical lines of the table are calculated, and then the binary images of the intersection points of the table are calculated according to the binary images of the horizontal and vertical lines;
[0025] Step S6.2: according to the binary graph of the intersections in the table, obtain the coordinates of each intersection, group the intersection coordinates and the intersections on each horizontal line and vertical line, and obtain the grouped intersection coordinates;
[0026] Step S6.3: According to the grouped intersection coordinates, the number of horizontal and vertical lines in the table is obtained, and all cells are traversed to represent and obtain cell information;
[0027] The representation form of the cell is [starting row, ending row, starting column, ending column];
[0028] Step S6.4: Filter all cells displayed to obtain the coordinate information of the cells that actually exist;
[0029] In step S6.4:
[0030] Step S6.4.1: Obtain the coordinates of each cell through the cell information, and determine whether the four intersection points of the cell meet the rectangular condition; if the result is yes, retain it; if the result is no, filter it;
[0031] Step S6.4.2: Filter out cells with repeated representations to obtain the actual cell coordinate information.
[0032] Preferably, in step S7:
[0033] Step S7.1: obtaining an image of a non-table area based on the coordinate information of the table area in the cell coordinate information;
[0034] Step S7.2: Perform text recognition on the image in the non-table area through PaddleOCR to obtain the coordinate information of each text box in the image and the recognized content in the text box;
[0035] Step S7.3: Based on the ordinate information of each text box, merge the recognized contents in the text boxes in the same row, and return the text content of each row to obtain result data;
[0036] The result data is output from top to bottom according to the actual layout of the page.
[0037] According to the present invention, a table text recognition system based on OCR is provided, comprising:
[0038] Module M1: Parse PDF files and convert them into image data;
[0039] Module M2: Perform layout analysis on the image data to obtain layout analysis results;
[0040] Module M3: Based on the layout analysis results, determine whether there is a table element; if the result is yes, save the coordinate information of the table detection area; if the result is no, identify it as plain text; based on the deep learning network, obtain the number and area of the table detection box;
[0041] Module M4: Based on the image data, find the contours in the image through morphological processing; and according to the contours, obtain the number and area of the table detection box;
[0042] Module M5: Determine whether the number of detection frames obtained by module M3 is equal to the number of detection frames obtained by module M4. If the result is yes, the number of detection frames obtained by module M4 is used as the input item; if the result is no, the result with a larger number of detection frames is used as the input item;
[0043] Module M6: based on the input items, obtain cell information, and filter the cell information to obtain cell coordinate information;
[0044] Module M7: Based on the cell coordinate information, obtain and return the text content of each row through the coordinate information of each text box and the identification content in the text box to obtain the result data.
[0045] Preferably, in the module M2: according to the actual layout of the page of the layout analysis result, the layout elements in the layout analysis result are output from top to bottom;
[0046] The layout analysis results include layout elements and coordinate areas of the layout elements in the image;
[0047] The layout elements include: text, title, table, and picture.
[0048] Preferably, in the module M3, the number and area of table detection boxes are obtained based on a deep learning method;
[0049] In the module M4:
[0050] Module M4.1: After binarizing the image data, perform morphological processing to obtain the horizontal and vertical lines of the table in the image, and calculate the intersection of the horizontal and vertical lines;
[0051] Module M4.2: Based on the intersection of horizontal and vertical lines, the contours in the image are obtained through OpenCV, and the number and area of the table detection boxes are obtained based on the circumscribed rectangle table detection method.
[0052] In the module M5, when the number of detection frames obtained by the deep learning method is greater than the number of detection frames obtained by the circumscribed rectangular table detection method, and the number of detection frames obtained by the circumscribed rectangular table detection method is greater than or equal to one, it is determined whether the position of the frame obtained by the circumscribed rectangular table detection method is within the frame obtained by the deep learning method;
[0053] If the result is yes, the position information of the box detected by the deep learning method is replaced by the box detected by the bounding rectangle table detection method;
[0054] If the result is no, the position information of the box detected by deep learning method is used.
[0055] Preferably, in the module M6:
[0056] Module M6.1: Based on the table detection results obtained in step S5, binarization and morphological processing are performed on each table detection result, that is, each table, and then the binary images of the horizontal and vertical lines of the table are calculated, and then the binary images of the intersection points of the table are calculated according to the binary images of the horizontal and vertical lines;
[0057] Module M6.2: According to the binary graph of the intersection points in the table, obtain the coordinates of each intersection point, group the intersection point coordinates and the intersection points on each horizontal and vertical line, and obtain the grouped intersection point coordinates;
[0058] Module M6.3: According to the coordinates of the grouped intersection points, the number of horizontal and vertical lines in the table is obtained, and all cells are traversed to represent and obtain cell information;
[0059] The representation form of the cell is [starting row, ending row, starting column, ending column];
[0060] Module M6.4: Filter all cells displayed to obtain the final real cell coordinate information;
[0061] In the module M6.4:
[0062] Module M6.4.1: Obtain the coordinates of each cell through cell information and determine whether the four intersection points of the cell meet the rectangular condition; if the result is yes, retain it; if the result is no, filter it;
[0063] Module M6.4.2: Filter out cells with repeated representations and obtain the actual cell coordinate information.
[0064] Preferably, in the module M7:
[0065] Module M7.1: obtaining an image of a non-table area based on the coordinate information of the table area in the cell coordinate information;
[0066] Module M7.2: Use PaddleOCR to perform text recognition on images in non-table areas, and obtain the coordinate information of each text box in the image and the recognized content in the text box;
[0067] Module M7.3: Based on the ordinate information of each text box, merge the recognized contents in the text boxes in the same row, and return the text content of each row to obtain the result data;
[0068] The result data is output from top to bottom according to the actual layout of the page.
[0069] Compared with the prior art, the present invention has the following beneficial effects:
[0070] 1. The present invention provides the integrity of the method for identifying the content of PDF file tables and texts, and provides effective information for subsequent table detection and cell detection by analyzing the layout results of each page of the file.
[0071] 2. The present invention performs table detection on a page, detects the table area existing in the page, and prepares for cell detection and information extraction; using this method can improve the accuracy of table detection.
[0072] 3. The present invention detects cells and extracts information, performs OCR recognition on the detected cells respectively to obtain text information of each cell, thereby improving the text recognition rate of the cells, distinguishes the table and text parts in the page through the table text typesetting algorithm, and finally outputs the recognition result. BRIEF DESCRIPTION OF THE DRAWINGS
[0073] Other features, objects and advantages of the present invention will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings:
[0074] Figure 1 A schematic diagram of the OCR table text recognition process provided by the present invention. DETAILED DESCRIPTION
[0075] The present invention is described in detail below in conjunction with specific embodiments. The following embodiments will help those skilled in the art to further understand the present invention, but are not intended to limit the present invention in any form. It should be noted that, for those of ordinary skill in the art, several changes and improvements can also be made without departing from the concept of the present invention. These all belong to the protection scope of the present invention.
[0076] The present invention realizes accurate detection of tables in documents, detects horizontal and vertical lines of tables according to traditional image processing methods, detects intersections of tables, determines the coordinate positions of cells through table intersections, recognizes tables and text contents in PDF documents, and returns accurate cell content information and text contents. In addition, the present invention realizes layout analysis and content typesetting in PDF documents, classifies tables and text contents in documents, distinguishes tables and texts through separators, and outputs tables and text contents through the real positions of pages.
[0077] According to the present invention, a table text recognition method based on OCR is provided, comprising:
[0078] Step S1: Parse the input PDF file through the PDF parsing module, and convert each page of the PDF file into image data for storage.
[0079] The PDF parsing module is used to parse the PDF file and convert it into image data.
[0080] Step S2: According to the layout analysis module in Paddle, the layout analysis results of each page of pictures are obtained, and the layout elements in the layout analysis results are output from top to bottom according to the actual layout of the page.
[0081] Specifically, the layout analysis result indicates the layout structural elements contained in the page, that is, the layout elements and the coordinate areas of the corresponding elements in the picture; the layout elements include: text, title, table, and picture;
[0082] Step S3: Based on the layout analysis result of step S2, determine whether there is a table element. If there is a table element, save the coordinate information of the table detection area; if there is no table element, identify the page as plain text.
[0083] In other words, based on the layout analysis results, determine whether there is a table element; if the result is yes, save the coordinate information of the table detection area; if the result is no, recognize it as plain text; based on the deep learning method, get the number and area of the table detection box;
[0084] The deep learning method, i.e., a table detection method based on deep learning, comprises:
[0085] Step 1: Call the open source Baidu Feijiang PPstructure interface to obtain the layout analysis results of the input image. The layout analysis results include the layout types included in each page, such as tables, texts, titles and other types of detection areas.
[0086] Step 2: When the layout type is a table, calculate the coordinates of the layout area and put these coordinates into a list. The list stores the coordinate positions of all detection boxes.
[0087] Step S4: preprocessing the image, i.e., morphological processing, using morphological processing after image binarization to obtain horizontal and vertical lines in the table, and calculating the intersection of the horizontal and vertical lines;
[0088] Based on the intersection of horizontal and vertical lines, OpenCV is used to find the contours in the image. The outermost rectangles of these contours are the outer frame rectangles of the table. These outer frame rectangles are filtered to remove the rectangular areas in the table where the table and contour areas are less than the threshold, and finally the regional coordinate position of the real table is retained.
[0089] In other words, based on the image data, the contours in the image are found through morphological processing; and based on the contours, the number and area of the table detection box are obtained based on the circumscribed rectangle table detection method;
[0090] The circumscribed rectangle table detection method, i.e., a table detection method based on the circumscribed rectangle of the table, comprises:
[0091] Step 1: Binarize and morphologically process the image to obtain the outline of the table in the image;
[0092] Step 2: Calculate the maximum and minimum horizontal and vertical coordinates for each contour to obtain the coordinate information of the circumscribed rectangle of each contour;
[0093] Step 3: Get the bounding rectangle of each table based on these coordinate information, filter out the bounding rectangles that do not meet the conditions, and finally get the bounding rectangle that meets the conditions, that is, the table area.
[0094] The length and width of the circumscribed rectangle are both less than 10 pix, and are completely inside another circumscribed rectangle.
[0095] Step S5: By comparing the number of boxes detected by the deep learning method table detection and the bounding rectangle table detection method table detection, the method with a larger number of detections is usually used as the subsequent input; in unusual cases, that is, if there are the same number of boxes, the bounding rectangle table detection method is used to detect the results; through experiments, it is found that the table area detected by the bounding rectangle table detection method is more accurate. If the number of boxes detected by the deep learning method is larger and the bounding rectangle table detection method detects at least one box, it is necessary to determine whether the position of the box detected by the bounding rectangle table detection method is in the box detected by the deep learning method. If so, it is necessary to replace the position information of the box detected by the deep learning method. If not, no replacement is performed, and the coordinate result of the box detected by the deep learning method is used.
[0096] For example, if there are two tables detected by the deep learning method and one table detected by the bounding rectangle table detection method, it is necessary to calculate the IOU of the bounding rectangle table detection method and the deep learning method. When a certain IOU exceeds a certain threshold and is the maximum value, the coordinates of the corresponding box are replaced with the result detected by the bounding rectangle table detection method. In other words, the number and actual coordinate values of the bounding rectangle table detection method and deep learning method detection boxes are calculated for each actual sample, and the IOU values of each two boxes are compared. If the conditions are met, the deep learning box will be replaced with the bounding rectangle table detection method box.
[0097] The circumscribed rectangle table detection method is named to distinguish it from the deep learning method.
[0098] The circumscribed rectangle table detection method treats different formats in a document as different targets for detection or segmentation. The task of table recognition is to recognize the table information in the document and extract the information.
[0099] Step S6: Based on the table detection result of step S5 as the input for cell information extraction, the algorithm uses the area in the table detection result as the input image, calculates, supplements and filters the intersection of the image; through the intersection, it is obtained that the entire image contains several horizontal lines and vertical lines, there are several points on each line, and the coordinates of each point are expressed by the indexes of the horizontal and vertical lines, and the cells are filtered to retain the smallest unit of cells that actually exist, and finally the coordinate position of each cell is obtained; the cell area is cut out by image processing and OCR text recognition is performed in turn to obtain the text content in each cell.
[0100] Specifically, step S6.1: based on the table detection results after comparison of the input, each table detection result (i.e. each table) is judged, firstly, the table image is binarized and morphologically processed, and the binary images of the horizontal and vertical lines are calculated according to the characteristics of the horizontal and vertical lines, and the binary image of the intersection of the table is calculated based on the binary image of the horizontal and vertical lines.
[0101] Step S6.2: According to the binary graph of the intersections in the table, the coordinates of each intersection are obtained, the coordinates of the intersections are grouped, and the intersections on each horizontal or vertical line are determined and grouped to obtain the coordinates of the intersections on each horizontal or vertical line.
[0102] Step S6.3: According to the coordinates of the grouped intersection points, determine the number of horizontal and vertical lines in the table, represent the cells, and represent each cell with [starting row, ending row, starting column, ending column], and traverse to represent all cells.
[0103] Step S6.4: Filter all cells that are displayed. First, filter out cells that do not meet the rectangular condition. Calculate the coordinates of each cell through the cell information. If the four points of the cell do not meet the rectangular condition, filter it. Secondly, filter out duplicate cells. In step S6.3, all cells are displayed, but in fact, only the first cell is needed for cells that share the same starting row and column. Therefore, other cells need to be filtered. After two filterings, the final real cell coordinate information is obtained.
[0104] Step S7: According to step S6, the coordinate information of the table area in the image is obtained, and the table area is blocked to obtain the image of the non-table area. PaddleOCR is used to perform full-image text recognition on this part of the image to obtain the coordinate information of each text box and the recognized content in the text box. By calculating the vertical coordinate information of each text box, the text box contents in the same row are merged, and finally the text content of each row is returned to obtain the result data.
[0105] According to the relationship between the upper and lower vertical coordinates of the table area and the text box coordinates, the table position is typeset, and separators are added to the upper and lower edges of the table.
[0106] Implementation example 1:
[0107] like Figure 1 As shown, the table text recognition solution used in the present invention is mainly divided into three parts:
[0108] The first part is data preprocessing, including PDF parsing, that is, converting PDF contract files into images, and performing image preprocessing on each page of the image, obtaining binary images of horizontal and vertical lines in the table and binary images of intersections through binarization and morphological processing;
[0109] The second part is table and cell detection;
[0110] First, the layout analysis results of each page are obtained through PP-Structure layout analysis, and the number of tables and coordinate areas are calculated using the layout analysis results as the deep learning method detection results;
[0111] The circumscribed rectangle table detection method is used to find the outline of the table area in the preprocessed image, and the coordinate position of the real table area is obtained by screening the outline;
[0112] Then, the table selection algorithm is used to compare the table detection results of the deep learning method and the table detection results of the circumscribed rectangle table detection method, and the final result is decided based on the number of tables.
[0113] The third part is the post-processing of table detection results, including table and text typesetting and output results. Through the table and text typesetting algorithm, the specific location information of the table and text contained in each page is calculated, and the recognition results are output from top to bottom according to the actual layout of the page.
[0114] The table text typesetting algorithm uses separators to distinguish the text parts of the detected and identified table area from those of the non-table area.
[0115] For example, the contents on a page, from top to bottom, are table area - non-table text - table area;
[0116] First, calculate the vertical coordinate ranges of the two table areas. For example, the vertical coordinate range of Table 1 is [table1_y1,table2_y2], and the vertical coordinate range of Table 2 is [table2_y1,table2_y2];
[0117] After masking the table area, perform OCR recognition on the entire image. At this time, the table area is filled with white, and the vertical coordinate range of the non-table area, that is, the text part, is calculated, for example, [text_y1, text_y2].
[0118] Finally, conditional judgment is performed on each page; the content is judged, that is, whether it is a table and the vertical coordinate relationship between them; if there is no table, no separator is inserted; if there is a table, the separator is inserted between the corresponding table and the text, as shown in Table 1:
[0119]
[0120] Table 1
[0121] The present invention also provides an OCR-based table text recognition system, which can be implemented by executing the process steps of the OCR-based table text recognition method, that is, those skilled in the art can understand the OCR-based table text recognition method as a preferred implementation of the OCR-based table text recognition system.
[0122] According to the present invention, a table text recognition system based on OCR is provided, comprising:
[0123] Module M1: Parse PDF files and convert them into image data;
[0124] Module M2: Perform layout analysis on the image data to obtain layout analysis results;
[0125] Module M3: Based on the layout analysis results, determine whether there is a table element; if the result is yes, save the coordinate information of the table detection area; if the result is no, identify it as plain text; based on the deep learning network, obtain the number and area of the table detection box;
[0126] Module M4: Based on the image data, find the contours in the image through morphological processing; and according to the contours, obtain the number and area of the table detection box;
[0127] Module M5: Determine whether the number of detection frames obtained by module M3 is equal to the number of detection frames obtained by module M4. If the result is yes, the number of detection frames obtained by module M4 is used as the input item; if the result is no, the result with a larger number of detection frames is used as the input item;
[0128] Module M6: based on the input item, obtain cell information, and filter the cell information to obtain cell coordinate information;
[0129] Module M7: Based on the cell coordinate information, obtain and return the text content of each row through the coordinate information of each text box and the identification content in the text box to obtain the result data.
[0130] Specifically, in the module M2: according to the actual layout of the page of the layout analysis result, the layout elements in the layout analysis result are output from top to bottom;
[0131] The layout analysis results include layout elements and coordinate areas of the layout elements in the image;
[0132] The layout elements include: text, title, table, and picture.
[0133] Specifically, in the module M3, based on the deep learning method, the number and area of table detection boxes are obtained;
[0134] In the module M4:
[0135] Module M4.1: After binarizing the image data, perform morphological processing to obtain the horizontal and vertical lines of the table in the image, and calculate the intersection of the horizontal and vertical lines;
[0136] Module M4.2: Based on the intersection of horizontal and vertical lines, the contours in the image are obtained through OpenCV, and the number and area of the table detection boxes are obtained based on the circumscribed rectangle table detection method.
[0137] In the module M5, when the number of detection frames obtained by the deep learning method is greater than the number of detection frames obtained by the circumscribed rectangular table detection method, and the number of detection frames obtained by the circumscribed rectangular table detection method is greater than or equal to one, it is determined whether the position of the frame obtained by the circumscribed rectangular table detection method is within the frame obtained by the deep learning method;
[0138] If the result is yes, the position information of the box detected by the deep learning method is replaced by the box detected by the bounding rectangle table detection method;
[0139] If the result is no, the position information of the box detected by deep learning method is used.
[0140] Specifically, in the module M6:
[0141] Module M6.1: Based on the table detection results obtained in step S5, binarization and morphological processing are performed on each table detection result, that is, each table, and then the binary images of the horizontal and vertical lines of the table are calculated, and then the binary images of the intersection points of the table are calculated according to the binary images of the horizontal and vertical lines;
[0142] Module M6.2: According to the binary graph of the intersection points in the table, obtain the coordinates of each intersection point, group the intersection point coordinates and the intersection points on each horizontal and vertical line, and obtain the grouped intersection point coordinates;
[0143] Module M6.3: According to the coordinates of the grouped intersection points, the number of horizontal and vertical lines in the table is obtained, and all cells are traversed to obtain cell information;
[0144] The representation form of the cell is [starting row, ending row, starting column, ending column];
[0145] Module M6.4: Filter all cells displayed to obtain the final real cell coordinate information;
[0146] In the module M6.4:
[0147] Module M6.4.1: Obtain the coordinates of each cell through cell information and determine whether the four intersection points of the cell meet the rectangular condition; if the result is yes, retain it; if the result is no, filter it;
[0148] Module M6.4.2: Filter out cells with repeated representations and obtain the actual cell coordinate information.
[0149] Specifically, in the module M7:
[0150] Module M7.1: obtaining an image of a non-table area based on the coordinate information of the table area in the cell coordinate information;
[0151] Module M7.2: Use PaddleOCR to perform text recognition on images in non-table areas, and obtain the coordinate information of each text box in the image and the recognized content in the text box;
[0152] Module M7.3: Based on the ordinate information of each text box, merge the recognized contents in the text boxes in the same row, and return the text content of each row to obtain the result data;
[0153] The result data is output from top to bottom according to the actual layout of the page.
[0154] Those skilled in the art know that, in addition to realizing the system and its various devices, modules, and units provided by the present invention in a purely computer-readable program code, it is entirely possible to realize the same functions in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, and embedded microcontrollers by logically programming the method steps. Therefore, the system and its various devices, modules, and units provided by the present invention can be considered as a hardware component, and the devices, modules, and units included therein for realizing various functions can also be regarded as structures within the hardware component; the devices, modules, and units for realizing various functions can also be regarded as both software modules for realizing the method and structures within the hardware component.
[0155] The above describes the specific embodiments of the present invention. It should be understood that the present invention is not limited to the above specific embodiments, and those skilled in the art can make various changes or modifications within the scope of the claims, which does not affect the essence of the present invention. In the absence of conflict, the embodiments of the present application and the features in the embodiments can be combined with each other arbitrarily.
Claims
1. A table text recognition method based on OCR, characterized in that: include: Step S1: Parse the PDF file and convert the PDF file into image data; Step S2: Perform layout analysis on the image data to obtain layout analysis results; Step S3: Based on the layout analysis result, determine whether there is a table element; If the result is yes, save the coordinate information of the table detection area; If the result is no, the recognition is performed according to the plain text; Based on the deep learning network, the number and area of the detection boxes in the table are obtained; Step S4: Based on the image data, find the contour in the image through morphological processing; and obtain the number and area of the detection frame in the table according to the contour; Step S5: determining whether the number of detection frames obtained in step S3 is equal to the number of detection frames obtained in step S4. If yes, the number of detection frames obtained in step S4 is used as the input item. If the result is no, the detection result with more detection boxes is used as the input item; Step S6: based on the input item, obtain cell information, and filter the cell information to obtain cell coordinate information; Step S7: Based on the cell coordinate information, the coordinate information of each text box and the identified content in the text box are obtained, and the text content of each row is returned to obtain the result data.
2. The method for recognizing text in a table based on OCR according to claim 1, characterized in that: In the step S2: according to the actual layout of the page of the layout analysis result, the layout elements in the layout analysis result are output from top to bottom; The layout analysis results include layout elements and coordinate areas of the layout elements in the image; The layout elements include: text, title, table, and picture.
3. The method for recognizing text in a table based on OCR according to claim 2, characterized in that: In the step S3, based on the deep learning method, the number and area of the table detection boxes are obtained; In step S4: Step S4.1: After the image data is binarized, morphological processing is performed to obtain the horizontal and vertical lines of the table in the image, and the intersection points of the horizontal and vertical lines are calculated; Step S4.2: Based on the intersection of the horizontal and vertical lines, the contour in the image is obtained through OpenCV, and based on the circumscribed rectangle table detection method, the number and area of the table detection box are obtained. In step S5, when the number of detection frames obtained by the deep learning method is greater than the number of detection frames obtained by the circumscribed rectangular table detection method, and the number of detection frames obtained by the circumscribed rectangular table detection method is greater than or equal to one, it is determined whether the position of the frame obtained by the circumscribed rectangular table detection method is within the frame obtained by the deep learning method; If the result is yes, the position information of the box detected by the deep learning method is replaced by the box detected by the bounding rectangle table detection method; If the result is no, the position information of the box detected by deep learning method is used.
4. The method for recognizing text in a table based on OCR according to claim 3, characterized in that: In step S6: Step S6.1: Based on the table detection results obtained in step S5, binarization and morphological processing are performed on each table detection result, that is, each table, and then the binary images of the horizontal and vertical lines of the table are calculated, and then the binary images of the intersection points of the table are calculated according to the binary images of the horizontal and vertical lines; Step S6.2: according to the binary graph of the intersections in the table, obtain the coordinates of each intersection, group the intersection coordinates and the intersections on each horizontal line and vertical line, and obtain the grouped intersection coordinates; Step S6.3: According to the grouped intersection coordinates, the number of horizontal and vertical lines in the table is obtained, and all cells are traversed to represent and obtain cell information; The representation form of the cell is [starting row, ending row, starting column, ending column]; Step S6.4: Filter all cells displayed to obtain the coordinate information of the cells that actually exist; In step S6.4: Step S6.4.1: Obtain the coordinates of each cell through the cell information, and determine whether the four intersection points of the cell meet the rectangular condition; if the result is yes, retain it; if the result is no, filter it; Step S6.4.2: Filter out cells with repeated representations to obtain the actual cell coordinate information.
5. The method for recognizing text in a table based on OCR according to claim 4, characterized in that: In step S7: Step S7.1: obtaining an image of a non-table area based on the coordinate information of the table area in the cell coordinate information; Step S7.2: Perform text recognition on the image in the non-table area through PaddleOCR to obtain the coordinate information of each text box in the image and the recognized content in the text box; Step S7.3: Based on the ordinate information of each text box, merge the recognized contents in the text boxes in the same row, and return the text content of each row to obtain result data; The result data is output from top to bottom according to the actual layout of the page.
6. A table text recognition system based on OCR, characterized in that: include: Module M1: Parse PDF files and convert them into image data; Module M2: Perform layout analysis on the image data to obtain layout analysis results; Module M3: Based on the layout analysis results, determine whether there are table elements; If the result is yes, save the coordinate information of the table detection area; If the result is no, the recognition is performed according to the plain text; Based on the deep learning network, the number and area of the detection boxes in the table are obtained; Module M4: Based on the image data, find the contour in the image through morphological processing; and according to the contour, obtain the number of detection box areas in the table; Module M5: Determine whether the number of detection frames obtained by module M3 is equal to the number of detection frames obtained by module M4. If yes, use the number of detection frames obtained by module M4 as input; If the result is no, the detection result with more detection boxes is used as the input item; Module M6: based on the input items, obtain cell information, and filter the cell information to obtain cell coordinate information; Module M7: Based on the cell coordinate information, obtain and return the text content of each row through the coordinate information of each text box and the identification content in the text box to obtain the result data.
7. The OCR-based table text recognition system according to claim 6, characterized in that: In the module M2: according to the actual layout of the page of the layout analysis result, the layout elements in the layout analysis result are output from top to bottom; The layout analysis results include layout elements and coordinate areas of the layout elements in the image; The layout elements include: text, title, table, and picture.
8. The OCR-based table text recognition system according to claim 7, characterized in that: In the module M3, based on the deep learning method, the number and area of table detection boxes are obtained; In the module M4: Module M4.1: After binarizing the image data, perform morphological processing to obtain the horizontal and vertical lines of the table in the image, and calculate the intersection of the horizontal and vertical lines; Module M4.2: Based on the intersection of horizontal and vertical lines, the contours in the image are obtained through OpenCV, and the number and area of the table detection boxes are obtained based on the circumscribed rectangle table detection method. In the module M5, when the number of detection frames obtained by the deep learning method is greater than the number of detection frames obtained by the circumscribed rectangular table detection method, and the number of detection frames obtained by the circumscribed rectangular table detection method is greater than or equal to one, it is determined whether the position of the frame obtained by the circumscribed rectangular table detection method is within the frame obtained by the deep learning method; If the result is yes, the position information of the box detected by the deep learning method is replaced by the box detected by the bounding rectangle table detection method; If the result is no, the position information of the box detected by deep learning method is used.
9. The OCR-based table text recognition system according to claim 8, characterized in that: In the module M6: Module M6.1: Based on the table detection results obtained in step S5, binarization and morphological processing are performed on each table detection result, that is, each table, and then the binary images of the horizontal and vertical lines of the table are calculated, and then the binary images of the intersection points of the table are calculated according to the binary images of the horizontal and vertical lines; Module M6.2: According to the binary graph of the intersection points in the table, obtain the coordinates of each intersection point, group the intersection point coordinates and the intersection points on each horizontal and vertical line, and obtain the grouped intersection point coordinates; Module M6.3: According to the coordinates of the grouped intersection points, the number of horizontal and vertical lines in the table is obtained, and all cells are traversed to obtain cell information; The representation form of the cell is [starting row, ending row, starting column, ending column]; Module M6.4: Filter all cells displayed to obtain the final real cell coordinate information; In the module M6.4: Module M6.4.1: Obtain the coordinates of each cell through cell information and determine whether the four intersection points of the cell meet the rectangular condition; If the result is yes, it is retained; if the result is no, it is filtered; Module M6.4.2: Filter out cells with repeated representations and obtain the actual cell coordinate information.
10. The OCR-based table text recognition system according to claim 9, characterized in that: In the module M7: Module M7.1: obtaining an image of a non-table area based on the coordinate information of the table area in the cell coordinate information; Module M7.2: Use PaddleOCR to perform text recognition on images in non-table areas, and obtain the coordinate information of each text box in the image and the recognized content in the text box; Module M7.3: Based on the ordinate information of each text box, merge the recognized contents in the text boxes in the same row, and return the text content of each row to obtain the result data; The result data is output from top to bottom according to the actual layout of the page.
Citation Information
Patent Citations
Method and device for identifying diagram
CN104636717A
Intelligent extraction method and device for table cells of financial statements
CN108491788A
A detection method for a curved form line of a financial statement
CN109766749A
Table recognition restoration method based on deep learning and image processing
CN112364834A
Method and device for identifying table information in image, electronic equipment and storage medium
CN112818812A
Cited By
Text evaluation method and system
CN119578401A
Multi-modal analysis method for mechanism investigation PDF (Portable Document Format)
CN120472487A
A multi-modal analysis method for institutional survey PDFs
CN120472487B
