A method for generating OCR training data for general tables

Generate complete, accurate and diverse table OCR training data through corpus splitting and post-processing techniques, solving the problems of incomplete and inaccurate data sets in the existing technology, reducing the dependence of manual annotation, and building a good OCR training dataset.

CN115205871BActive Publication Date: 2024-11-19NANJING RUNHE RUNYUN TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202210814223.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-07-11
Publication Date
2024-11-19
Estimated Expiration
2042-07-11

AI Technical Summary

Technical Problem

The existing data set acquisition methods for table detection have problems such as incomplete data, inaccuracy and lack of diversity, especially in electronic documents, the tables are too regular and the manpower labeling is not reliable enough.

Method used

The text in the table is generated through corpus splitting, plain text representation is constructed, transcribed into a picture table, and multiple post-processing is performed to simulate real scenes to generate OCR training data with completeness, accuracy and diversity.

Benefits of technology

A general tabular OCR training data generation method is provided to ensure the completeness, accuracy and diversity of the data set, reduce the dependence of manual annotation, and lay a solid foundation for building good OCR training data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115205871B_ABST
    Figure CN115205871B_ABST
Patent Text Reader

Abstract

The present invention discloses a method for generating OCR training data for a general table. Corpus splitting is performed through corpora in various fields to generate text in the table, including key type, value type, and long text type; a plain text representation of the table is formed by using random table element types and text in the table, that is, a string table is generated; the string table is transcribed onto a blank picture, and a table picture and position information of annotated text and cells are generated at the same time, that is, a picture table is generated; post-processing of the table image is performed, and the generated table picture and position information are changed through a variety of post-processors to simulate the effect of a real scene. The present invention can ensure the completeness, accuracy, and diversity of the data set for table detection, and lay a solid foundation for building good general table OCR training data.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of optical character recognition, and in particular to a method for generating OCR training data for a general form. Background Art

[0002] At present, in any application that needs to extract the table content in the image, a table detection model is generally used to perform table detection, and subsequent text recognition and table reconstruction are performed based on the table detection results. Among them, the table detection model is trained by a large number of data sets. Generally speaking, the data set for table detection is directly extracted from the electronic document or a large amount of manpower is used to annotate the table image. There are at least the following problems in the prior art: the existing method for obtaining the data set for table detection, the table in the electronic document is too regular, and the manually annotated table does not guarantee the complete correctness of the annotated data, that is, the completeness, accuracy and diversity of the data cannot be guaranteed.

[0003] In view of this, the present invention provides a method for generating OCR training data for a general table, which can ensure the completeness, accuracy and diversity of the data set for table detection. Summary of the invention

[0004] In order to solve the deficiencies in the prior art, the present invention aims to provide a method for generating OCR training data for a general table.

[0005] To achieve the purpose of the present invention, the technical solution adopted by the present invention is:

[0006] A method for generating OCR training data for a general table, comprising the steps of:

[0007] S1: Split the corpus through the corpus of each field to generate text in the table, including key type, value type, and long text type;

[0008] S2: Use random table metatypes and table text to construct a plain text representation of the table, i.e. generate a string table;

[0009] S3: transcribe the string table to a blank image, and generate a table image and the position information of the annotated text and cells, that is, generate an image table;

[0010] S4: Post-processing the table image, changing the generated table image and position information through a variety of post-processors to simulate the effect of a real scene.

[0011] Furthermore, in step S1, the specific steps of corpus splitting are as follows:

[0012] S11: Read the corpus of each field and initialize the key set, value set, and long text set to be empty;

[0013] S12: Traverse all the strings in the corpus and split them into lines to get a list of sentences;

[0014] S13: traverse the sentence list, if the sentence length is greater than the threshold, add it to the long text set; and split the sentence into words and add them to the word list;

[0015] S14: Remove stop words from the word list, and count the number of occurrences and part of speech of each word; put high-frequency content words into the key set, and put the remaining words into the value set;

[0016] S15: After the corpus is split, the key set, value set and long text set of each field are obtained.

[0017] Furthermore, in step S2, there are multiple table element types, including single-line text type T1, multi-line text type T2, single key-value pair type T3, multiple key-value pair type T4, single-key multiple option type T5, multi-row and multi-column type T6, cross-row and cross-column type T7, and multi-level header type T8.

[0018] Furthermore, the method for generating each type of string table is as follows:

[0019] S21: T1 type subroutine

[0020] S211: Take the character string text and calculate the length to be L;

[0021] S212: Set the left and right default margins (i.e., the number of padding spaces) to lpad=1, rpad=1;

[0022] S213: The left and right boundary characters are ║, the upper and lower boundary characters are ═, and the upper left boundary character is The upper right delimiter is The lower right delimiter is The lower left delimiter is

[0023] S213: Get the multi-line string representation of the table of type T1: The first line is The second line is ║+”+text+”+║; the third line is

[0024] S22: T2 type subroutine

[0025] S221: Take multiple character strings text_list and calculate the maximum length to be Lmax;

[0026] S222: Get the multi-line string representation of the table of type T2 as follows: The first line The last act

[0027] S223: For each line of text in the middle of text_list, its length is Li, and its string is represented by ║+”+text+''×(Lmax-Li+1)+║;

[0028] S224: connect S222 and S223 in sequence to obtain a table string representation of type T2;

[0029] S23: T3 type subroutine

[0030] S231: Take out the key string key from the key set and generate key_cell using S21;

[0031] S232: Take out the value type string value from the value set, and generate value_cell using S21;

[0032] S233: merge key_cell and value_cell into a T3-type table string representation through a horizontal merge subroutine;

[0033] S24: T4 type subroutine

[0034] S241: Take the number of key-value pairs as N;

[0035] S242: repeat S23 N times to obtain N T3-type table character string representations;

[0036] S242: merging N T3-type character strings into a T4-type character string representation through a horizontal merging subroutine;

[0037] S25: T5 type subroutine

[0038] S251: Take out the key string key from the key set and generate key_cell using S21;

[0039] S252: Get the value string value from the value set, add a checkbox symbol before each value, and generate value_cell using S21;

[0040] S253: Repeat S252 N times to obtain N value_cells;

[0041] S254: merge the key_cell of S251 and the N value_cells of S253 into a T5-type string representation through a horizontal merge subroutine;

[0042] S26: T6 type subroutine

[0043] S261: take the number of rows as rows and the number of columns as cols;

[0044] S262: Take out rows+cols-1 key-type character string keys from the key set;

[0045] S263: Take (rows-1)(cols-1) value-type character strings values ​​from the value set;

[0046] S264: For each column, calculate the maximum character width Lmax of the column; use S21 to obtain rows of T1-type strings; use the vertical merge subroutine to merge them into Ci;

[0047] S265: merge the cols Ci obtained in S264 into a T6-type string representation through a horizontal merge subroutine;

[0048] S27: T7 type subroutine

[0049] S271: Generate a T6 type string using S26;

[0050] S272: Generate a T1 type string using S21;

[0051] S273: randomly selecting a horizontal merging subroutine or a vertical merging subroutine to merge the T6 type and the T1 type to obtain a T7 type character string representation;

[0052] S28: T8 type subroutine

[0053] S281: Use S26 to generate a T6-type string with cols 2;

[0054] S282: Generate a T1 type string using S21;

[0055] S283: merging the T1-type character string of S282 and the T6-type character string of S281 through a vertical merging subroutine to obtain a new character string;

[0056] S284: Repeat S283 to obtain two new character strings, and merge them through the horizontal merge subroutine to obtain a new character string;

[0057] S285: Repeat S284 to obtain two new character strings, and merge them through the horizontal merge subroutine to obtain a T8-type character string;

[0058] S29: General

[0059] S291: Randomly select multiple strings of types T1 to T8 and put them into table_list; each type can be selected zero to multiple times;

[0060] S292: Randomly shuffle table_list;

[0061] S293: Merge the shuffled table_list into the final table string through the vertical merging subroutine.

[0062] Further, in step S2, the specific steps of the horizontal merging subroutine are as follows:

[0063] Denote the table strings to be merged as A and B, calculate their character widths as WA and WB, and calculate their row heights as HA and HB; if HA = HB, connect A and B row by row; if HA < HB, perform a row addition operation on A to make HA = HB; if HA > HB, perform a row addition operation on B to make HA = HB;

[0064] For the row-by-row connection operation, take the end character a of A and the start character b of B, and perform an addition operation to obtain a new connection character c; the operation rules of the addition operation are specifically defined as: 1. ║ + ║ = ║, 2. 3. 4. 5. 6. The row addition operation is: Insert HB - HA number of padding rows before the last row. The start and end of this row are ║, and there are WA - 2 space characters in the middle.

[0065] Further, in step S2, the specific steps of the vertical merging subroutine are as follows:

[0066] Denote the table strings to be merged as A and B, calculate their character widths as WA and WB, and calculate their row heights as HA and HB; if WA = WB, connect A and B column by column; if WA < WB, perform a width addition operation on A to make WA = WB; if WA > WB, perform a width addition operation on B to make WA = WB;

[0067] For the column-by-column connection operation: Take each character a of the last row of A and the corresponding character b at the same position in the first row of B, and perform an addition operation to obtain a new connection character c; the operation rules of the addition operation are specifically defined as: 1. ═ + ═ = ══, 2. 3. 4. 5. 6. The width addition operation is: Insert WB - WA number of padding spaces before each row.

[0068] Further, in step S3, the specific steps of generating the picture table are as follows:

[0069] S31: Set the font width font_width used, the pixel value line_pad for the top and bottom padding of the table rows, and the row height line_height = font_width + line_pad;

[0070] S32: Calculate the width and height of the table image;

[0071] S33: create a blank image with pixel size width×height;

[0072] S34: Scan the character string of the table row by row, draw it on the picture row by row, and record the coordinates corresponding to the text and the cell.

[0073] Furthermore, the specific steps of scanning and drawing the table row by row are as follows:

[0074] S341: Initialize the current line number i=0; the text box coordinate list text_list is empty, the cell coordinate set cell_set; calculate the y coordinate as y=i×line_height+y0;

[0075] S342: Take the string line in the i-th row, split it into multiple substrings according to the table symbol, and obtain the list cells;

[0076] S343: traverse each substring in the substring list cells of this row;

[0077] S344: If the substring does not contain ═, calculate the number of characters n in the previous string of the substring, calculate the x coordinate of drawing the substring as x=x+n×font_width, calculate the length of the substring as N, and draw the width w=N×font_width;

[0078] S345: Draw text at position x, y on the image, and put the combination of the text and the coordinate box (x, y, x+w, y+font_width) into text_list;

[0079] S346: For each substring, find the coordinate box of the cell where it is located, the positions of the left and right separators of the substring are L and R, and the row numbers of the upper and lower separators are initialized to T=i-1 and B=i+1;

[0080] S347: If the L+1 position of the T-th row is the table symbol ═, then T is its upper bound row number, otherwise T=T-1, repeat S347;

[0081] S348: If the L+1 position of the B-th row is the table symbol ═, then B is its lower bound row number, otherwise B=B+1, and S348 is repeated;

[0082] S349: Convert the cell character coordinates (L, T, R, B) into pixel coordinates, put them into cell_set to remove duplicates; and draw a rectangular frame on the picture.

[0083] Furthermore, in step S4, post-processing of the table image includes stamping, light and shadow, folds, noise, rotation, perspective, distortion, and background addition.

[0084] The beneficial effect of the present invention is that, compared with the prior art, the present invention improves the previous method of generating table OCR training data, which requires a large amount of manual text annotation and cell annotation, and provides a method for generating OCR training data for general tables, which can ensure the completeness, accuracy and diversity of the data set for table detection, and lay a solid foundation for constructing good general table OCR training data. BRIEF DESCRIPTION OF THE DRAWINGS

[0085] Figure 1 It is a flow chart of the method for generating OCR training data for the general form described in the present invention. DETAILED DESCRIPTION

[0086] The technical solution of the present invention is further described below in conjunction with the accompanying drawings and embodiments. The following embodiments are only used to more clearly illustrate the technical solution of the present invention, and cannot be used to limit the protection scope of this application.

[0087] like Figure 1 As shown, the method for generating OCR training data of a general form according to the present invention comprises the following steps:

[0088] S1: Split the corpus through the corpus of each field to generate text in the table, including key type, value type, and long text type;

[0089] The specific steps of corpus splitting are as follows:

[0090] S11: Read the corpus of each field and initialize the key set, value set, and long text set to be empty;

[0091] S12: Traverse all the strings in the corpus and split them into lines to get a list of sentences;

[0092] S13: traverse the sentence list, if the sentence length is greater than the threshold, add it to the long text set; and split the sentence into words and add them to the word list;

[0093] S14: Remove stop words from the word list, and count the number of occurrences and part of speech of each word; put high-frequency content words into the key set, and put the remaining words into the value set;

[0094] S15: After the corpus is split, the key set, value set and long text set of each field are obtained.

[0095] S2: Use random table metatypes and table text to construct a plain text representation of the table, i.e. generate a string table;

[0096] The specific steps for generating a string table are as follows:

[0097] Various table element types, including: single-line text type T1, multi-line text type T2, single key-value pair type T3, multiple key-value pair type T4, single-key multiple options type T5, multi-row and multi-column type T6, cross-row and cross-column type T7, multi-level header type T8, etc.

[0098] The methods for generating various types of string tables are as follows:

[0099] S21: T1 type subroutine

[0100] S211: Take the character string text and calculate the length to be L;

[0101] S212: Set the left and right default margins (i.e., the number of padding spaces) to lpad=1, rpad=1;

[0102] S213: The left and right boundary characters are ║, the upper and lower boundary characters are ═, and the upper left boundary character is The upper right delimiter is The lower right delimiter is The lower left delimiter is

[0103] S213: Get the multi-line string representation of the table of type T1: The first line is The second line is ║+”+text+”+║; the third line is

[0104] S22: T2 type subroutine

[0105] S221: Take multiple character strings text_list and calculate the maximum length to be Lmax;

[0106] S222: Get the multi-line string representation of the table of type T2 as follows: The first line The last act

[0107] S223: For each line of text in the middle of text_list, its length is Li, and its string is represented by ║+”+text+''×(Lmax-Li+1)+║;

[0108] S224: Connect S222 and S223 in sequence to obtain a table string representation of type T2.

[0109] S23: T3 type subroutine

[0110] S231: Take out the key string key from the key set and generate key_cell using S21;

[0111] S232: Take out the value type string value from the value set, and generate value_cell using S21;

[0112] S233: Merge key_cell and value_cell into a T3-type table string representation through a horizontal merge subroutine.

[0113] S24: T4 type subroutine

[0114] S241: Take the number of key-value pairs as N;

[0115] S242: repeat S23 N times to obtain N T3-type table character string representations;

[0116] S242: N T3-type character strings are merged into a T4-type character string representation through a horizontal merging subroutine.

[0117] S25: T5 type subroutine

[0118] S251: Take out the key string key from the key set and generate key_cell using S21;

[0119] S252: Get the value string value from the value set, add a checkbox symbol before each value, and generate value_cell using S21;

[0120] S253: Repeat S252 N times to obtain N value_cells;

[0121] S254: merge the key_cell of S251 and the N value_cells of S253 into a T5-type string representation through a horizontal merge subroutine.

[0122] S26: T6 type subroutine

[0123] S261: take the number of rows as rows and the number of columns as cols;

[0124] S262: Take out rows+cols-1 key-type character string keys from the key set;

[0125] S263: Take (rows-1)(cols-1) value-type character strings values ​​from the value set;

[0126] S264: For each column, calculate the maximum character width Lmax of the column; use S21 to obtain rows of T1-type strings; use the vertical merge subroutine to merge them into Ci;

[0127] S265: The cols Ci obtained in S264 are merged into a T6-type character string representation through a horizontal merge subroutine.

[0128] S27: T7 type subroutine

[0129] S271: Generate a string of type T6 using S26;

[0130] S272: Generate a string of type T1 using S21;

[0131] S273: Randomly select a horizontal merging subroutine or a vertical merging subroutine to merge the string of type T6 and the string of type T1 to obtain a string representation of type T7.

[0132] S28: Subroutine of type T8

[0133] S281: Generate a string of type T6 with cols equal to 2 using S26;

[0134] S282: Generate a string of type T1 using S21;

[0135] S283: Merge the string of type T1 in S282 and the string of type T6 in S281 through a vertical merging subroutine to obtain a new string;

[0136] S284: Repeat S283 to obtain 2 new strings, and merge them through a horizontal merging subroutine to obtain a new string;

[0137] S285: Repeat S284 to obtain 2 new strings, and merge them through a horizontal merging subroutine to obtain a string of type T8.

[0138] S29: Synthesis

[0139] S291: Randomly select multiple strings of types T1 to T8 and put them into table_list; each type can be selected zero to multiple times;

[0140] S292: Randomly shuffle table_list;

[0141] S293: Merge the shuffled table_list into the final table string through a vertical merging subroutine.

[0142] In step S2, the specific steps of the horizontal merging subroutine are as follows:

[0143] Denote the table strings to be merged as A and B, calculate their character widths as WA and WB, and calculate their row heights as HA and HB; if HA = HB, connect A and B row by row; if HA < HB, perform a row addition operation on A to make HA = HB; if HA > HB, perform a row addition operation on B to make HA = HB.

[0144] For the row-by-row connection operation, take the end-of-row symbol a of A and the start-of-row symbol b of B, and perform an addition operation to obtain a new connection symbol c. The operation rules of the addition operation are specifically defined as: 1. ║ + ║ = ║, 2. 3. 4. 5. 6. The line addition operation is: insert the number of padding lines equal to the number of HB - HA before the last line. The head and tail of this line are ║, and in the middle are WA - 2 space characters.

[0145] In step S2, the specific steps of the vertical merging subroutine are as follows:

[0146] Denote the table strings to be merged as A and B, calculate their character widths as WA and WB, and calculate their line heights as HA and HB; if WA = WB, connect A and B column - by - column; if WA < WB, perform a width - adding operation on A to make WA = WB; if WA > WB, perform a width - adding operation on B to make WA = WB.

[0147] The column - by - column connection operation is: take each character a of the last line of A and the corresponding character b of the first line of B, and perform an addition operation to get a new connection character c. The operation rules of the addition operation are specifically defined as: 1. ═+═=═, 2. 3. 4. 5. 6. The width - adding operation is: insert the number of padding spaces equal to WB - WA before each line.

[0148] S3: Transcribe the string table onto a blank image, and at the same time generate the table image and the position information of the annotation text and cells, that is, generate the image table;

[0149] The specific steps for generating the image table are as follows:

[0150] S31: Set the font width font_width used, the pixel value of the upper and lower padding of the table row line_pad, and the line height line_height = font_width + line_pad;

[0151] S32: Calculate the width width and height height of the table image;

[0152] S33: Create a blank image with pixel dimensions of width × height;

[0153] S34: Scan the string of the table line by line, draw it onto the image line by line, and record the coordinates corresponding to the text and cells.

[0154] The specific steps for scanning and drawing the table line by line are as follows:

[0155] S341: Initialize the current line number i=0; the text box coordinate list text_list is empty, the cell coordinate set cell_set; calculate the y coordinate as y=i×line_height+y0;

[0156] S342: Take the string line in the i-th row, split it into multiple substrings according to the table symbol, and obtain the list cells;

[0157] S343: traverse each substring in the substring list cells of this row;

[0158] S344: If the substring does not contain ═, calculate the number of characters n in the previous string of the substring, calculate the x coordinate of drawing the substring as x=x+n×font_width, calculate the length of the substring as N, and draw the width w=N×font_width;

[0159] S345: Draw text at position x, y on the image, and put the combination of the text and the coordinate box (x, y, x+w, y+font_width) into text_list;

[0160] S346: For each substring, find the coordinate box of the cell where it is located, the positions of the left and right separators of the substring are L and R, and the row numbers of the upper and lower separators are initialized to T=i-1 and B=i+1;

[0161] S347: If the L+1 position of the T-th row is the table symbol ═, then T is its upper bound row number, otherwise T=T-1, repeat S347;

[0162] S348: If the L+1 position of the B-th row is the table symbol ═, then B is its lower bound row number, otherwise B=B+1, and S348 is repeated;

[0163] S349: Convert the cell character coordinates (L, T, R, B) into pixel coordinates, put them into cell_set to remove duplicates; and draw a rectangular frame on the picture.

[0164] S4: Post-processing of the table image is performed, and the generated table image and position information are changed through a variety of post-processors to simulate the effects of real scenes, including stamping, light and shadow, creases, noise, rotation, perspective, distortion, adding background, etc.

[0165] The present invention improves the previous method of generating table OCR training data, which requires a large amount of manual text annotation and cell annotation, and provides a method for generating OCR training data for general tables, which can ensure the completeness, accuracy and diversity of the data set for table detection, and lay a solid foundation for constructing good general table OCR training data.

[0166] The applicant of the present invention has made a detailed explanation and description of the implementation examples of the present invention in conjunction with the drawings in the specification. However, those skilled in the art should understand that the above implementation examples are only preferred implementation schemes of the present invention, and the detailed description is only to help readers better understand the spirit of the present invention, but not to limit the scope of protection of the present invention. On the contrary, any improvements or modifications based on the inventive spirit of the present invention should fall within the scope of protection of the present invention.

Claims

1. A method for generating OCR training data for a general table, characterized in that: Includes steps: S1: Split the corpus through the corpus of each field to generate text in the table, including key type, value type, and long text type; S2: Use random table metatypes and text in the table to form a plain text representation of the table, that is, generate a string table; multiple table metatypes, including single-line text type T1, multi-line text type T2, single key-value pair type T3, multiple key-value pair type T4, single-key multiple options type T5, multi-line multi-column type T6, cross-row and cross-column type T7, and multi-level header type T8; The methods for generating various types of string tables are as follows: S21: T1 type subroutine S211: Take the character string text and calculate the length to be L; S212: Set the left and right default margins lpad=1, rpad=1; S213: The left and right boundary characters are ║, the upper and lower boundary characters are ═, the upper left boundary character is ╔, the upper right boundary character is ╗, the lower right boundary character is ╝, and the lower left boundary character is ╚; S213: The multi-line character string of the T1 type table is obtained as follows: the first line is ╔+(lpad+L+rpad)×═+╗; the second line is ║+' '+text+' '+║; the third line is ╚+(lpad+L+rpad)×═+╝; S22: T2 type subroutine S221: Take multiple character strings text_list and calculate the maximum length to be Lmax; S222: The multi-line string representation of the T2 type table is obtained as follows: the first line is ╔+(lpad+Lmax+rpad)×═+╗; the last line is ╚+(lpad+Lmax+rpad)×═+╝; S223: For each line of text in the middle of text_list, its length is Li, and its string is represented as ║+' '+text+' '×(Lmax-Li+1)+║; S224: connect S222 and S223 in sequence to obtain a table string representation of type T2; S23: T3 type subroutine S231: Take out the key string key from the key set and generate key_cell using S21; S232: Take out the value type string value from the value set, and generate value_cell using S21; S233: merge key_cell and value_cell into a T3-type table string representation through a horizontal merge subroutine; S24: T4 type subroutine S241: Take the number of key-value pairs as N; S242: repeat S23 N times to obtain N T3-type table character string representations; S243: merging N T3-type character strings into a T4-type character string representation through a horizontal merging subroutine; S25: T5 type subroutine S251: Take out the key string key from the key set and generate key_cell using S21; S252: Get the value type string value from the value set, add a checkbox symbol before each value, and use S21 to generate value_cell; S253: Repeat S252 N times to obtain N value_cells; S254: Combine the key_cell of S251 and the N value_cells of S253 into a T5-type string representation through a horizontal merging subroutine; S26: T6-type subroutine S261: Obtain the number of rows as rows and the number of columns as cols; S262: Extract rows + cols - 1 key-type strings keys from the key set; S263: Extract (rows - 1)(cols - 1) value-type strings values from the value set; S264: For each column, calculate the maximum character width Lmax of this column; Use S21 to obtain rows T1-type strings; Combine them into Ci through a vertical merging subroutine; S265: Combine the cols Ci obtained in S264 into a T6-type string representation through a horizontal merging subroutine; S27: T7-type subroutine S271: Generate a T6-type string using S26; S272: Generate a T1-type string using S21; S273: Randomly select a horizontal merging subroutine or a vertical merging subroutine to merge the T6-type and T1-type to obtain a T7-type string representation; S28: T8-type subroutine S281: Generate a T6-type string with cols equal to 2 using S26; S282: Generate a T1-type string using S21; S283: Combine the T1-type string of S282 and the T6-type string of S281 through a vertical merging subroutine to obtain a new string; S284: Repeat S283 to obtain 2 new strings, and combine them through a horizontal merging subroutine to obtain a new string; S285: Repeat S284 to obtain 2 new strings, and combine them through a horizontal merging subroutine to obtain a T8-type string; S29: Comprehensive S291: Randomly select multiple T1 - T8 type strings and put them into table_list; Each type can be selected zero to multiple times; S292: Randomly shuffle table_list; S293: Combine the shuffled table_list into the final table string through a vertical merging subroutine; Among them, the specific steps of the horizontal merging subroutine are as follows: Denote the table strings to be merged as A and B, calculate their character widths as WA and WB, and calculate their row heights as HA and HB; If HA = HB, connect A and B by rows; If HA < HB, perform a row addition operation on A to make HA = HB; If HA > HB, perform a row addition operation on B to make HA = HB; For the row connection operation, take the row end symbol a of A and the row start symbol b of B, and perform an addition operation to obtain a new connection symbol c; The operation rules of the addition operation are specifically defined as:

1. ║ + ║ = ║, 2. ╗ + ╔ = ╦, 3. ╣ + ║ = ╣, 4. ╣ + ╠ = ╬, 5. ║ + ╠ = ╠, 6. ╝ + ╚ = ╩; The row addition operation is: Insert HB - HA number of padding rows before the last row, with ║ at both ends of this row and WA - 2 space characters in the middle; Among them, the specific steps of the vertical merging subroutine are as follows: Denote the strings of the merged tables as A and B, calculate their character widths as WA and WB, and calculate their line heights as HA and HB; if WA = WB, connect A and B column by column; if WA < WB, perform a width addition operation on A to make WA = WB; if WA > WB, perform a width addition operation on B to make WA = WB; The column connection operation is as follows: take each character a in the last row of A and the corresponding character b in the first row of B, and perform an addition operation to obtain a new connection character c; the specific operation rules for the addition operation are defined as follows:

1. ═ + ═ = ═, 2.╚+╔=╠, 3.╩+╦=╬, 4.╩+═=╩, 5.═+╦=╦, 6.═+╗=╗; the width addition operation is: insert WB - WA number of padding spaces before each row; S3: Transcribe the string table onto a blank image, and simultaneously generate a table image and annotate the position information of the text and cells, that is, generate an image table; The specific steps for generating the image table are as follows: S31: Set the font width font_width used, the pixel value line_pad for filling above and below the table rows, and the line height line_height = font_width + line_pad; S32: Calculate the width width and height height of the table image; S33: Create a blank image with pixel dimensions of width × height; S34: Scan the strings of the table row by row, draw them onto the image row by row, and record the coordinates corresponding to the text and cells; S4: Perform post - processing on the table image, and vary the generated table image and position information through multiple post - processors to simulate the effects of a real - world scenario.

2. The method for generating OCR training data for a general table according to claim 1, characterized in that, In step S1, the specific steps for corpus splitting are as follows: S11: Read the corpora in each field, and initialize the key set, value set, and long text set to be empty; S12: Traverse all the strings in the corpus, and split them by row to obtain a list of sentences; S13: Traverse the list of sentences. If the length of a sentence is greater than the threshold, add it to the long text set; and split the sentence into words and add them to the word list; S14: Remove the stop words from the word list, and count the number of occurrences and part - of - speech of each word; put the high - frequency content words into the key set, and the remaining words into the value set; S15: The corpus splitting is completed to obtain the key set, value set, and long text set for each field.

3. The method for generating OCR training data for a general table according to claim 1, characterized in that, The specific steps for scanning and drawing the table row by row are as follows: S341: Initialize the current row number i = 0; the text box coordinate list text_list is empty, and the cell coordinate set cell_set; calculate the y - coordinate as y = i × line_height + y0; S342: Take the string line in the i - th row, and split it into multiple substrings by table symbols to obtain a list cells; S343: Traverse each substring in the list cells of the substrings in this row; S344: If the substring does not contain ═, calculate the number of characters n of the substring before the substring, calculate the x coordinate of drawing the substring as x=x+n×font_width, calculate the length of the substring as N, and draw the width w=N×font_width; S345: Draw text at position x, y on the image, and put the combination of the text and the coordinate box (x, y, x+w, y+font_width) into text_list; S346: For each substring, find the coordinate box of the cell where it is located, the left and right separator positions of the substring are L and R, and the row numbers of the upper and lower separators are initialized to T=i-1 and B=i+1; S347: If the L+1 position of the Tth row is the table symbol ═, then T is its upper bound row number, otherwise T=T-1, and repeat S347; S348: If the L+1 position of the Bth row is the table symbol ═, then B is its lower bound row number, otherwise B=B+1, and S348 is repeated; S349: Convert the cell character coordinates (L, T, R, B) into pixel coordinates, put them into cell_set to remove duplicates; and draw a rectangular frame on the picture.

4. The method for generating OCR training data for a general form according to claim 1, characterized in that: In step S4, the table image is post-processed, including stamping, light and shadow, folds, noise, rotation, perspective, distortion, and background addition.

Citation Information

Patent Citations

  • Method for generating OCR data of arbitrary character combination

    CN113435163A

  • Table information recognition system, table information conversion system, method, and recording medium

    WO2014002601A1