A method and system for intelligently extracting input text containing mathematical formulas
Using intelligent extraction methods to split and identify embedded and interline formulas in complex documents, combined with different recognition model processing, it solves the problem of insufficient accuracy and robustness of existing OCR technology in mathematical formula recognition, and achieves efficient mathematical formulas. Extraction and text processing.
Patent Information
- Application Number
- CN202410349731.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-03-26
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2044-03-26
AI Technical Summary
Existing OCR technology has insufficient accuracy and robustness when dealing with recognition of mathematical formulas in complex documents, especially challenges in processing complex formulas embedded in text.
An intelligent extraction method containing mathematical formulas is proposed. Through format judgment, preprocessing, angle correction, formula detection, layout analysis, text recognition and merging processing, it splits and identifies embedded formulas and interline formulas, and uses different models to identify and combine them. Merge the results and solve the problem of nested output of formula text.
It improves the recognition accuracy and processing efficiency of mathematical formulas in complex documents, can efficiently process mixed Chinese and English texts, solves the problem of English number adhesion, and enhances the coherence and readability of text processing results.
Smart Images

Figure CN118230348B
Abstract
Description
Technical Field
[0001] The present invention belongs to the technical field of text extraction, and relates to a method and system for extracting input text, and in particular to a method and system for intelligently extracting input text containing mathematical formulas. Background Art
[0002] With the rapid development of information technology, a large amount of text data is stored electronically. The effective extraction and utilization of this data has become increasingly important, especially in the fields of knowledge management and information retrieval.
[0003] Among them, optical character recognition (OCR) technology has received significant attention due to its wide application in document digitization and automatic text analysis. OCR technology mainly uses character template matching and machine learning algorithms to convert characters in images into editable text. In recent years, with the rise of deep learning, OCR systems based on convolutional neural networks (CNN) have begun to significantly improve their performance. For example, open source OCR systems such as Tesseract OCR have successfully improved the accuracy of text recognition by combining traditional algorithms and deep learning technology. In comparison, PaddleOCR, which uses deep learning, performs better in Chinese character recognition. However, in the face of complex document structures such as charts, formulas, and page layouts, existing OCR technology has not yet reached ideal standards in terms of accuracy, robustness, and processing speed.
[0004] At the same time, in text extraction, formula detection and recognition used to rely on pattern matching-based methods, but there are limitations in dealing with complex and irregular formulas. With the development of machine learning technology, deep learning-based methods (such as LaTeX-OCR) have made significant progress, and automatic feature learning through deep neural networks has improved the recognition ability of complex formulas. However, current models still face challenges in dealing with complex formulas embedded in the text.
[0005] Therefore, in view of the defects existing in the above-mentioned prior art, it is necessary to develop a new intelligent extraction method and system for input text containing mathematical formulas. Summary of the invention
[0006] In order to overcome the defects of the prior art, the present invention proposes an intelligent extraction method and system for input text containing mathematical formulas, which can effectively improve the extraction efficiency and accuracy of text and formula content in textbooks, books, PDF papers, and pictures, and provide strong support for text information processing in related fields.
[0007] In order to achieve the above object, the present invention provides the following technical solutions:
[0008] A method for intelligently extracting input text containing mathematical formulas, characterized in that it comprises the following steps:
[0009] 1) Determine the format of the input text. If the format of the input text is not a picture format, convert the input text into a picture format text and pre-process the picture format text;
[0010] 2) Performing text detection on the preprocessed text in the image format to obtain an OCR detection frame, determining whether to perform angle correction on the preprocessed text in the image format through the aspect ratio of the OCR detection frame and the text direction classifier, and performing angle correction when angle correction is required to obtain the corrected text in the image format and the OCR detection frame;
[0011] 3) performing formula detection on the corrected text in the image format to obtain a formula detection frame and its formula category, wherein the formula category includes an embedded formula and an interline formula;
[0012] 4) performing layout analysis on the corrected text in picture format to obtain a layout analysis frame and its layout categories, wherein the layout categories include title, text, picture, figure annotation, table, table annotation, formula, header, footer and references;
[0013] 5) For the embedded formula, judging whether the corrected OCR detection frame contains the embedded formula according to the formula detection frame and splitting the OCR detection frame containing the embedded formula to obtain the OCR detection frame of the plain text;
[0014] 6) cropping the text in the corrected picture format according to the formula detection frame to obtain a formula area, performing formula recognition on the formula area using a formula recognition model and simplifying the format of the output LaTeX to obtain a formula recognition result;
[0015] 7) Use the corresponding OCR recognition model for different scenarios to perform text recognition on the OCR detection box of the plain text to obtain the text recognition result;
[0016] 8) Combine the layout analysis frame and its layout category to determine and merge the formula recognition results and text recognition results in the same detection frame to obtain the extraction result of the input text.
[0017] Preferably, the intelligent extraction method of input text containing mathematical formulas further comprises:
[0018] 9) For the interline formula, determine whether the formula detection frame overlaps significantly with the corrected OCR detection frame. If so, proceed to step 10);
[0019] 10) cropping the text in the corrected picture format according to the formula detection frame to obtain a formula area, using a formula recognition model to perform formula recognition on the formula area and simplifying the format of the output LaTeX to obtain a formula recognition result;
[0020] 11) Using the corresponding OCR recognition model for different scenarios to perform text recognition on the corrected OCR detection frame to obtain text recognition results;
[0021] 12) The text recognition result is replaced by the formula recognition result to obtain an extraction result of the input text.
[0022] Preferably, the step 1) specifically includes:
[0023] 1.1) Determine whether the input text is in PDF format or image format. If the input text is in PDF format, use a PDF parser to convert the input text into an image format.
[0024] 1.2) The text in the image format is dynamically extended to match the background size, and the median filter algorithm is used to denoise the text in the image format.
[0025] Preferably, the step 2) specifically includes:
[0026] 2.1) Input the preprocessed text in the image format into the OCR detection model for text detection to obtain the OCR detection box;
[0027] 2.2) Calculate the aspect ratio of the OCR detection frame. If the proportion of OCR detection frames with a height greater than the width in all OCR detection frames exceeds a set threshold, the pre-processed image format text is rotated 90 degrees clockwise to obtain an updated image format text. Otherwise, the pre-processed image format text and OCR detection frame are directly output;
[0028] 2.3) Inputting the updated text in the image format into the OCR detection model for text detection to obtain an updated OCR detection frame;
[0029] 2.4) According to the updated OCR detection frame, the updated text in the picture format is cropped to obtain the OCR detection frame area and the OCR detection frame area is sent to the text direction classifier for direction determination. The output of the text direction classifier is 0 degrees or 180 degrees. If the proportion of the OCR detection frame area with an output of 180 degrees in the total OCR detection frame area is greater than the set threshold, the text in the updated picture format is rotated 180 degrees clockwise to obtain the text in the picture format that is updated again. Otherwise, the updated text in the picture format and the updated OCR detection frame are directly output;
[0030] 2.5) Input the text in the updated image format into the OCR detection model for text detection to obtain the updated OCR detection frame, and output the text in the updated image format and the updated OCR detection frame.
[0031] Preferably, the step 5) specifically includes:
[0032] 5.1) For each OCR detection box, obtain the corresponding first-order equations of the upper, lower, left and right boundary lines according to the coordinates of its upper left corner, lower left corner, upper right corner and lower right corner;
[0033] 5.2) Filtering a formula detection frame whose formula category is an embedded formula from the formula detection frame, calculating the X-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula and substituting it into a linear equation of the upper and lower boundary lines of the OCR detection frame to determine whether the Y-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula is within the Y value interval of the upper and lower boundary lines of the OCR detection frame, calculating the Y-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula and substituting it into a linear equation of the left and right boundary lines of the OCR detection frame to determine whether the X-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula is within the X value interval of the left and right boundary lines of the OCR detection frame;
[0034] 5.3) If the Y-axis coordinate of the center point of the formula detection box with the formula category of embedded formula is within the Y value interval of the upper and lower boundary lines of the OCR detection box, and the X-axis coordinate of the center point of the formula detection box with the formula category of embedded formula is within the X value interval of the left and right boundary lines of the OCR detection box, calculate the ratio of the overlapping area of the OCR detection box and the formula detection box with the formula category of embedded formula to the total area of the two, that is, IoU;
[0035] 5.4) If the IoU is greater than 0, the formula detection box with the formula category as embedded formula is added to the formula list, and the OCR detection box is split.
[0036] Preferably, the step 6) is specifically:
[0037] 6.1) Crop the text in the corrected image format according to the coordinates of the formula detection box to obtain the formula area and send the formula area to the formula recognition model, and the output result is LaTeX;
[0038] 6.2) Send the output LaTeX to the rendering engine for rendering judgment. If the rendering fails, the format is repaired. If the rendering still fails after the format is repaired, an additional error message is output to prevent the output of incorrect formulas;
[0039] 6.3) Simplify LaTeX and remove unnecessary formats. The final output includes the formula detection box, formula category and formula LaTeX.
[0040] Preferably, the step 7) is specifically:
[0041] 7.1) Crop the text in the rectified image format according to the split plain text OCR detection frame to obtain the OCR detection frame area;
[0042] 7.2) Send the OCR detection box area to the Chinese OCR recognition model for preliminary text recognition to obtain preliminary text recognition results;
[0043] 7.3) If the preliminary text recognition result only contains English or numbers, the OCR detection box area is sent to the English OCR recognition model for recognition to obtain the final text recognition result and overwrite the preliminary text recognition result. The final output result includes the OCR detection box and the text recognition result.
[0044] Preferably, the step 8) specifically includes:
[0045] 8.1) Add the formula recognition results to the text recognition results;
[0046] 8.2) Preliminarily determine whether the formula detection box and the OCR detection box are in the same row, so as to preliminarily filter out the detection boxes belonging to the same row;
[0047] 8.3) Classifying the preliminarily screened detection frames according to the layout analysis frame and its layout category, and determining whether the preliminarily screened detection frames belong to the same layout category, so as to screen out the detection frames belonging to the same layout;
[0048] 8.4) Project the selected detection frames belonging to the same layout on the X-axis to determine the segmentation points, and judge whether the detection frame can be segmented on the X-axis according to the number of segmentation points. If it cannot be segmented, it is determined that the selected detection frames belonging to the same layout belong to the same line detection frame; if it can be segmented, it is determined that the selected detection frames belonging to the same layout do not belong to the same line detection frame;
[0049] 8.5) The determined detection boxes in the same row are sorted within the row and then merged. The output extraction result of the input text includes the merged row text detection box and the merged text content.
[0050] Preferably, in step 8.2), when the Y-axis intersection of the formula detection box and the OCR detection box is greater than a threshold and the X-axis intersection is less than a threshold, it is preliminarily determined that the formula detection box and the OCR detection box are in the same row.
[0051] In addition, the present invention also provides an intelligent extraction system for input text containing mathematical formulas, characterized in that it includes:
[0052] An input format determination and image preprocessing module, which is used to determine the format of the input text. If the format of the input text is not an image format, the input text is converted into an image format text and the image format text is preprocessed;
[0053] An automatic image correction module is used to perform text detection on the preprocessed image format text to obtain an OCR detection frame, determine whether to perform angle correction on the preprocessed image format text through the aspect ratio of the OCR detection frame and the text direction classifier, and perform angle correction when angle correction is required to obtain the corrected image format text and OCR detection frame;
[0054] A formula detection module, which is used to perform formula detection on the corrected text in the image format to obtain a formula detection frame and its formula category, wherein the formula category includes an embedded formula and an interline formula;
[0055] A layout analysis module, which is used to perform layout analysis on the text in the corrected picture format to obtain a layout analysis frame and its layout categories, wherein the layout categories include title, text, picture, figure annotation, table, table annotation, formula, header, footer and references;
[0056] An embedded formula text splitting module is used to determine whether the corrected OCR detection frame contains an embedded formula according to the formula detection frame and split the OCR detection frame containing the embedded formula to obtain an OCR detection frame of the plain text;
[0057] A formula recognition module is used to crop the text in the picture format according to the formula detection frame to obtain a formula area, use a formula recognition model to perform formula recognition on the formula area and simplify the format of the output LaTeX to obtain a formula recognition result;
[0058] A text recognition module is used to perform text recognition on the corrected OCR detection frame using the corresponding OCR recognition model according to different scenarios to obtain text recognition results;
[0059] The merging processing module is used to combine the layout analysis frame and its layout category to perform peer detection frame judgment and merge the formula recognition result and the text recognition result to obtain the extraction result of the input text.
[0060] Compared with the prior art, the intelligent extraction method and system of input text containing mathematical formulas of the present invention has one or more of the following beneficial technical effects:
[0061] 1. The present invention provides an innovative solution for extracting input text containing mathematical formulas, which can accurately identify and process mathematical formulas in complex documents. It separates the embedded formulas in the text from the ordinary text and uses the best model to identify them separately, and then merges and restores them, solving the problem of nested output of formula text.
[0062] 2. The present invention adopts different text recognition models in a targeted manner, so that the recognition is accurate and can efficiently process texts mixed with Chinese and English, and can solve the problem of English and numbers sticking together without spaces.
[0063] 3. The present invention realizes the intelligent generation of coherent text lines by identifying whether the recognized text is in the same line, and through internal sorting and merging, and takes into account the layout of the lines in the page layout, so that the text is accurately and orderly organized, thereby enhancing the coherence and readability of the text processing results. BRIEF DESCRIPTION OF THE DRAWINGS
[0064] Figure 1 It is a flow chart of the intelligent extraction method of input text containing mathematical formulas of the present invention.
[0065] Figure 2 It is a flow chart of the automatic picture correction method of the present invention.
[0066] Figure 3 It is a flow chart of the embedded formula text splitting of the present invention.
[0067] Figure 4 It is a flow chart of the process of combining the formula recognition result and the text recognition result of the present invention.
[0068] Figure 5 It is a schematic diagram of the composition of the intelligent extraction system of input text containing mathematical formulas of the present invention. DETAILED DESCRIPTION
[0069] Before describing in detail any embodiment of the present invention, it should be understood that the present invention is not limited in its application to the construction and arrangement details of the components described below or illustrated in the following figures. The present invention can have other embodiments and can be practiced or carried out in various ways. In addition, it should be understood that the words and terms used here are for descriptive purposes and should not be considered restrictive. The use of "including" or "having" and its variations herein is intended to cover the items and their equivalents and additional items displayed below. Unless otherwise specified or limited, the terms "install", "connect", "support" and "couple" and their variations are widely used and cover direct installation and indirect installation, connection, support and connection. In addition, "connect" and "couple" are not limited to physical or mechanical connections or connections.
[0070] Furthermore, on the first aspect, in the disclosure of the present invention, the orientation or positional relationship indicated by terms such as "longitudinal", "transverse", "upper", "lower", "front", "back", "left", "right", "vertical", "horizontal", "top", "bottom", "inside" and "outside" are based on the orientation or positional relationship shown in the accompanying drawings, which are only for the convenience of describing the present invention and simplifying the description, rather than indicating or implying that the device or element referred to must have a specific orientation, be constructed and operate in a specific orientation, and therefore the above terms cannot be understood as limitations on the present invention; on the second aspect, the term "one" should be understood as "at least one" or "one or more", that is, in one embodiment, the number of an element may be one, while in another embodiment, the number of the element may be multiple, and the term "one" cannot be understood as a limitation on the quantity.
[0071] Figure 1 The flowchart of the intelligent extraction method of input text containing mathematical formulas of the present invention is shown. Figure 1 As shown, the intelligent extraction method of input text containing mathematical formulas of the present invention comprises the following steps:
[0072] 1. Input format judgment and image preprocessing.
[0073] For the input text to be recognized, the format of the input text needs to be determined. If the format of the input text is not a picture format, the input text is converted into a picture format text and the picture format text is preprocessed.
[0074] Specifically, first, it is determined whether the input text is in a picture format. If the input text is not in a picture format, for example, in a PDF format, a PDF parser is used to convert the input text into a picture format.
[0075] Next, the text in the image format is dynamically extended to the background size, and the median filter algorithm is used to denoise the text in the image format. Dynamically extending the background size can meet the optimal input resolution requirements of multiple subsequent detection and recognition models. Through denoising, the image background can be processed to improve the image quality. The specific technologies of dynamically extending the background size and denoising are all existing technologies. For the sake of simplicity, they are not described in detail here.
[0076] 2. Automatic picture correction.
[0077] Considering that pages in some books or images may be rotated 90 degrees, automatic image correction is required.
[0078] When automatically correcting an image, text detection is performed on the text in the preprocessed image format to obtain an OCR detection frame. The aspect ratio of the OCR detection frame and the text direction classifier are used to determine whether to perform angle correction on the text in the preprocessed image format. If angle correction is required, angle correction is performed to obtain the text in the corrected image format and the OCR detection frame.
[0079] Specifically, Figure 2 As shown, the automatic correction of the picture specifically includes:
[0080] 1. Input the preprocessed text in the image format into the OCR detection model for text detection to obtain the OCR detection box.
[0081] 2. Calculate the aspect ratio of the OCR detection frame. If the proportion of OCR detection frames whose height is greater than their width exceeds the set threshold, the preprocessed image format text is rotated 90 degrees clockwise to obtain the updated image format text. Otherwise, the preprocessed image format text and OCR detection frame are directly output.
[0082] The threshold in this step can be set to 0.8.
[0083] 3. Input the updated text in the image format into the OCR detection model for text detection to obtain an updated OCR detection box.
[0084] 4. According to the updated OCR detection frame, the updated text in the picture format is cropped to obtain the OCR detection frame area and the OCR detection frame area is sent to the text direction classifier for direction determination. The output of the text direction classifier is 0 degrees or 180 degrees. If the proportion of the OCR detection frame area outputted as 180 degrees in the total OCR detection frame area is greater than the set threshold, the text in the updated picture format is rotated 180 degrees clockwise to obtain the text in the picture format that is updated again. Otherwise, the updated text in the picture format and the updated OCR detection frame are directly output.
[0085] The text direction classifier can be a text direction classifier of PaddleOCR. And, when cropping in the updated text in the image format according to the updated OCR detection frame, the text in the updated image format can be cropped according to the coordinates of the updated OCR detection frame to obtain multiple OCR detection frame areas and batch-feed the multiple OCR detection frame areas to the text direction classifier for direction determination. Moreover, the threshold in this step can also be set to 0.8.
[0086] 5. Input the text in the updated image format into the OCR detection model for text detection to obtain the updated OCR detection frame, and output the text in the updated image format and the updated OCR detection frame.
[0087] Among them, the OCR detection model can adopt the PP-OCRv4 detection model of PaddleOCR.
[0088] Through the above steps, text and OCR detection boxes in the image format with the correct orientation can be obtained.
[0089] 3. Perform formula detection on the text in the corrected image format to obtain a formula detection frame and its formula category.
[0090] The formula categories include embedded formulas and interline formulas. In addition, when performing formula detection, the corrected text in the image format can be fed into the formula detection model to obtain a formula detection frame and its formula category.
[0091] 4. Perform layout analysis on the text in the corrected image format to obtain a layout analysis frame and its layout category.
[0092] The layout categories include title, text, pictures, figure annotations, tables, table annotations, formulas, headers, footers and references.
[0093] Furthermore, when performing layout analysis, the text in the corrected picture format may be sent to a layout analysis model, for example, a PP-PicoDet model for layout analysis to obtain a layout analysis frame and its layout category.
[0094] Meanwhile, preferably, after obtaining the layout analysis frame, overlap judgment can be performed based on the coordinates of the layout analysis frame. If the layout analysis frame overlaps significantly, for example, the overlap rate exceeds 30%, deduplication processing is performed.
[0095] In the present invention, different processing methods are used for embedded formulas and in-row formulas. For embedded formulas, the following steps 5 to 8 are processed, and for in-row formulas, the following steps 9 to 12 are processed.
[0096] 5. Splitting of embedded formula text.
[0097] For OCR detection boxes containing embedded formulas, the formula and text are split to obtain formula detection results, thereby improving recognition accuracy.
[0098] Among them, it can be determined whether the OCR detection frame with the correct direction obtained in step 2 contains the embedded formula according to the formula detection frame whose formula category is the embedded formula, and the OCR detection frame containing the embedded formula is split to obtain the OCR detection frame of the plain text.
[0099] In the present invention, the embedded formula text splitting includes embedded formula and text matching and embedded formula and text cutting. Through the embedded formula and text matching, it can be judged whether the OCR detection box contains the embedded formula. Through the embedded formula and text cutting, the OCR detection box containing the embedded formula can be split to cut it into a formula detection box and a plain text OCR detection box.
[0100] The embedded formula and text matching is as follows: for each OCR detection box, find the embedded formula in it. The matching conditions are: (1) the center point coordinates of the formula detection box whose formula category is embedded formula are within the range of the OCR detection box; (2) the formula detection box whose formula category is embedded formula overlaps with the OCR detection box.
[0101] The specific algorithm for matching condition (1) is:
[0102] 1. Calculate the coordinates of the OCR detection frame and generate the upper and lower boundary lines and left and right boundary line equations of the OCR detection frame;
[0103] 2. Calculate the X coordinate of the center point of the formula detection box whose formula category is embedded formula and bring it into the upper and lower boundary line equations of the OCR detection box to determine whether the Y coordinate of the center point of the formula detection box whose formula category is embedded formula is within the Y value range of the upper and lower boundary lines;
[0104] 3. Calculate the Y coordinate of the center point of the formula detection box whose formula category is embedded formula and substitute it into the left and right boundary line equations of the OCR detection box to determine whether the X coordinate of the center point of the formula detection box whose formula category is embedded formula is within the X value range of the left and right boundary lines.
[0105] The specific algorithm for matching condition (2) is:
[0106] 1. According to the coordinates of the formula detection box whose formula category is embedded formula and the coordinates of the OCR detection box, determine whether the formula detection box whose formula category is embedded formula and the OCR detection box have an intersection;
[0107] 2. When matching condition (1) is met, the IOU (Intersection over Union, which indicates the ratio of the area of the overlapping part of the two to the total area) of the formula detection box with the formula category of embedded formula and the OCR detection box is calculated. If the formula detection box with the formula category of embedded formula is within the range of the OCR detection box, and there is a certain overlap between the two, the formula detection box with the formula category of embedded formula is added to the corresponding formula list, and the OCR detection box is determined to be the OCR detection box containing the embedded formula.
[0108] The specific steps of embedding formula and text cutting are: cutting the OCR detection frame according to the coordinates of the formula detection frame whose formula category is embedded formula, adding the segmented formula detection frame to the corresponding list, and returning the result list. The specific algorithm for segmenting the OCR detection frame is:
[0109] 1. If the OCR detection box does not have an embedded formula, return to the original OCR detection box directly.
[0110] 2. If there is an embedded formula in the OCR detection frame, sort the formula detection frames whose formula category is embedded formula in the list obtained above according to the X-axis, process each formula detection frame whose formula category is embedded formula in turn, and segment it according to the position of its left boundary and the position of its right boundary.
[0111] 3. Make sure the OCR detection box is a rectangle after segmentation. If it is not a rectangle, segment out the extra parts. Finally, return a list of all segmented OCR detection boxes.
[0112] Based on the above principle, Figure 3 As shown, the embedded formula text splitting of the present invention specifically includes:
[0113] 1. For each OCR detection box, obtain the corresponding first-order equations of the upper, lower, left and right boundary lines according to its upper left corner coordinates, lower left corner coordinates, upper right corner coordinates and lower right corner coordinates.
[0114] 2. Filtering a formula detection frame whose formula category is an embedded formula from the formula detection frame, calculating the X-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula and substituting it into a linear equation of the upper and lower boundary lines of the OCR detection frame to determine whether the Y-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula is within the Y value interval of the upper and lower boundary lines of the OCR detection frame, calculating the Y-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula and substituting it into a linear equation of the left and right boundary lines of the OCR detection frame to determine whether the X-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula is within the X value interval of the left and right boundary lines of the OCR detection frame;
[0115] 3. If the Y-axis coordinate of the center point of the formula detection box with the formula category of embedded formula is within the Y value interval of the upper and lower boundary lines of the OCR detection box, and the X-axis of the center point of the formula detection box with the formula category of embedded formula is within the X value interval of the left and right boundary lines of the OCR detection box, then calculate the ratio of the overlapping area of the OCR detection box and the formula detection box with the formula category of embedded formula to the total area of the two, that is, IoU;
[0116] 4. Determine whether the IoU is greater than 0. If the IoU is greater than 0, add the formula detection box whose formula category is an embedded formula to the formula list, determine that the OCR detection box is an OCR detection box containing a mathematical formula, and split the OCR detection box.
[0117] If it is determined that the OCR detection box is an OCR detection box that does not contain an embedded formula, the OCR detection box is directly returned. If it is determined that the OCR detection box is an OCR detection box that contains an embedded formula, it is determined whether the OCR detection box has one or more embedded formulas. If there are multiple embedded formulas, the formula detection boxes whose formula categories are embedded formulas are sorted on the X-axis, and the OCR detection boxes are cut according to the left and right boundary positions of the formula detection boxes whose formula categories are embedded formulas.
[0118] Furthermore, if there is a non-rectangular OCR detection frame, during the cutting process, the redundant non-rectangular part of the OCR detection frame is cut and discarded, and finally the multiple split OCR detection frames are returned.
[0119] 6. Formula recognition.
[0120] The formula detection frame is cropped in the text in the corrected picture format to obtain a formula area, a formula recognition model is used to perform formula recognition on the formula area and the output LaTeX is format simplified to obtain a formula recognition result.
[0121] Specifically, first, the coordinates of the formula detection box are cropped in the text of the rectified picture format to obtain the formula area. In order to avoid the occurrence of garbled characters in the small picture formula recognition, the formula area is dynamically extended and background processed.
[0122] The processed formula area is sent to the formula recognition model, and the output result is in LaTeX format, that is, LaTeX. The formula recognition model can adopt the existing handwritten formula recognition model.
[0123] Then, the output LaTeX is sent to the rendering engine for rendering judgment. If the rendering fails (rendering failure is mainly due to the omission of some paired tokens), the format is repaired. If the rendering still fails after the format repair, additional error information is output to prevent the output of incorrect formulas. The rendering engine can use the KaTex rendering engine.
[0124] Finally, simplify the LaTeX and remove unnecessary formats to provide a clearer and more concise formula expression. The final output includes the formula detection box, formula category (embedded formula), and the LaTeX of the formula.
[0125] 7. Text recognition.
[0126] According to different scenarios, the corresponding OCR recognition model is used to perform text recognition on the OCR detection box of the plain text to obtain the text recognition result.
[0127] Specifically, first, the plain text OCR detection frame split according to step 5 is cropped in the text in the corrected image format to obtain the OCR detection frame area.
[0128] Then, the OCR detection box area is sent to the Chinese OCR recognition model for preliminary text recognition to obtain a preliminary text recognition result. The Chinese OCR recognition model can adopt the PP-OCRv4 Chinese recognition model of PaddleOCR.
[0129] Among them, in order to solve the problem of English and numerical space adhesion and improve the recognition accuracy of English and numerical content, in the present invention, if the preliminary text recognition result only contains English or numbers, the OCR detection box area is sent to the English OCR recognition model for recognition to obtain the final text recognition result and cover the preliminary text recognition result. Among them, the English OCR recognition model can adopt the PP-OCRv4 English recognition model of PaddleOCR. Therefore, by using different text recognition models in a targeted manner, the recognition is accurate and can efficiently process texts mixed in Chinese and English.
[0130] In the present invention, the final output result of text recognition includes an OCR detection box and a final text recognition result.
[0131] 8. Combined processing.
[0132] Combined with the layout analysis frame and its layout category, the formula recognition result of step six and the text recognition result of step seven are judged and merged in the same line detection frame to obtain the extraction result of the input text.
[0133] In the present invention, after the formula recognition result is added to the text recognition result, the merging process continuously evaluates whether the formula recognition result and the text recognition result are located in the same row, and the formula recognition result and the text recognition result confirmed to be in the same row are merged.
[0134] The specific steps of the merge row algorithm are:
[0135] 1. Determine whether the formula detection box and the OCR detection box whose formula category is embedded formula are in the same row:
[0136] (1) Initial filtering: When the Y-axis intersection between the formula detection frame and the OCR detection frame of the formula category of embedded formula is greater than the threshold value of 0.5, and the X-axis intersection is less than the threshold value of 0.5 (screening out the formula detection frame and OCR detection frame that exist in different rows but have overlapping axes), the formula detection frame and OCR detection frame of the formula category of embedded formula are initially filtered out;
[0137] (2) Further confirmation, when the initial filtering is satisfied, the layout analysis frame and its layout category are combined to determine whether the formula detection frame and the OCR detection frame whose formula category is embedded formula are in the same layout;
[0138] (3) After the above two conditions are met, the X_cut algorithm is used to determine whether the formula detection box and the OCR detection box are segmented on the X-axis. If they cannot be segmented, they are determined to be in the same row; otherwise, they are not in the same row.
[0139] In the present invention, the X_cut algorithm is specifically:
[0140] (1) Detection box sorting: Sort the formula detection boxes and OCR detection boxes according to their X-axis coordinates.
[0141] (2) X-axis projection: Perform X-axis projection on the sorted formula detection boxes and OCR detection boxes whose formula categories are embedded formulas, and generate a projection array that reflects the distribution of formula detection boxes and OCR detection boxes whose formula categories are embedded formulas;
[0142] (3) Segmentation point confirmation: find the point with a low projection height (e.g., 0) according to the projection array and regard it as a potential segmentation point;
[0143] (4) Segmentation decision: If the potential segmentation point is 1, it means that the formula detection box and OCR detection box of the formula category "embedded formula" cannot be segmented on the X-axis. If there are multiple segmentation points, the formula detection box and OCR detection box of the formula category "embedded formula" are further segmented according to each segmentation point.
[0144] 2. Internal sorting within a row: Perform internal sorting on the formula detection boxes and OCR detection boxes that are confirmed to be embedded formulas in the same row.
[0145] The specific in-row sorting algorithm is as follows: a starting box is specified in the row, and its maximum allowed intersection range on the X-axis is calculated to filter and sort the adjacent left and right formula detection boxes and OCR detection boxes whose formula categories are embedded formulas, and add them to the result list one by one, and use them as new starting boxes in turn, and cycle until no new formula detection boxes and OCR detection boxes whose formula categories are embedded formulas that meet the conditions can be found.
[0146] 3. Merge detection frames: Merge the formula detection frames and OCR detection frames whose formula categories are embedded formulas and are in the same row and have been correctly sorted. The merging methods include: merging text content in order, merging into one detection frame, etc.
[0147] Based on the above principles, Figure 4 As shown, the merging process of the present invention specifically includes:
[0148] 1. Add the formula recognition results to the text recognition results.
[0149] 2. Preliminarily determine whether the formula detection box and the OCR detection box of the formula category embedded formula are in the same row, so as to preliminarily filter out the detection boxes belonging to the same row. When the Y-axis intersection of the formula detection box and the OCR detection box of the formula category embedded formula is greater than the threshold value 0.5 and the X-axis intersection is less than the threshold value 0.5, it is preliminarily determined that the formula detection box and the OCR detection box of the formula category embedded formula are in the same row.
[0150] 3. Classify the preliminarily screened detection frames in combination with the layout analysis frame and its layout category, determine whether the preliminarily screened detection frames belong to the same layout category, and screen out the detection frames belonging to the same layout.
[0151] 4. Project the selected detection frames belonging to the same layout on the X-axis to determine the segmentation points. Judge whether the detection frames can be segmented on the X-axis according to the number of segmentation points. If they cannot be segmented, determine that the selected detection frames belonging to the same layout belong to the same industry detection frames. If they can be segmented, determine that the selected detection frames belonging to the same layout do not belong to the same industry detection frames.
[0152] 5. The determined detection boxes in the same row are sorted within the row and then merged. The output extraction result of the input text includes the merged row text detection box and the merged text content.
[0153] 9. For formulas between lines, determine whether the formula detection frame overlaps the corrected OCR detection frame to a large extent.
[0154] In the present invention, it is possible to determine whether the coordinates of the formula detection frame of the formula category being the interline formula and the coordinates of the corrected OCR detection frame are substantially overlapped, for example, whether the overlap rate is greater than 90%. If there is a substantial overlap, it means that the corrected OCR detection frame is an OCR detection frame of a pure interline formula; if there is a substantial overlap, it means that the corrected OCR detection frame is not an OCR detection frame of a pure interline formula, but an ordinary text OCR detection frame, and text recognition can be performed on it using a text recognition model.
[0155] 10. Identify formulas between lines.
[0156] In this step, the same method as in step six is used to perform formula recognition on the formula detection box whose formula category is an inter-row formula to obtain a formula recognition result.
[0157] 11. Text recognition.
[0158] In this step, the same method as in step seven is used to perform text recognition on the corrected OCR detection frame that substantially overlaps with the formula detection frame whose formula category is an interline formula, so as to obtain a text recognition result.
[0159] 12. Replacement.
[0160] The text recognition result obtained in step 11 is replaced with the formula recognition result obtained in step 10 to obtain an extraction result of the input text, where the extraction result of the input text is a text extraction result of the inter-line formula.
[0161] In addition, the present invention also relates to an intelligent extraction system for input text containing mathematical formulas. Figure 5 As shown, the intelligent extraction system of input text containing mathematical formulas of the present invention includes:
[0162] An input format determination and image preprocessing module, which is used to determine the format of the input text. If the format of the input text is not an image format, the input text is converted into an image format text and the image format text is preprocessed;
[0163] An automatic image correction module is used to perform text detection on the preprocessed image format text to obtain an OCR detection frame, determine whether to perform angle correction on the preprocessed image format text through the aspect ratio of the OCR detection frame and the text direction classifier, and perform angle correction when angle correction is required to obtain the corrected image format text and OCR detection frame;
[0164] A formula detection module, which is used to perform formula detection on the corrected text in the image format to obtain a formula detection frame and its formula category, wherein the formula category includes an embedded formula and an interline formula;
[0165] A layout analysis module, which is used to perform layout analysis on the text in the corrected picture format to obtain a layout analysis frame and its layout categories, wherein the layout categories include title, text, picture, figure annotation, table, table annotation, formula, header, footer and references;
[0166] An embedded formula text splitting module is used to determine whether the corrected OCR detection frame contains an embedded formula according to the formula detection frame and split the OCR detection frame containing the embedded formula to obtain an OCR detection frame of the plain text;
[0167] A formula recognition module is used to crop the text in the picture format according to the formula detection frame to obtain a formula area, use a formula recognition model to perform formula recognition on the formula area and simplify the format of the output LaTeX to obtain a formula recognition result;
[0168] A text recognition module is used to perform text recognition on the corrected OCR detection frame using the corresponding OCR recognition model according to different scenarios to obtain text recognition results;
[0169] The merging processing module is used to combine the layout analysis frame and its layout category to perform peer detection frame judgment and merge the formula recognition result and the text recognition result to obtain the extraction result of the input text.
[0170] The present invention provides an innovative solution for extracting input text containing mathematical formulas, and can accurately identify and process mathematical formulas in complex documents. It separates the nested formulas in the text from the ordinary text and uses the best model to identify them respectively, and then merges and restores them, solving the problem of nested output of formula text. Moreover, by identifying whether the recognized text is in the same line, through internal sorting and merging, the intelligent generation of coherent text lines is achieved, and the layout of the lines in the layout is considered, so that the text is accurately and orderly organized, which enhances the coherence and readability of the text processing results.
[0171] Finally, it should be noted that the above embodiments are only used to illustrate the technical solution of the present invention, rather than to limit the scope of protection of the present invention. Those skilled in the art can modify or replace the technical solution of the present invention according to the idea of the present invention without departing from the essence and scope of the technical solution of the present invention.
Claims
1. An intelligent extraction method for input text containing mathematical formulas, characterized in that: The following steps are involved: 1) Determine the format of the input text. If the format of the input text is not a picture format, convert the input text into a picture format text and pre-process the picture format text; 2) Performing text detection on the preprocessed text in the image format to obtain an OCR detection frame, determining whether to perform angle correction on the preprocessed text in the image format through the aspect ratio of the OCR detection frame and the text direction classifier, and performing angle correction when angle correction is required to obtain the corrected text in the image format and the OCR detection frame; 3) performing formula detection on the corrected text in the image format to obtain a formula detection frame and its formula category, wherein the formula category includes an embedded formula and an interline formula; 4) performing layout analysis on the corrected text in picture format to obtain a layout analysis frame and its layout categories, wherein the layout categories include title, text, picture, figure annotation, table, table annotation, formula, header, footer and references; 5) For the embedded formula, judging whether the corrected OCR detection frame contains the embedded formula according to the formula detection frame and splitting the OCR detection frame containing the embedded formula to obtain the OCR detection frame of the plain text; 6) cropping the text in the corrected picture format according to the formula detection frame to obtain a formula area, performing formula recognition on the formula area using a formula recognition model and simplifying the format of the output LaTeX to obtain a formula recognition result; 7) Use the corresponding OCR recognition model for different scenarios to perform text recognition on the OCR detection box of the plain text to obtain the text recognition result; 8) Combine the layout analysis frame and its layout category to determine and merge the formula recognition results and text recognition results in the same detection frame to obtain the extraction result of the input text.
2. The intelligent extraction method of input text containing mathematical formulas according to claim 1, characterized in that: Further including: 9) For the interline formula, determine whether the formula detection frame overlaps significantly with the corrected OCR detection frame. If so, proceed to step 10); 10) cropping the text in the corrected picture format according to the formula detection frame to obtain a formula area, using a formula recognition model to perform formula recognition on the formula area and simplifying the format of the output LaTeX to obtain a formula recognition result; 11) Using the corresponding OCR recognition model for different scenarios to perform text recognition on the corrected OCR detection frame to obtain text recognition results; 12) replacing the text recognition result with the formula recognition result to obtain an extraction result of the input text; The substantial overlap refers to an overlap rate exceeding 90%.
3. The intelligent extraction method of input text containing mathematical formulas according to claim 2 is characterized in that: The step 1) specifically includes: 1.1) Determine whether the input text is in PDF format or image format. If the input text is in PDF format, use a PDF parser to convert the input text into an image format. 1.2) The text in the image format is dynamically extended to match the background size, and the median filter algorithm is used to denoise the text in the image format.
4. The intelligent extraction method of input text containing mathematical formulas according to claim 3 is characterized in that: The step 2) specifically includes: 2.1) Input the preprocessed text in the image format into the OCR detection model for text detection to obtain the OCR detection box; 2.2) Calculate the aspect ratio of the OCR detection frame. If the proportion of OCR detection frames with a height greater than the width in all OCR detection frames exceeds a set threshold, the pre-processed image format text is rotated 90 degrees clockwise to obtain an updated image format text. Otherwise, the pre-processed image format text and OCR detection frame are directly output; 2.3) Inputting the updated text in the image format into the OCR detection model for text detection to obtain an updated OCR detection frame; 2.4) According to the updated OCR detection frame, the updated text in the picture format is cropped to obtain the OCR detection frame area and the OCR detection frame area is sent to the text direction classifier for direction determination. The output of the text direction classifier is 0 degrees or 180 degrees. If the proportion of the OCR detection frame area with an output of 180 degrees in the total OCR detection frame area is greater than the set threshold, the text in the updated picture format is rotated 180 degrees clockwise to obtain the text in the picture format that is updated again. Otherwise, the updated text in the picture format and the updated OCR detection frame are directly output; 2.5) Input the text in the updated image format into the OCR detection model for text detection to obtain the updated OCR detection frame, and output the text in the updated image format and the updated OCR detection frame.
5. The intelligent extraction method of input text containing mathematical formulas according to claim 4 is characterized in that: The step 5) specifically includes: 5.1) For each OCR detection box, obtain the corresponding first-order equations of the upper, lower, left and right boundary lines according to the coordinates of its upper left corner, lower left corner, upper right corner and lower right corner; 5.2) Filtering a formula detection frame whose formula category is an embedded formula from the formula detection frame, calculating the X-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula and substituting it into a linear equation of the upper and lower boundary lines of the OCR detection frame to determine whether the Y-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula is within the Y value interval of the upper and lower boundary lines of the OCR detection frame, calculating the Y-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula and substituting it into a linear equation of the left and right boundary lines of the OCR detection frame to determine whether the X-axis coordinate of the center point of the formula detection frame whose formula category is an embedded formula is within the X value interval of the left and right boundary lines of the OCR detection frame; 5.3) If the Y-axis coordinate of the center point of the formula detection box with the formula category of embedded formula is within the Y value interval of the upper and lower boundary lines of the OCR detection box, and the X-axis coordinate of the center point of the formula detection box with the formula category of embedded formula is within the X value interval of the left and right boundary lines of the OCR detection box, calculate the ratio of the overlapping area of the OCR detection box and the formula detection box with the formula category of embedded formula to the total area of the two, that is, IoU; 5.4) If the IoU is greater than 0, the formula detection box with the formula category as embedded formula is added to the formula list, and the OCR detection box is split.
6. The intelligent extraction method of input text containing mathematical formulas according to claim 5, characterized in that: The step 6) is specifically as follows: 6.1) Crop the text in the corrected image format according to the coordinates of the formula detection box to obtain the formula area and send the formula area to the formula recognition model, and the output result is LaTeX; 6.2) Send the output LaTeX to the rendering engine for rendering judgment. If the rendering fails, the format is repaired. If the rendering still fails after the format is repaired, an additional error message is output to prevent the output of incorrect formulas; 6.3) Simplify LaTeX and remove unnecessary formats. The final output includes the formula detection box, formula category and formula LaTeX.
7. The intelligent extraction method of input text containing mathematical formulas according to claim 6, characterized in that: The step 7) is specifically as follows: 7.1) Crop the text in the rectified image format according to the split plain text OCR detection frame to obtain the OCR detection frame area; 7.2) Send the OCR detection box area to the Chinese OCR recognition model for preliminary text recognition to obtain preliminary text recognition results; 7.3) If the preliminary text recognition result only contains English or numbers, the OCR detection box area is sent to the English OCR recognition model for recognition to obtain the final text recognition result and overwrite the preliminary text recognition result. The final output result includes the OCR detection box and the text recognition result.
8. The intelligent extraction method of input text containing mathematical formulas according to claim 7, characterized in that: The step 8) specifically includes: 8.1) Add the formula recognition results to the text recognition results; 8.2) Preliminarily determine whether the formula detection box and the OCR detection box are in the same row, so as to preliminarily filter out the detection boxes belonging to the same row; 8.3) Classifying the preliminarily screened detection frames according to the layout analysis frame and its layout category, and determining whether the preliminarily screened detection frames belong to the same layout category, so as to screen out the detection frames belonging to the same layout; 8.4) Project the selected detection frames belonging to the same layout on the X-axis to determine the segmentation points, and judge whether the detection frame can be segmented on the X-axis according to the number of segmentation points. If it cannot be segmented, it is determined that the selected detection frames belonging to the same layout belong to the same line detection frame; if it can be segmented, it is determined that the selected detection frames belonging to the same layout do not belong to the same line detection frame; 8.5) The determined detection boxes in the same row are sorted within the row and then merged. The output extraction result of the input text includes the merged row text detection box and the merged text content.
9. The intelligent extraction method of input text according to claim 8, characterized in that: In the step 8.2), when the Y-axis intersection of the formula detection frame and the OCR detection frame is greater than the threshold and the X-axis intersection is less than the threshold, it is preliminarily determined that the formula detection frame and the OCR detection frame are in the same row.
10. An intelligent extraction system for input text containing mathematical formulas, characterized in that: include: An input format determination and image preprocessing module, which is used to determine the format of the input text. If the format of the input text is not an image format, the input text is converted into an image format text and the image format text is preprocessed; An automatic image correction module is used to perform text detection on the preprocessed image format text to obtain an OCR detection frame, determine whether to perform angle correction on the preprocessed image format text through the aspect ratio of the OCR detection frame and the text direction classifier, and perform angle correction when angle correction is required to obtain the corrected image format text and OCR detection frame; A formula detection module, which is used to perform formula detection on the corrected text in the image format to obtain a formula detection frame and its formula category, wherein the formula category includes an embedded formula and an interline formula; A layout analysis module, which is used to perform layout analysis on the text in the corrected picture format to obtain a layout analysis frame and its layout categories, wherein the layout categories include title, text, picture, figure annotation, table, table annotation, formula, header, footer and references; An embedded formula text splitting module is used to determine whether the corrected OCR detection frame contains an embedded formula according to the formula detection frame and split the OCR detection frame containing the embedded formula to obtain an OCR detection frame of the plain text; A formula recognition module is used to crop the text in the picture format according to the formula detection frame to obtain a formula area, use a formula recognition model to perform formula recognition on the formula area and simplify the format of the output LaTeX to obtain a formula recognition result; A text recognition module is used to perform text recognition on the corrected OCR detection frame using the corresponding OCR recognition model according to different scenarios to obtain text recognition results; The merging processing module is used to combine the layout analysis frame and its layout category to perform peer detection frame judgment and merge the formula recognition result and the text recognition result to obtain the extraction result of the input text.
