Method and related device for merging and dividing of OCR document recognition results

By recognizing text boxes using an OCR model and determining the order of the text set using a language model and a depth-first search algorithm, the problem of poor readability of OCR recognition results is solved, and the consistency of text recognition results and the quality of typesetting are improved.

CN117115822BActive Publication Date: 2026-05-01WUHAN WANWUYUN DIGITAL OPERATION CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
WUHAN WANWUYUN DIGITAL OPERATION CO LTD
Filing Date
2023-08-29
Publication Date
2026-05-01

AI Technical Summary

Technical Problem

Existing OCR technology produces results with poor readability because it ignores the connections between texts and layout rules.

Method used

The text boxes are identified and their positional information is obtained by using an OCR model. The probability of the preceding and following sentences of the text box is calculated using a pre-trained language model. A directed graph is constructed by combining the minimum distance. A depth-first search algorithm is used to determine the order of the text set. The text sets are then merged according to the probability threshold to obtain the final text recognition result.

Benefits of technology

It improves the coherence and readability of text recognition results, reduces human intervention, and saves time and manpower costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117115822B_ABST
    Figure CN117115822B_ABST
Patent Text Reader

Abstract

The application discloses a merging and dividing method for an OCR document recognition result and related devices. The method obtains the text box and the position information corresponding to the text box of the document through an OCR model, then calculates the order and the minimum distance between the text boxes; takes the text box as a node, constructs the directional edge between the nodes according to the order and the minimum distance of the text box, and obtains a directed graph; traverses the directed graph by using a depth-first search algorithm to obtain a plurality of text sets, determines the order between the text sets according to the order of the text box, and obtains a set order; according to the set order, calculates the probability that the two adjacent text sets belong to a sentence above and below, and judges whether the calculation result is greater than a preset probability threshold; if yes, the corresponding two text sets are merged according to the set order to obtain a final text recognition result. Compared with the prior art, the application greatly improves the readability of the text recognition content, and saves time and labor cost.
Need to check novelty before this filing date? Find Prior Art

Description

Methods and related devices for merging and segmenting OCR document recognition results Technical Field

[0001] The embodiments of the present invention relate to the field of OCR recognition technology, and in particular to a method and related apparatus for merging and dividing OCR document recognition results. Background Technology

[0002] Optical Character Recognition (OCR) is a computer-based conversion of text images into digital form, which is machine-editable text, using standard encoding schemes. This process eliminates the need to manually type documents into computer systems. This technology has been widely applied in many fields, such as document digitization, automated data entry, and image search. Traditional OCR techniques typically employ deep learning methods based on object detection and variable-length sequence classification to recognize characters in images as text. The text recognized in this way is usually character-level or sentence-level, ignoring the connections between text and the rules of formatting, resulting in disjointed sentences and poor readability. Summary of the Invention

[0003] This invention provides a method and related apparatus for merging and dividing OCR document recognition results, aiming to solve the technical problem of poor readability of OCR document recognition results in the prior art.

[0004] In a first aspect, embodiments of the present invention provide a method for merging and dividing OCR document recognition results, comprising:

[0005] The document image to be recognized is input into a pre-trained OCR model for recognition, resulting in several text boxes and their corresponding position information.

[0006] The probability of any two text boxes belonging to the preceding and following sentences is calculated based on the pre-trained language model, and the order of the text boxes is determined according to the preceding and following sentence probabilities.

[0007] Based on the location information, the minimum distance between any two text boxes is calculated to obtain the minimum distance between any two text boxes;

[0008] Using the text boxes as nodes, directional edges are constructed between nodes according to the order of the text boxes and the minimum distance to obtain a directed graph; the directed graph is traversed using a depth-first search algorithm to obtain several text sets, and the order between the text sets is determined according to the order of the text boxes to obtain the set order, wherein the text set includes several nodes;

[0009] Based on the order of the sets, calculate the probability that two adjacent text sets belong to the next sentence, and determine whether the calculation result is greater than a preset probability threshold.

[0010] If so, the two corresponding text sets are merged according to the order of the sets to obtain the final text recognition result.

[0011] Secondly, embodiments of the present invention provide a device for merging and dividing OCR document recognition results, comprising:

[0012] The recognition module is used to input the document image to be recognized into the pre-trained OCR model for recognition, and obtain several text boxes and the position information corresponding to the text boxes;

[0013] The sequence calculation module is used to calculate the probability that any two text boxes belong to the next sentence based on the pre-trained language model, and determine the order of the text boxes based on the calculation result.

[0014] The distance calculation module is used to calculate the minimum distance between any two text boxes based on the location information, so as to obtain the minimum distance between any two text boxes;

[0015] The set order calculation module is used to construct directional edges between nodes based on the text boxes as nodes, according to the order of the text boxes and the minimum distance, to obtain a directed graph; the directed graph is traversed using a depth-first search algorithm to obtain several text sets, and the order between the text sets is determined according to the order of the text boxes to obtain the set order, wherein the text set includes several nodes;

[0016] The judgment module is used to calculate the probability that two adjacent text sets belong to the next sentence according to the order of the set, and to determine whether the calculation result is greater than a preset probability threshold.

[0017] The merging module is used to merge the two corresponding text sets according to the set order if the calculation result is greater than a preset probability threshold, and to retain the order of the two text sets to obtain the final text recognition result.

[0018] Thirdly, embodiments of the present invention provide a computer device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the merging and segmentation method for OCR document recognition results described in the first aspect.

[0019] Fourthly, embodiments of the present invention also provide a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, which, when executed by a processor, causes the processor to perform the merging and segmentation method for OCR document recognition results described in the first aspect.

[0020] This invention provides a method and related apparatus for merging and segmenting OCR document recognition results. The method obtains text boxes and their corresponding positional information from an OCR model, then calculates the order and minimum distance between text boxes. Using text boxes as nodes, directional edges are constructed between nodes based on their order and minimum distance, resulting in a directed graph. A depth-first search algorithm is used to traverse the directed graph, obtaining several text sets. The order between these text sets is determined based on the order of the text boxes, resulting in a set order. Based on the set order, the probability that two adjacent text sets belong to the same sentence is calculated, and the result is checked against a preset probability threshold. If the probability is greater than a threshold, the corresponding two text sets are merged according to the set order to obtain the final text recognition result. This method, based on OCR model document recognition, sorts and merges the recognized text boxes, making the text box sorting more accurate and fluent, and the content of the text recognition result more coherent, greatly improving the readability of the recognized text content and saving time and labor costs. Attached Figure Description

[0021] To more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the following description of the embodiments will be briefly introduced. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0022] Figure 1 is a flowchart illustrating an embodiment of the method for merging and dividing OCR document recognition results provided by this invention.

[0023] Figure 2 is a schematic diagram of the minimum distance calculation in the merging and segmentation method for OCR document recognition results provided in the embodiment of the present invention;

[0024] Figure 3 is a schematic diagram of nodes in the merging and segmentation method for OCR document recognition results provided in an embodiment of the present invention;

[0025] Figure 4 is a schematic diagram of a directed graph in the merging and partitioning method for OCR document recognition results provided in an embodiment of the present invention;

[0026] Figure 5 is a schematic diagram of the text box in the merging and segmentation method for OCR document recognition results provided in an embodiment of the present invention;

[0027] Figure 6 is a schematic diagram of the text recognition results obtained by the traditional method;

[0028] Figure 7 is a schematic diagram of the text recognition result of the merging and segmentation method for OCR document recognition results provided in the embodiment of the present invention;

[0029] Figure 8 is a schematic block diagram of a device for merging and dividing OCR document recognition results provided in an embodiment of the present invention. Detailed Implementation

[0030] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some, not all, of the embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0031] It should be understood that, when used in this specification and the appended claims, the terms "comprising" and "including" indicate the presence of the described features, integrals, steps, operations, elements and / or components, but do not exclude the presence or addition of one or more other features, integrals, steps, operations, elements, components and / or collections thereof.

[0032] It should also be understood that the terminology used in this specification is for the purpose of describing particular embodiments only and is not intended to limit the invention. As used in this specification and the appended claims, the singular forms “a,” “an,” and “the” are intended to include the plural forms unless the context clearly indicates otherwise.

[0033] It should also be further understood that the term "and / or" as used in this specification and the appended claims refers to any combination of one or more of the associated listed items and all possible combinations, and includes such combinations.

[0034] Please refer to Figure 1, which is a flowchart of a method for merging and dividing OCR document recognition results provided in an embodiment of the present invention. The method includes steps S110 to S160.

[0035] Step S110: Input the document image to be recognized into the pre-trained OCR model for recognition, and obtain several text boxes and the position information corresponding to the text boxes;

[0036] In this embodiment, the OCR model is pre-trained to output the text boxes and their corresponding position information of the document image, resulting in a trained OCR model. The document image to be recognized is then input into the trained OCR model for document recognition, yielding the text boxes and their corresponding position information within the document image. The position information [x,y,w,h] includes the coordinates (x,y) of the top-left point of the text box, the width w of the text box, and the height h of the text box.

[0037] Step S120: Calculate the probability that any two text boxes belong to the preceding and following sentences based on the pre-trained language model, obtain the preceding and following sentence probabilities, and determine the order of the text boxes according to the preceding and following sentence probabilities;

[0038] In this embodiment, to determine the order between text boxes, it is necessary to calculate the probability that any two text boxes belong to adjacent sentences. The calculated probability determines whether two text boxes are adjacent sentences. Here, adjacent sentences refer to any two text boxes (such as text box A and text box B) having a sequential word order relationship; that is, in a sentence, text box A precedes text box B. Specifically, the probability that any two text boxes belong to adjacent sentences is calculated using a pre-trained language model.

[0039] In one embodiment, the language model can be a BERT model. The BERT model is a Transformer-based language model that is trained using unsupervised learning on large-scale text data and then fine-tuned in various downstream tasks. The probability of any two text boxes belonging to adjacent sentences is calculated using the BERT model. Specifically, this involves: extracting sentence vectors from any two text boxes using the BERT model to obtain a first sentence vector and a second sentence vector; concatenating the first and second sentence vectors; inputting the concatenated result into the classification layer of the BERT model; and using the softmax function to calculate the probability that the first and second sentence vectors belong to adjacent sentences, thus obtaining the probability of adjacent sentences. The probability p of the first and second sentence vectors belonging to adjacent sentences is calculated using the following formula:

[0040] p = softmax(W T X),

[0041] In the formula, X represents the concatenation result of the first and second sentence vectors, softmax() represents the softmax function, and W... T This represents the transpose of the weight matrix W.

[0042] In one embodiment, the language model can be the Kenlm language model. The Kenlm language model calculates the probability that any two text boxes belong to adjacent sentences. Specifically, the process includes: segmenting any two text boxes using Jieba segmentation to obtain corresponding segmentation results; using the first segmentation result of one text box as the first segmentation result and the last segmentation result of the other text box as the second segmentation result, merging the first and second segmentation results to obtain a merged segmentation result; calculating the confusion level of the merged segmentation result using the Kenlm language model, and using the confusion level result as the probability of adjacent sentences. Jieba segmentation is a segmentation component that can perform word segmentation, part-of-speech tagging, and keyword extraction on Chinese text.

[0043] Step S130: Calculate the minimum distance between any two text boxes based on the location information to obtain the minimum distance between any two text boxes;

[0044] In this embodiment, based on the position information of the text boxes, the minimum distance between the two text boxes is calculated using the distance between the two nearest edges. For example, as shown in Figure 2, for text boxes b1 = [x1, y1, w1, h1], b2 = [x2, y2, w2, h2], and b3 = [x3, y3, w3, h3], where (x1, y1) is the origin of the coordinate system, the minimum distance between text boxes b1 and b2 is d. 12 =y2-(y1+h1), the minimum distance between text boxes b2 and b3 is d. 23 = x3 - (x2 + w2).

[0045] Step S140: Using the text boxes as nodes, construct directional edges between nodes according to the order of the text boxes and the minimum distance to obtain a directed graph; use a depth-first search algorithm to traverse the directed graph to obtain several text sets, and determine the order between the text sets according to the order of the text boxes to obtain the set order;

[0046] In this embodiment, according to the construction rules of the directed graph, as shown in Figure 3, text boxes are used as nodes. Directional edges between nodes are constructed based on the order of the text boxes and the minimum distance, resulting in a directed graph, as shown in Figure 4, with directional edges 1-4, 4-9, and 3-2, etc. Specifically, if the minimum distance between any two text boxes is less than a preset threshold, a directional edge is established between their corresponding nodes, starting with the text box that appears earlier in the sequence and ending with the text box that appears later. Then, a depth-first search algorithm is used to traverse the directed graph, obtaining several sets of text represented by nodes. Finally, the order of all text sets is determined based on the order of the text boxes, resulting in the set order. It should be noted that if the minimum distance between any two text boxes is greater than the preset threshold, no directional edge is established between the corresponding two nodes.

[0047] For example, as shown in Figure 4, text set S1 contains node 1, node 4, node 9 and node 8, text set S2 contains node 3, node 2 and node 6, and text set S3 contains node 5.

[0048] Furthermore, determining the order of text sets based on the order of text boxes specifically includes: obtaining any two text sets, using the last node of one text set as the first text box, and the first node of the other text set as the second text box; determining the text box order between the first and second text boxes based on the order of the text boxes, and determining the set order between the corresponding two text sets based on the text box order between the first and second text boxes. For example, text set S1 contains nodes 1, 4, 9, and 8, and text set S2 contains nodes 3, 2, and 6. Specifically, using the last node (node ​​8) in text set S1 as the first text box and the first node (node ​​3) in text set S2 as the second text box, and determining whether nodes 8 and 3 are consecutive sentences according to the order of all text boxes determined in step S120. If nodes 8 and 3 are paired sentences, then text sets S1 and S2 are also paired sentences, with text set S1 preceding text set S2. If nodes 8 and 3 are not paired sentences, then text sets S1 and S2 are also not paired sentences. In this case, the order can be reversed to determine whether text set S2 precedes text set S1. The first node (node ​​6) in text set S2 is taken as the first text box, and the last node (node ​​1) in text set S1 is taken as the second text box. According to the order among all text boxes determined in step S120, it is determined whether nodes 6 and 1 are paired sentences. If nodes 6 and 1 are paired sentences, then text sets S2 and S1 are also paired sentences, with text set S2 preceding text set S1. If nodes 6 and 1 are not paired sentences, then text sets S1 and S2 are also not paired sentences.

[0049] Step S150: Calculate the probability that two adjacent text sets belong to the next sentence according to the set order, and determine whether the calculation result is greater than the preset probability threshold.

[0050] Step S160: If yes, then merge the two corresponding text sets according to the set order to obtain the final text recognition result.

[0051] In this embodiment, after determining the order of the text sets, to improve readability, it is determined whether two adjacent text sets can be merged. The specific method includes: calculating the probability that two adjacent text sets belong to the same sentence; determining whether the calculated result is greater than a preset probability threshold; if the probability that two adjacent text sets belong to the same sentence is greater than the preset probability threshold, then the corresponding two text sets are merged according to the set order to obtain the final text recognition result. The process of calculating the probability that two adjacent text sets belong to the same sentence is similar to calculating the probability that two text boxes belong to the same sentence in step S120, and will not be described again here.

[0052] For example, as shown in Figures 5 to 7, after OCR recognition and processing of the document image, a text box as shown in Figure 5 is obtained. Based on the text box in Figure 5, the text recognition result output by the traditional method is shown in Figure 6. Following the steps above in this method, based on the text box in Figure 5, the order and minimum distance of the text boxes are calculated. Then, a directed graph is constructed to obtain the corresponding text set, and the set order of all text sets is determined. Finally, the probability that two adjacent text sets belong to the preceding and following sentences is calculated. If the probability that two adjacent text sets belong to the preceding and following sentences is greater than a preset probability threshold, the corresponding two text sets are merged according to the set order to obtain the text recognition result shown in Figure 7.

[0053] This method obtains text boxes and their corresponding positional information from a document using an OCR model. It then calculates the order and minimum distance between text boxes. Using text boxes as nodes, it constructs directional edges between nodes based on their order and minimum distance, resulting in a directed graph. A depth-first search algorithm is used to traverse the directed graph, obtaining several text sets. The order of these text sets is determined based on the order of the text boxes, resulting in a set order. Based on the set order, the probability that two adjacent text sets belong to the same sentence is calculated, and the result is checked against a preset probability threshold. If the probability is greater than a threshold, the two corresponding text sets are merged according to the set order to obtain the final text recognition result. This method, based on OCR model document recognition, sorts and merges the recognized text boxes, making the text box order more coherent and improving layout quality. It reduces the need for manual intervention and significantly improves processing efficiency. Compared to traditional OCR systems, it can quickly and accurately complete text box sorting and layout, saving time and labor costs.

[0054] This invention also provides a device for merging and dividing OCR document recognition results. This device is used to execute any of the aforementioned methods for merging and dividing OCR document recognition results. Specifically, please refer to FIG8, which is a schematic block diagram of the device for merging and dividing OCR document recognition results provided in this invention.

[0055] As shown in Figure 8, the device 100 for merging and dividing OCR document recognition results includes a recognition module 110, a sequence calculation module 120, a distance calculation module 130, a set sequence calculation module 140, a judgment module 150, and a merging module 160.

[0056] The recognition module 110 is used to input the document image to be recognized into a pre-trained OCR model for recognition, and obtain several text boxes and the position information corresponding to the text boxes.

[0057] The sequence calculation module 120 is used to calculate the probability that any two text boxes belong to the next sentence based on the pre-trained language model, and determine the order of the text boxes according to the calculation result.

[0058] The distance calculation module 130 is used to calculate the minimum distance between any two text boxes based on the location information, so as to obtain the minimum distance between any two text boxes.

[0059] The set order calculation module 140 is used to construct directional edges between nodes based on the order of the text boxes and the minimum distance, using the text boxes as nodes, to obtain a directed graph; to traverse the directed graph using a depth-first search algorithm to obtain several text sets, and to determine the order between the text sets based on the order of the text boxes, to obtain the set order, wherein the text set includes several nodes;

[0060] The judgment module 150 is used to calculate the probability that two adjacent text sets belong to the next sentence according to the order of the set, and to determine whether the calculation result is greater than a preset probability threshold.

[0061] The merging module 160 is used to merge the two corresponding text sets according to the set order if the calculation result is greater than the preset probability threshold, and retain the order of the two text sets to obtain the final text recognition result.

[0062] In one embodiment, the sequential calculation module 120 includes:

[0063] The extraction unit is used to extract sentence vectors from any two text boxes using the Bert model to obtain the first sentence vector and the second sentence vector.

[0064] The first calculation unit is used to concatenate the first sentence vector and the second sentence vector, input the concatenation result into the classification layer of the BERT model, and use the softmax function to calculate the probability that the first sentence vector and the second sentence vector belong to the preceding and following sentences to obtain the preceding and following sentence probabilities.

[0065] In one embodiment, the sequential calculation module 120 includes:

[0066] The word segmentation unit is used to segment any two text boxes using Jieba word segmentation to obtain the corresponding word segmentation results;

[0067] The merging unit is used to take the first word segmentation result of one text box as the first word segmentation result and the last word segmentation result of the other text box as the second word segmentation result, and merge the first word segmentation result and the second word segmentation result to obtain the merged word segmentation result.

[0068] The second calculation unit is used to calculate the confusion degree of the merged word segmentation result through the Kenlm language model, and use the confusion degree calculation result as the probability of the next and next sentences.

[0069] In one embodiment, the set order calculation module 140 includes:

[0070] The distance judgment unit is used to determine whether the minimum distance between any two text boxes is less than a preset threshold.

[0071] The directional edge construction unit is used to establish directional edges between corresponding nodes according to the order of the text boxes, starting from the text box that appears earlier in the sequence and ending with the text box that appears later in the sequence, if the minimum distance between any two text boxes is less than a preset threshold, thereby obtaining the directed graph.

[0072] In one embodiment, the set order calculation module 140 further includes:

[0073] The acquisition unit is used to acquire any two text sets, with the last node of one text set as the first text box and the first node of the other text set as the second text box;

[0074] The sequence determination unit is used to determine the order of the text boxes between the first text box and the second text box according to the order of the text boxes, and to determine the order of the set based on the order of the text boxes between the first text box and the second text box.

[0075] This invention also provides a computer device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor executes the computer program to implement the merging and segmentation method for OCR document recognition results as described above.

[0076] In another embodiment of the invention, a computer-readable storage medium is provided. This computer-readable storage medium may be a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the merging and segmentation method for OCR document recognition results as described above.

[0077] Those skilled in the art will readily understand that, for the sake of convenience and brevity, the specific working processes of the devices, apparatuses, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this invention.

[0078] In the embodiments provided by this invention, it should be understood that the disclosed devices, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative. For instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. Units with the same function may be grouped into one unit. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. In addition, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection through some interfaces, devices, or units, or it may be an electrical, mechanical, or other form of connection.

[0079] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of the embodiments of the present invention, depending on actual needs.

[0080] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0081] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), magnetic disks, or optical disks.

[0082] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in the present invention, and these modifications or substitutions should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A method for merging and dividing OCR document recognition results, characterized in that, include: The document image to be recognized is input into a pre-trained OCR model for recognition, resulting in several text boxes and their corresponding position information. The probability of any two text boxes belonging to a preceding and following sentence is calculated based on a pre-trained language model, and the order of the text boxes is determined according to the preceding and following sentence probabilities. The minimum distance between any two text boxes is calculated based on the positional information. Using the text boxes as nodes, directional edges are constructed between the nodes according to the order of the text boxes and the minimum distance, resulting in a directed graph. A depth-first search algorithm is used to traverse the directed graph, obtaining several text sets. The order of the text sets is determined according to the order of the text boxes, resulting in a set order. Based on the set order, the probability of two adjacent text sets belonging to a preceding and following sentence is calculated, and it is determined whether the calculated result is greater than a preset probability threshold. If so, the corresponding two text sets are merged according to the set order to obtain the final text recognition result. The step of constructing directional edges between nodes based on the order and minimum distance of the text boxes to obtain a directed graph includes: determining whether the minimum distance between any two text boxes is less than a preset threshold. If so, then according to the order of the text boxes, starting from the text box that appears earlier in the sequence and ending at the text box that appears later in the sequence, directional edges are established between the corresponding nodes to obtain the directed graph.

2. The method for merging and dividing OCR document recognition results according to claim 1, characterized in that, The language model is a BERT model. The pre-trained language model calculates the probability that any two text boxes belong to adjacent sentences to obtain the adjacent sentence probability. This includes: extracting sentence vectors from any two text boxes using the BERT model to obtain a first sentence vector and a second sentence vector; concatenating the first sentence vector and the second sentence vector; inputting the concatenation result into the classification layer of the BERT model; and using the softmax function to calculate the probability that the first sentence vector and the second sentence vector belong to adjacent sentences to obtain the adjacent sentence probability.

3. The method for merging and dividing OCR document recognition results according to claim 2, characterized in that, The calculation of the probability that the first sentence vector and the second sentence vector belong to the preceding and following sentences using the softmax function includes: calculating the probability p that the first sentence vector and the second sentence vector belong to the preceding and following sentences according to the following formula: p = softmax(W T X), where X represents the concatenation result of the first and second sentence vectors, softmax() represents the softmax function, and W T This represents the transpose of the weight matrix W.

4. The method for merging and dividing OCR document recognition results according to claim 1, characterized in that, The position information of the text box includes the coordinates of the top left corner of the text box, the width of the text box, and the height of the text box.

5. The method for merging and dividing OCR document recognition results according to claim 1, characterized in that, The language model is the Kenlm language model. The pre-trained language model calculates the probability that any two text boxes belong to adjacent sentences, including: segmenting any two text boxes using Jieba segmentation to obtain corresponding segmentation results; taking the first segmentation result of one text box as the first segmentation result and the last segmentation result of the other text box as the second segmentation result, merging the first and second segmentation results to obtain a merged segmentation result; calculating the confusion degree of the merged segmentation result using the Kenlm language model, and using the confusion degree calculation result as the probability of adjacent sentences.

6. The method for merging and dividing OCR document recognition results according to claim 1, characterized in that, The step of determining the order between the text sets based on the order of the text boxes to obtain the set order includes: obtaining any two text sets, taking the last node of one text set as the first text box, and taking the first node of the other text set as the second text box; determining the text box order between the first text box and the second text box based on the order of the text boxes, and determining the set order based on the text box order between the first text box and the second text box.

7. A device for merging and segmenting OCR document recognition results, characterized in that, include: The recognition module is used to input the document image to be recognized into the pre-trained OCR model for recognition, and obtain several text boxes and the position information corresponding to the text boxes; The sequence calculation module is used to calculate the probability that any two text boxes belong to the next sentence based on the pre-trained language model, and determine the order of the text boxes based on the calculation result. The system includes a distance calculation module, which calculates the minimum distance between any two text boxes based on the location information; a set order calculation module, which constructs directional edges between the text boxes as nodes, based on their order and minimum distance, to obtain a directed graph; a depth-first search algorithm is used to traverse the directed graph to obtain several text sets, and the order between the text sets is determined based on the order of the text boxes, thus obtaining a set order; a judgment module, which calculates the probability that two adjacent text sets belong to the same sentence based on the set order, and determines whether the calculation result is greater than a preset probability threshold; and a merging module, which merges the corresponding two text sets according to the set order if the calculation result is greater than the preset probability threshold, while retaining the order of the two text sets, to obtain the final text recognition result. The set order calculation module includes: a distance judgment unit, used to determine whether the minimum distance between any two text boxes is less than a preset threshold; The directional edge construction unit is used to establish directional edges between corresponding nodes according to the order of the text boxes, starting from the text box that appears earlier in the sequence and ending with the text box that appears later in the sequence, if the minimum distance between any two text boxes is less than a preset threshold, thereby obtaining the directed graph.

8. A computer device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the merging and segmentation method for OCR document recognition results as described in any one of claims 1 to 6.

9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, causes the processor to perform the merging and segmentation method for OCR document recognition results as described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Text merging method and device, equipment and storage medium

    CN114219876A

  • Label extraction method and device, storage medium and electronic equipment

    CN114461748A